
Exercise 10/2/03
1. Write a C++ program that inputs a sequence of double values, and for each input value outputs its square root. The
program should terminate when the input value is negative. Your program should produce output as shown below:
This program will output the square root for each real number you input.
Press the [RETURN] key after typing each number. Enter a negative
number to terminate the program.
Input Square Root
1.0
1.000
2.0
1.414
3.0
1.732
4.0
2.000
5.0
2.236
-1.0
2. Run the following program and determine if the output is correct. If not, find out why and make the necessary
corrections.
//Determines user’s grade. Grades are Pass or Fail.
#include <iostream>
using namespace std;
char grade(int received_par, int min_score_par);
//Returns ’P’ for passing, if received_par is
//min_score_par or higher. Otherwise returns ’F’ for failing.
int main( )
{
int score, need_to_pass;
char letter_grade;
cout << "Enter your score"
<< " and the minimum needed to pass:\n";
cin >> score >> need_to_pass;
letter_grade = grade(need_to_pass, score);
cout << "You received a score of " << score << endl
<< "Minimum to pass is " << need_to_pass << endl;
if (letter_grade == 'P')
cout << "You Passed. Congratulations!\n";
else
cout << "Sorry. You failed.\n";
cout << letter_grade
<< " will be entered in your record.\n";
return 0;
}
char grade(int received_par, int min_score_par)
{