C++ Programming Exercise: Input and Output of Square Roots and Grades, Assignments of Computer Science

A c++ programming exercise that involves writing a program to input real numbers and output their square roots until a negative number is entered. It also includes a separate grade determination function. The expected output format and asks the reader to run the program and check if the output is correct.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-0pe
koofers-user-0pe 🇺🇸

9 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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)
{
pf2

Partial preview of the text

Download C++ Programming Exercise: Input and Output of Square Roots and Grades and more Assignments Computer Science in PDF only on Docsity!

Exercise 10/2/

  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.

  1. 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 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) {

if (received_par >= min_score_par) return 'P'; else return 'F'; }