Download presentation
Presentation is loading. Please wait.
Published byErnest Parks Modified over 6 years ago
1
Computer Science 1 1/19/2011 On the record (paper) write the following
Name:______________ Farthest from Salem:____________ Favorite Food: _____________ Favorite College: _____________ Top three college majors:_______________
2
Computer Science 2 Today:
Understand how to save different kinds of information about a person in a record. On the record (paper) write the following Name:______________ Farthest from Salem:____________ Favorite Food: _____________ Favorite College: _____________ Top three college majors:_______________
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, Project due date. Student name, Student ID number, Class schedule.
8
First Record Program Input an unknown number of 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: Same input as above, and show the schools with the top five scores. (You do need an array and a sort for this one.)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.