CIS 122: Assignment #4

Due on Tuesday, August 2 2005


Problem 1 (50 points)

Do either (a) or (b); do both for extra credit (10 points).

(a) Application 4-2 and 4-3 of Lesson10, Page 161 of the text book. Only one final program is required, the one meet the requirements of both 4-2 and 4-3.

(b) Application 4-5 of Lesson 10, Page 162 of the text book. Besides what's in the text book, the number of total guess trials is also required in the output.

Problem 2 (30 points)

In Professor Fox's Algorithm Basics course, each students takes 5 exams. A student's letter grade is determined by first calculating her weighted average as follows:

avg = (score1 + score2 + score3 + score4 + score5 - min_score)/4

(It means her minimum score will not be counted.) Then her letter grade is given according to the weighted average score. Here is the program to provide a student's letter grade according to her input scores. The detailed implementation of the functions have been skipped, and you do not need to know that. Some lines are missing, please fill them, IF NECESSARY. (Again, you may not need all of the empty lines.)

// letter_grade.cpp
// Find weighted average score and letter grade

#include < iostream >
#include < iomanip >
____________________
____________________

using namespace std;

float min(float a, float b);
    // return min of a and b

char grade(float score);
    // Given the score, return letter grade A, B, C, D or F

int main()
{
	float score1, score2, score3, score4, score5;

	float min_score;

	___________________

	___________________

	float avg;

	char letter_grade;

	// Input 5 scores

	cout << "Please enter your scores of five exams: " << endl;

	cin >> score1 >> score2 >> score3 >> score4 >> score5;

	// Determine the weighted average by calling function min(a, b)

	________________________________________________

	________________________________________________

	________________________________________________

	________________________________________________

	avg = (score1 + score2 + score3 + score4 + score5 - min_score)/4.0;

	//Determine grade

	________________________________________________

	// Output average and grade

	cout << fixed << showpoint << setprecision(1);

	cout << "Weighted average is: " << avg;

	cout << " The final grade is " << letter_grade << endl;

	return 0;

}

//function defintions go here... You do not need to implement the functions.

Problem 3 (20 points)

Write a short program providing the square root of

1.02.0 + 1.12.1 + 1.22.2+ 1.32.3 + 1.42.4 + 1.52.5 + 1.62.6 + 1.72.7 + 1.82.8 + 1.92.9.

Standards:

Your program will be judged primarily on its correctness. In particular, the program must compile. Programs that do not will receive a severe grade penalty. Over and above this is the requirement of correct behavior: the cubic volume reported must be correct.

Third, there is presentation: prompts should be formatted neatly (exactly matching the example here is good). Both of the two output numbers provided should have two decimal places, which means, they have a precision of two digits after the decimal point.

Finally, your program will be judged on elegance and adherence to the principles of good programming style. Elegance means that there should be nothing there that isn't necessary for the computation: all variables should have a use, as should all assignments to those variables. Style refers to the proper use of indentation, information variable names, documentation with comments, and other matters of readability.

Turn in:


Dan Rao
Last modified: Thu Jul 27 23:54:34 PDT 2005