2.1
ADT integer is{
Data
Operations.
Assume that u and v are integer expressions,
and N is an integer variable.
Compute the quotient using integer division u/v.
Input: Two integer values, u and v.
Preconditions: Denominator v cannot be 0.
Process: Divide v into u using integer
division.
Output: Value of quotient.
Post Conditions: Error conditions exists if v=0.
}end ADT
Computer Storage of integers
2.2 Character Types.
ADT character is{
Data
ASCII character set
Operations
Assignment
A character value can be assigned to a character variable.
Relational
The six standard relational operators apply to characters using the ASCII
dictionary order relation end ADT.
ASCII: Coding scheme using a 7 bit integer code.
Table 2.2 Page 44.
Table 2.3 Page 45.
Type char is used to store a character.
}end ADT
2.3: Real Data Types
2.4 Enumerated Types.
ADT Enumerated is{
Data
User defined list of N distinct items.
Operations
Assignment
A variable of enumerated types can be assigned any of the items
in the list.
Relational:
The six standard relational operators use the order relation
determined by the way in which items are listed.
} end ADT.
The following statements illustrate fundamental pointer operations.
cout <<*PC<<endl;
//Print `A'
PC+=4;
//Move PC right 4 chars.
cout <<*PC<<endl;
//Print `E'
PC--;
//Move PC left 1 char
cout <<*PC<<endl;
//Print `D'
cout <<*PX+3 <<endl;
//Print 36=33+3
ADT string isData
A string is a sequence of characters with an associated length. The string structure may have a NULL-terminating character or a separate length parameter.Operations
Length Input: None Preconditions: None Process: For a Null-terminating string, count the characters up to the NULL character; for a length count string, retrieve the length value. Post Conditions: None Output: Return the string length.Copy Input: Two strings STR1 and STR2. STR2 is the source and STR1 is the destination. Preconditions: None Process: Copy the characters from STR2 to STR1. Post Conditions: A new string STR1 is created with the length and data obtained from STR2. Output: Return access to STR1.
Concatenation Input: Two strings STR1 and STR2. Join STR2 onto the tail of STR1. Preconditions: None Process: Find the end of STR1. Copy characters from STR2 onto the tail of STR1. Update information on the length of STR1. Post Conditions: STR1 is modified. Output: Return access to STR1.
Compare Input: Two strings STR1 and STR2. Preconditions: None Process: Apply ASCII order to the strings. Post Conditions: None. Output: Return a value as follows. STR1 less than STR2: return a negative value. STR1 equal to STR2: return a value 0. STR1 greater than STR2: return a positive value.
Index Input: A string STR and a single character CH. Preconditions: None Process: Search STR for the input character CH. Post Conditions: None. Output: Return the address of the location containing the first occurence of CH in STR or 0 if the character is not found.
Right Index Input: A string STR and a single character CH. Preconditions: None Process: Search STR for the last occurence of character CH. Post Conditions: None. Output: Return the address of the location containing the last occurence of CH in STR or 0 if the character is not found. Read Input: The file string from which the characters are read and the string STR to hold the characters. Preconditions: None Process: Read a sequence of characters from the stream into the string STR. Post Conditions: The string STR is assigned the characters read. Output: None. Write Input: A string that contains characters for output and a stream to which characters are written. Preconditions: None Process: Send the string of characters to the stream. Post Conditions: None Output: The output stream is modified. end ADT String
ADT Record is Data An item containing a set of fields of heterogenous type. Each field has a name that allows for direct access to data in the field. Operations Access Operator Preconditions: None Input: Record name (recname) and field. Process: Access data in the field. Output: When retrieving data, return the field value to the client. Post Conditions: When storing data the record is changed. end ADT Record
ADT File is
Data
An identification of the external file and the
direction of the data flow. A sequence of characters
that are read from or written to the file.
Operations
Open
Input: Name of the file and the direction of flow.
Preconditions: For input, the external file must exist.
Process: Link a stream with the file.
Output: A flag that indicates the operation is successful.
Post Conditions: Data may flow between the external file
and system memory through the stream.
Close
Input: None
Preconditions: None
Process: unlink the stream from the file.
Output: None.
Post Conditions: Data may no longer flow through the
stream between the external file and
system memory.
Read
Input: An array to hold blocks of data; A count N
Preconditions: The stream must be open with read-only or
read-write direction.
Process: Input N characters from the stream into the array.
Stop on end-of-file
Output: Return the number of characters that are read.
Post Conditions: The file pointer is moved forward N
characters.
Write
Input: An array; A count N
Preconditions: The stream must be open with write-only or
read-write direction.
Process: Output N characters from the array into the stream.
Output: Return the number of characters that are written.
Post Conditions: The stream contains the output data and
the file pointer is advanced forward N
characters.
Seek
Input: Parameters to reset the file pointer.
Preconditions: None.
Process: Reset the file Pointer.
Output: Return a flag that indicates whether the seek is
successful.
Post Conditions: A new file pointer is set.
end ADT File