Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:

Slides:



Advertisements
Similar presentations
CS150 Introduction to Computer Science 1
Advertisements

CS107 Introduction to Computer Science Lecture 5, 6 An Introduction to Algorithms: List variables.
Looping While-continue.
ARRAYS 1.Basic Ideas 2.The Array Type 3.Processing Arrays 4.Parallel Arrays 5.Two-dimensional Array 6.Arrays as Parameters.
VBA (continued) DSC340 Mike Pangburn. Consider a quite different example  You need to compute someone’s exact age.  The math is actually somewhat complicated.
Review the following : Flowcharting Variable declarations Output Input Arithmetic Calculations Conditional Statements Loops.
COMPUTER PROGRAMMING 2 ArrayLists. Objective/Essential Standard Essential Standard 3.00Apply Advanced Properties of Arrays Essential Indicator 3.02 Apply.
Computer Science 1 How do you store a bunch of similar stuff?
Computer Science I: Understand how to evaluate expressions with DIV and MOD Random Numbers Reading random code Writing random code Odds/evens/…
Outline lecture Revise arrays Entering into an array
Single Dimensional Arrays
Array Review Selection Sort
Program options Write a program for one of the following
Computer Science Dynamics.
One-Dimensional Array Introduction Lesson xx
How do you store a bunch of similar stuff?
Computer Science II First With files.
Computer Science II First With files.
Truth tables: Ways to organize results of Boolean expressions.
Sorts on the AP Exam Insertion Sort.
Computer Science 2 Arrays of Records.
Computer Science 2 Review the Bubble Sort
Continue on the Array of Records program
Insertion Sort Quiz on Thursday.
Computer Science 2 Arrays of Records.
Computer Science 2 Getting an unknown # of …. Into an array.
Remembering lists of values lists
Truth tables: Ways to organize results of Boolean expressions.
Computer Science Dynamics.
Computer Science Sorting.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2 Arrays of Records.
Arrays Topics Definition of a Data Structure Definition of an Array
Big problem  small steps
How do you store a bunch of similar stuff?
Computer Science Sorting Pre-Test Discussion/program
Deleting from a binary tree
Computer Science 2 Tally Arrays 2/4/2016.
CS 2 Records 2/22/2018.
Truth tables: Ways to organize results of Boolean expressions.
Computer Science II Second With files.
Computer Science Procedures Day 2.
Sorting Develop a sorting algorithm
Continue with Life, Magic and Catch -up
Computer Science 2 More Trees.
Computer Science 1 while
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Deleting from a binary tree
DATA STRUCTURES 5/3/2019© 2006 ITT Educational Services Inc.
How do you store a bunch of similar stuff?
Welcome Back CS 2 2/4/2013 On the record (paper) write the following
More Trees 5/9/2-017 Be able to dry run a program that uses trees
Computer Science I: Get out your notes.
Consider Write a program that prompts a user to enter the number of students and then, their names and grades. The program will then outputs the average.
Continue on the Valentines program
Computer Science 2 Queue.
Time to finish first stack program
Array Review Selection Sort
Learning Plan 5 Arrays.
Program options Write a program for one of the following
Dry Run Fix it Write a program
Program: Mini Phone Book 2/11/2016
Computer Science 1 while
CS 2 2/25/2015 File Exists?.
Computer Science 1 while
Dry Run Fix it Write a program
Arrays Topics Definition of a Data Structure Definition of an Array
Selection Sort Insertion Sort if time
A bit of Review Review, Dry Run, Program.
Computer Science II First With files.
Presentation transcript:

Computer Science 2 Arrays of Records

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.)

Goals Review making records Figure out how to make an array of records Write a fantastic program with arrays, records and candy bars!

Record Review 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(Student1); end. Potential Error:Putting a ; here Potential Error:Forgetting the ‘end.’ Error

Write the declarations (Type and var) for a variable that needs to hold… Name, school, Valentine card type (Small or Large), cost, type of candy (Candy bar, skittles, …). On Notepad, word, … As the class goes on we will add to this.

How would you… Store a large group of records? How can you set it up? How can you access it? How can you search it?

Array of Records Sample program arrayofrecsample; type rectype = record name:string; age:integer; end; arrayType = array[1..10] of rectype; var names:arrayType; temp:rectype; count, count2:integer; Draw a picture for the variables in this program.

More of the sample begin names[1].name:='Fred'; names[1].age := 72; Writeln('Please enter a name'); readln(names[2].name); writeln('Please enter their age'); readln(names[2].age); temp.name:='Betty'; temp.age := 29; names[3]:= temp; Record how this code changes the variable.

Using a for do loop for count := 4 to 6 do begin writeln('Please enter your name'); readln(names[count].name); writeln('Please enter the age'); readln(names[count].age); End; You select the info to enter for the readlns.

What about an unknown number (within limits)? count :=0; writeln('Please enter a name or ZZZ to quit'); readln(temp.name); while (temp.name <> 'ZZZ')and (count <10) do begin inc(count);//Same as count:=count+1; writeln('Please enter the age'); readln(temp.age); names[count]:= temp; // Copies the entire record writeln('Please enter a name or ZZZ to quit'); readln(temp.name); end;

Showing the data from a for loop writeln('Name':10, 'Age':10); for count2:= 1 to count do begin writeln(names[count2].name:10, names[count2].age:10); end; //Or for count2:= 1 to count do begin with names[count2] do begin writeln(name:10, age:10); end; end.

Write the declarations Store 5 Name, school, Valentine card, cost, type of candy. Use the record you declared at the beginning of class.

program Wrecko; type rectype = record a:integer; b:real; end; arraytype = array[1..5] of rectype; var data: arraytype; count,x,y:integer; begin for count := 1 to 5 do begin data[count].a:= count; data[count].b:= count *3; end; for count:= 1 to 5 do data[count].b:= data[count].b +data[count].a; for count:= 5 downto 1 do writeln(data[count].a:5, data[count].b:5:2); for count:= 1 to 4 do begin data[count].a := data[count+1].a; data[count+1].b:=data[count].b; end; for count:= 1 to 5 do writeln(data[count].a,data[count].b:5:2) end.

Program 1.Get 5 Names, schools, type of Valentines cards, costs, types of candy. 1.Show all the information in a chart. 2.Let the user enter a name and the program will return the type of candy. (Tell them if the person is not in the book) 3.Modify this to be set up as a menu. (Show all, Find person, Find School’s people, total sales, quit) 4.Let the user enter the name of the school, and it will show all of the students from that school. 5.Write the code to find the total of all of the sales. 2.Pushes: 1.Improve user friendliness of the program. 2.Include an ‘Add another person’ option to the menu. 3.Calculate how many of each candy you will need to order. 4.Let it support holding an unknown number of records (but less than 100) 5.Write the program using procedures.