DOC PREVIEW
TAMU CSCE 110 - 18-records
Type Miscellaneous
Pages 37

This preview shows page 1-2-17-18-19-36-37 out of 37 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 37 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

RecordsTracking InformationSlide 3Data TypesWhat Is The Benefit Of Using A RecordDeclaring RecordsDeclaring Records (2)A Record Definition Is Like A BlueprintDeclaring Variables That Are RecordsDeclaring An Instance Of A Record Actually Creates A RecordDeclaring Variables That Are Records: What You GetUsing Record VariablesUsing Record Variables (2)Assignment Between Different Record Types Cannot Be PerformedAssignment Between The Same Type Of Record Can Be PerformedUsing Record Variables (3)Examples Of Accessing The Fields Of A RecordA Shortcut For Referencing All The Fields Of A Record: With-DoPassing Records As ParametersPutting This All TogetherPutting This All Together (2)Putting This All Together (3)Putting This All Together (4)ArraysDeclaring Arrays Of RecordsSlide 26Passing Arrays Of Records As ParametersSlide 28Slide 29Slide 30Slide 31Putting This All Together (5)Putting This All Together (6)Putting This All Together (7)Putting This All Together (8)Putting This All Together (9)Putting This All Together (10)J. Michael MooreFrom James Tam's materialRecordsCSCE 110J. Michael MooreFrom James Tam's materialTracking InformationExample, storing information about a client:•First name•Last name•Phone number•Address•Postal code•Email address•Total purchases made…array or String…array or String…integer, array or String …array or String…array or String…array or String…integer or realJ. Michael MooreFrom James Tam's materialTracking InformationProblem: information about one client should be treated as one _________ in a program (it's composite). The following approach is not reasonable yet an array won't do (the fields of a client are not homogenous, not the same type):procedure initialize (firstName : String; lastName : String; phone : integer; address : String; postalCode : String; email : String; purchases : real);begin : : :end;Parameter HellJ. Michael MooreFrom James Tam's materialData Typessimplestructuredpointerordinal realpredefinedbooleancharintegerprogrammer-definedenumerated subrangearray recordset filepredefined programmer-definedtext________________J. Michael MooreFrom James Tam's materialWhat Is The Benefit Of Using A RecordIt allows new _______________ of variables to be declared.The variable can be a ________________ composite type:•All the parts that compose the whole __________________________The variable can be a ________________ composite type:•The different parts that compose the whole _____________________The new type can model information about most any _______________ entity:•Car•Movie•Your pet•Etc.J. Michael MooreFrom James Tam's materialDeclaring RecordsFormat:type Name of record = record name of field (1) : type of field (1); name of field (2) : type of field (2); name of field (3) : type of field (3); : : : : : : name of field (n) : type of field (n); end; (* Record declaration *)J. Michael MooreFrom James Tam's materialDeclaring Records (2)Example:const NAME_LENGTH = 16;type Person = record name : string [NAME_LENGTH]; age : integer; height : real; weight : real; end; (* Declaration of Person *)J. Michael MooreFrom James Tam's materialA Record Definition Is Like A Blueprint•It specifies the format or structure of an example of the record (what attributes will track what information)•No record is actually _____________ by this definition•________________________________ (A ____________).J. Michael MooreFrom James Tam's materialDeclaring Variables That Are RecordsFormat: name of variable : name of record;Example: var jMichaelMoore : Person; var bartSimpson : Person;J. Michael MooreFrom James Tam's materialDeclaring An Instance Of A Record Actually Creates A Record•Something has now been ___________________.J. Michael MooreFrom James Tam's materialDeclaring Variables That Are Records: What You GetFormat: name of variable : name of record;Example: var jMichaelMoore : Person; var bartSimpson : Person;jMichaelMoore name age height weightbartSimpson name age height weightJ. Michael MooreFrom James Tam's materialUsing Record VariablesExample: Declaring the record and instances of the recordconst NAME_LENGTH = 16;type Person = record name : string [NAME_LENGTH]; age : integer; height : real; weight : real; end; (* Declaration of a Person *)begin var jMichaelMoore : Person; var bartSimpson : Person; : : :end.J. Michael MooreFrom James Tam's materialUsing Record Variables (2)Assignment (_______________ basis):e.g.,bartSimpson.name := 'Bart';bartSimpson.age := 10;bartSimpson.height := 48;bartSimpson.weight := 80;Assignment (____________________, all fields are copied – if the records are declared to be the same type) e.g.,jMichaelMoore := bartSimpson;J. Michael MooreFrom James Tam's materialAssignment Between Different Record Types Cannot Be PerformedExample:const NAME_LENGTH = 80;type Cat = record name : string [NAME_LENGTH]; end; (* Declaration of a Cat *) Dog = record name : string [NAME_LENGTH]; end; (* Declaration of a Dog *)begin var aCat : Cat; var aDog : Dog; aCat := aDog; :end.Problem:•Cat <> Dog•Each has been declared to be a different type of variable.J. Michael MooreFrom James Tam's materialAssignment Between The Same Type Of Record Can Be PerformedExample:const NAME_LENGTH = 80;type Pet = record name : string [NAME_LENGTH]; end; (* Declaration of a Pet *)begin var aCat : Pet; var aDog : Pet; aCat := aDog; :end.OK:•Cat and Dog are of the same typeJ. Michael MooreFrom James Tam's materialUsing Record Variables (3)•Input and output is via read/readln and write/writeln•Must be done on a _____________________________ basis (if the field is a type that can be “understood”1 by read/readln or write/writelne.g., write('Enter name for student : '); readln(jMichaelMoore.name); writeln('First name: ', jMichaelMoore.name);1 This includes the built in simple types as well as one dimensional character arraysJ. Michael MooreFrom James Tam's materialExamples Of Accessing The Fields Of A Recordtype Fur = record color : array [1..10] of char; end; (* Declaration of Fur *) Animal = record species : array [1..10] of char; coat :


View Full Document

TAMU CSCE 110 - 18-records

Type: Miscellaneous
Pages: 37
Documents in this Course
06-IO

06-IO

29 pages

21-OOP

21-OOP

8 pages

key

key

6 pages

21-OOP

21-OOP

8 pages

Load more
Download 18-records
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view 18-records and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view 18-records 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?