Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 2 Records 2/22/2018.

Similar presentations


Presentation on theme: "CS 2 Records 2/22/2018."— Presentation transcript:

1 CS 2 Records 2/22/2018

2 Learning Targets Be able to model and write code using records.

3 What would you use if… You needed to store someone’s name, age, and phone number? What about name, strength, skills and position? What about a recipe: Title, Ingredients, instructions, … How about a song title, length of the song, artist name, ranking on your personal favorites list, … Pascal has a ‘data structure’ that can store more than one type of information in a single variable.

4 Program RecordsExample; type StudType = record name:string;
age:integer; gpa:real; end; var Student1,Student2:Studtype; begin writeln(‘Please enter your name’); readln(Student1.name); writeln(‘Please enter your age’); readln(Student1.age); writeln(‘Please enter another name’); readln(Student2.name); writeln(‘Please enter another age’); readln(Student2.age); if (Student1.age) > (Student2.age) then writeln(Student1.name,’ is older’) else writeln(Student1.name, ‘ is not older ‘); end. Student1 Name:________ Age:_________ GPA:_________ Student2

5 Declarations and stuff
In the Type section recType = record Field1:field1type; Field2, field3:field23type; end; In the Var section Recordvariable:Rectype; In the Code Section Recordvariable.Field1:=…;

6 What do you think this will do?
Program RecordsExample; type StudType = record name:string; age:integer; gpa:real; end; var Student1,Student2:Studtype; begin writeln(‘Please enter your name’); readln(Student1.name); writeln(‘Please enter your age’); readln(Student1.age); writeln(‘Please enter another name’); readln(Student2.name); writeln(‘Please enter another age’); readln(Student2.age); if (Student1.age) > (Student2.age) then writeln(Student1.name,’ is older’) else writeln(Student1.name, ‘ is not older ‘); Writeln(Student); end. Common errors Putting a ; here Forgetting the ‘end.’ What do you think this will do?

7 Write the declarations (Type and var) for a variable that needs to hold…
Team Name, School, Total score (For a swim meet, wrestling meet, track meet, …) Project Leader name, Three goals (Sentences), Money allocated for the project.

8 First Record Program Input 10 Team Names, School names, and Total scores. (While loop) Output: The winning team. That is the team with the highest score. (If there is a tie, just show the first team with the top score.) (Note, you don’t need an array for this program.) Push: Modify this so it takes an unknown number of the above. Push: Same input as above, and show the schools with the top five scores. (You do need an array and a sort for this one.)


Download ppt "CS 2 Records 2/22/2018."

Similar presentations


Ads by Google