Name: ________________________________

Honor Code Acknowledgment: ___________________


Random Quiz # 3

CPS 100E, Fall 1996

Due: September 17


Problem 1: 10-meter mania (4 points)

Write a function to calculate and return the overall score of a dive. The overall score is calculated by throwing out the high and low individual scores, then averaging the remaining individual scores and multiplying the average by a difficulty factor. For example, if six individual scores are:

   8.0   7.5   8.0   9.0   6.0   7.5

Then after throwing out high (9.0) and low (6.0) the remaining scores total 8.0 + 8.0 + 7.5 + 7.5 = 31, and the average is 31/4 = 7.75. A difficulty factor of 3.5 yields a total score of 7.75 * 3.5 = 27.125.

double DiveScore(double diffFactor, const Vector<double> & scores, int numScores) // precondition: numScores = # of values stored in scores // postcondition: returns dive score calculated from entries // in vector scores. { }

Problem 2: Operator, can you help me? (4 pts)

Write a C++ function RandomPhone() that returns a string representing a valid, random phone number. A valid phone number is defined as any 7-digit integer that does not start with 0 or 1. The phone number is separated into a three digit prefix and a four digit suffix.

For example, 411-9786 is a valid phone number, but 005-6789 (which starts with 0) and 116-7865 (starts with one) are not valid phone numbers.

Examples of calls to RandomPhone() include

string pnum = RandomPhone(); cout << RandomPhone() << endl << pnum << endl;

The output for the above code segment could be:

   345-8794
   983-1478

The output for the above code segment also could be:

999-9999
200-0000