120 likes | 167 Views
CS 115 Co-Op/Group Activity for 12/2/2009. We are going to write a program to do the following: Read in a set of names and score pairs from two different files Sort these based on score Compute the Average Score and the Quartile cutoffs.
E N D
We are going to write a program to do the following: • Read in a set of names and score pairs from two different files • Sort these based on score • Compute the Average Score and the Quartile cutoffs. • Display the students in their appropriate quartiles in a nice table.
Functional Breakdown • Sorting Function • File Reading Function • Average Computation Function • Quartile Computation Function • Display Function
Variables • Array for names (string) • Array for grades (float) • Const for num of students • Array for quartiles • Float for average
Libraries • Fstream • Iomanip • Iostream
Prototypes • Sorting Function • Void Sort(string names[], float grades[]); • File Reading Function • Void f_read(ifstream & f1, ifstream & f2, string names[], float grades[]); • Average Computation Function • Float comp_avg(float grades[]); • Quartile Computation Function • Void comp_quart(float grades[], float quart[]); • Display Function • Void display(string names[], float grades[], float average, float quart[]);
Loop!!! f1>>names[ct]; f2>>grades[ct]; • While(infile && ct < NUM_REC) { ct++; f1>>names[ct]; f2>>grades[ct]; }
Comp_avg!! acc = 0; ct = 0; while (ct < NUM_REC) { acc = acc+grade[ct]; } return (acc / float(ct));
Swap void swap(float & arg1, float & arg2) { float temp = arg1; arg1 = arg2; arg2 = temp; }
Selection Sort!! • Idea: • Start at the beginning • Scan the array • Find the smallest number • Swap it to the beginning • Do it again starting at beginning + 1 • Etc.
Quartiles • Quartiles are 25%, 50% 75%, 3 numbers. • 50% = median • Fill our array with a number for each quartile.
Display • Display the Quartiles one at a time while clearing the screen • Press any key to continue functionality • Nice tables!!