1 / 12

CS 115 Co-Op/Group Activity for 12/2/2009

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.

torgny
Download Presentation

CS 115 Co-Op/Group Activity for 12/2/2009

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS 115 Co-Op/Group Activity for 12/2/2009

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

  3. Functional Breakdown • Sorting Function • File Reading Function • Average Computation Function • Quartile Computation Function • Display Function

  4. Variables • Array for names (string) • Array for grades (float) • Const for num of students • Array for quartiles • Float for average

  5. Libraries • Fstream • Iomanip • Iostream

  6. 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[]);

  7. Loop!!! f1>>names[ct]; f2>>grades[ct]; • While(infile && ct < NUM_REC) { ct++; f1>>names[ct]; f2>>grades[ct]; }

  8. Comp_avg!! acc = 0; ct = 0; while (ct < NUM_REC) { acc = acc+grade[ct]; } return (acc / float(ct));

  9. Swap void swap(float & arg1, float & arg2) { float temp = arg1; arg1 = arg2; arg2 = temp; }

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

  11. Quartiles • Quartiles are 25%, 50% 75%, 3 numbers. • 50% = median • Fill our array with a number for each quartile.

  12. Display • Display the Quartiles one at a time while clearing the screen • Press any key to continue functionality • Nice tables!!

More Related