Introduction to Computer Science:
Assignment 28:  Hungry Mice and GPA
 Sewickley Academy, 2000-2001

See Course Home Page.
 
Date Assigned: Thu Jan-18
Date Due: Fri Jan-19

Note 0.  Be sure to read all the instructions before beginning.

Note 1.  You must work alone on these problems.

Note 2.  In order to assist partly-automated grading, you should submit exacty one program for all of these problems.  The first thing your program should do is read in one integer, which will correspond to the problem number to be solved.  The input after that point will be just for that problem.

Note 3.  Note that your program should not prompt the user for input (just read the input, don't cout some "helpful" message), and should only output precisely what the problem requests (again, no helpful messages, just the output exactly as requested).

Note 4.  Further, please do not include a getchar() at the end of your program (you of course may want it there for debugging purposes, but when you are ready to submit your program, please remove it).


Question 1.

Your task is to track a hungry mouse eating cheese.  Your program will first read in the starting location of the mouse as two integers (the (x,y) coordinates of the mouse).  Then, your program will read in one integer:  the total pieces of cheese.  Finally, your program will read in the locations of that many pieces of cheese.  Each location will be two integers representing the cheese's (x,y) coordinates.  Now, a mouse always moves directly to the closest remaining piece of cheese, eats that cheese, and continues until there is no more cheese.  Your program should print out the coordinates (printed out precisely as: x coordinate, comma, y coordinate, newline -- no spaces) that the mouse is at when all the cheese is gone (sad mouse).


Question 2.

Your task here is to compute the GPA (grade point average) for a set of grades.  Each grade will be a letter grade (A,B,C,D,F) followed by an optional + or -.  Each grade will also be separated by a period ('.') from the subsequent grade, except that the first and last letters of the input will both be an underscore ('_').  So, some sample inputs might be:  "_A.A-.C+.B-_".  Note that you do not know, a priori, how many grades will be in the input.  Your output should be the grade point average, to exactly 1 decimal place (use truncation, not rounding, so 3.19 is 3.1).  So if the GPA is 4.0, you may not output "4", nor "4.", but must output "4.0".  If the GPA is 3.19, you must output "3.1".  Use the following table when computing the GPA:
 
A 4.0
A- 3.7
B+ 3.3
B 3.0
B- 2.7
C+ 2.3
C 2.0
C- 1.7
D+ 1.3
D 1.0
D- 0.7
F+ n/a
F 0.0
F- n/a

Good luck!

DK


See Course Home Page.