CS215 - Lec 4 single record organization

15

description

Reading/writing a single records

Transcript of CS215 - Lec 4 single record organization

Page 1: CS215 - Lec 4  single record organization
Page 2: CS215 - Lec 4  single record organization

� List different methods for field organization.

� Continue with the company class;

� use fixed length ,

� use length indicator,

� use delimiter,

� use KeyWord.

Dr. Hussien M. Sharaf2

Page 3: CS215 - Lec 4  single record organization

Dr. Hussien M. Sharaf3

Fixed length

Variable length

Length indicator

Field delimiter

Keyword=Value

Like Tags of HTML and XML

Page 4: CS215 - Lec 4  single record organization

� Each field has a fixed length of bytes.

� The length must be the max expected length.

� Problems:

1. The estimation of max length.

2. The choice of a character to fill the remaining space.

Dr. Hussien M. Sharaf4

Page 5: CS215 - Lec 4  single record organization

a) Length indicator:

To store the field length just ahead of the field.

� Problems:

1. The field length must not be too long (less than 256 bytes) to be stored in a single byte.

2. Needs more programming effort.

3. Requires at least two disk trips for each field.

Dr. Hussien M. Sharaf5

2. Variable length fields

Page 6: CS215 - Lec 4  single record organization

b) Field delimiter:

To choose a special character that will not appear within a field and then insert that after each field .

� Problems:

1. The choice of a delimiter character that does not get in the way of processing (ex. White space is not a good choice cause the field may contain spaces within it like “address fields” same for @).

Dr. Hussien M. Sharaf6

Continue Variable length fields

Page 7: CS215 - Lec 4  single record organization

c) Keyword = Value:• The field provides information about itself by using a

keyword to identify each field.Example: last=sharaf first=hussein.

• It is often combined with another format (like delimiters) to separate each value from the keyword of the following field.

� Advantages:1. It is easy to say which fields are contained in a file.2. It is a good format for dealing with missing fields.

Dr. Hussien M. Sharaf7

Continue Variable length fields

Page 8: CS215 - Lec 4  single record organization

Dr. Hussien M. Sharaf 8

User Interface

Classes containing any processing of data

Page 9: CS215 - Lec 4  single record organization

//Declarations

while (ExitProgram!=true)

{ //take user choice

switch (UserChoice)

{ case 'I':

case 'i':

//handle user Choice

case'E':

case'e':ExitProgram=true; break;

}

}

system("pause");

Dr. Hussien M. Sharaf 9

Page 10: CS215 - Lec 4  single record organization

1. Start by determining Output.

2. List the inputs.

3. Think about processing.

Page 11: CS215 - Lec 4  single record organization

� Continue using the CompanyInfo class:

� In assignment #3 we overloaded operators to read and write comma delimited fields.

Add a method(not an overloaded operator) that takes in ostream and writes to it a company record.

1. Fields have length indicator of type short.

2. Modify the driver(main) to use this class based on the template Menu.

Example:03155 03All 15A-z Maintenance 05Malek 01- 32902 Bestel Avenue - Garden Grove..

Dr. Hussien M. Sharaf11

Page 12: CS215 - Lec 4  single record organization

� Continue using the CompanyInfo class:Write a method(not an overloaded operator) that takes in istream and reads from it a company record.

1. Fields have length indicator of type short.

2. Write a driver to use this class based on the template Menu.

Example:

03155 03All 15A-z Maintenance 05Malek 01- 32902 BestelAvenue - Garden Grove..

Note that the first two bytes are the length indicator.

Dr. Hussien M. Sharaf12

Page 13: CS215 - Lec 4  single record organization

� Next week is the deadline.

� No excuses.

� Don’t wait until last day.

� I can help you to the highest limit within the next 3 days.

Dr. Hussien M. Sharaf13

Page 14: CS215 - Lec 4  single record organization

1. Delete the “bin” and “obj” folders.

2. Compress the solution folder using winrar.

3. Rename the compressed file as follows:

StudentName_ID_A4.rar

StudentName_ID_A5.rar

4. Email to: [email protected] your ID in the subject.

Dr. Hussien M. Sharaf 14

Page 15: CS215 - Lec 4  single record organization