Computer Science 2 Tally Arrays 2/4/2016.

Slides:



Advertisements
Similar presentations
Copyright © 2006 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide
Advertisements

Lists. Lists store information in a certain order. You can add, remove, or rearrange items in a list. You can also pick out information from a list.
Lesson 7-1. Warm-up You are at a restaurant with a special for $10. You have the option to get: a) an appetizer and an entree or b) an entree and a dessert.
MOM! Phineas and Ferb are … Aims:
Warm Up October 31, 2011 What is the main goal in a football game? What is the main goal in a basketball game? What is the main goal in a baseball game?
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/…
Goals Your organization has three metrics to measure mission effectiveness Count your successes in each category for each roll 1.Total of exactly thirteen.
int [] scores = new int [10];
13 Lesson 1 Let Me Count the Ways Fundamental Counting Principle, Permutations & Combinations CP Probability and Statistics FA 2014 S-ID.1S-CP.3S-CP.5.
Computer Science 2 Arrays of Records. First Record Program Input an unknown number of Team Names, School names, and Total scores. (While loop) –Output:
Intro CS – Probability and Random Numbers
Organizing Data: Mean, Median, Mode and Range
Statistics and Probability
Program Options: 10 Minutes online
Review Dry Run A Little More Math Fix it Online time
Computer Science Dynamics.
Probability.
Computer Science 2 Hashing
Electoral College Simulation
How do you store a bunch of similar stuff?
int [] scores = new int [10];
Truth tables: Ways to organize results of Boolean expressions.
Computer Science 1 Dice Project.
Review Dry Run Taking Names Online time Math is Good
Computer Science 2 Arrays of Records.
Computer Science 1 Get out your notebook
Computer Science 2 Review the Bubble Sort
Continue on the Array of Records program
And and or…and RANDOMNESS
Computer Science 2 Arrays of Records.
Computer Science 2 Getting an unknown # of …. Into an array.
Dry run Fix Random Numbers
List Based Objects.
Program Options: 10 Minutes online
Truth tables: Ways to organize results of Boolean expressions.
Computer Science Dynamics.
Repeat Day2 Dry Run Second Repeat Program
int [] scores = new int [10];
Computer Science Sorting.
Computer Science 1 1/19/2011 On the record (paper) write the following
Computer Science 2 Arrays of Records.
How do you store a bunch of similar stuff?
Computer Science 2 Hashing.
CS 2 Records 2/22/2018.
List Based Objects.
Truth tables: Ways to organize results of Boolean expressions.
How can you make a guessing game?
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
How can you make a guessing game?
Computer Science 1 Dice Project.
Computer Science
How do you store a bunch of similar stuff?
Welcome Back CS 2 2/4/2013 On the record (paper) write the following
Computer Science 1 4/4/2016.
Computer Science I: Get out your notes.
Continue on the Valentines program
Dry Run Fix it Write a program
10/27/2016 Dry Run 2 Case Programs Fix it Second Case Program
Random Numbers while loop
int [] scores = new int [10];
Computer Science 1 while
Computer Science 1 Get out your notebook
Computer Science 1 Get out your notebook
Dry Run Fix it Write a program
Computer Science
Presentation transcript:

Computer Science 2 Tally Arrays 2/4/2016

Learning Objectives Students will be able to use arrays to keep track of votes for an election

Dry run practice. tot:=0; for count: = 1 to 3 do num[count]: = 0 ; Begin tot:= count mod 3 + 1; inc(num[tot]); End; For count:= 1 to 3 do writeln(num[count]);

Tally Array notes Types of uses for an array General: Storing lots of stuff Tallying: Storing votes for lots of events Sorting: Putting stuff in order

Election time We’ll be writing the code to run a small election between thee candidates. It will get votes and show the results of the election. Can this be done without using arrays?

Getting Ready to Code Hands on Pseudo Code Dry Run Code

while (vote<>4) do begin case Vote of 1:Cand1:=Cand1+1; end; Writeln(‘Please vote for’); Writeln(‘1-Wilma’); writeln(‘2-Fred’); writeln(‘3-Barney’); writeln(‘4-quit’); readln(Vote); end; {Of the while} writeln(‘Wilma has ‘,Cand1); writeln(‘Fred has ‘,Cand2); writeln(‘Barney has ‘,Cand3); end. Program NoArrayElection; var Cand1, Cand2, Cand3:integer; Vote:integer; begin Cand1:=0;{These hold the number of} Cand2:=0;{ votes for the candidates} Cand3:=0; Writeln(‘Please vote for’); Writeln(‘1-Wilma’); writeln(‘2-Fred’); writeln(‘3-Barney’); writeln(‘4-quit’); readln(Vote); What if there are more candidates? Translating this to using arrays

We need to save the votes for the four candidates. What type of an array would you use? Declare it TYPE VAR

Program Options Write a program that will roll a pair of six-sided dice 1000 times and count and display how often each roll occurs. Also show which roll occurs the most often and which occurs the least often. Push: Compare the results to what should happen statistically. Push: Display the results in a graph. Write the program for the election as in the warm ups and tell the winner of the election. Push: Let the use choose the names of the candidates Push: Store the names of the candidates in another array. Push: Let the user pick the names of the candidates, and how many candidates (up to 10) Write a program to keep track of scoring during a basketball game. Use the player number to find the address in the array (To keep it simple, just use player numbers 1..10). And the person can score 1, 2, or 3 points on each basket. Show the results (the points scored by each player at the end.) Push: Keep track of the names of the players also Push: Show the name of the player that scored the most points.