In: Computer Science
c++ class
Topics
Branches
if statement
if/else statement
Description
Write a program that will determine whether the user passed or failed a test. The program will ask the user to input the following:
Maximum Test Score - the maximum total scores in the test.
Percent Pass Score - the minimum percent scores required to pass the test.
User Test Score - the actual scores obtained by the user in the test.
From the above input values, the program will compute the user percent score. It will compare the percent user score with the percent pass score. If the percent user score is equal to or greater than the percent pass score, the program will consider the user having passed the test. Otherwise, the program will consider the user having failed the test. At the end, the program will display the result summary. See the Test section below.
Testing
Perform the test run 1 and the test run 2 below with the data shown below.
(User input is shown in bold.)
(It's OK if your decimal values don't look the same as below so long as they are equal)
Test Run 1
Enter Maximum Test Score:
400
Enter Percent Pass Score:
80
Enter User Test Score:
324
Result Summary
Test Result: Pass
User Test Score: 324
User Percent Score: 81.0 %
Maximum Score: 400
Percent Pass Score: 80.0 %
Test Run 2
Enter Maximum Test Score:
400
Enter Percent Pass Score:
80
Enter User Test Score:
316
Result Summary
Test Result: Fail
User Test Score: 316
User Percent Score: 79.0 %
Maximum Score: 400
Percent Pass Score: 80.0 %
Submit
Copy the following in a file and submit that file.
Output of test runs.
All the C/C++ source code.
Sample Code
// declare variables
double maxScore, pctPassScore, userScore, pctUserScore;
//write code to input maxScore, pctPassScore, userScore
//determine pctUserScore
pctUserScore = (userScore / maxScore) * 100.0
//determine test result
cout << "Result Summary" << endl << endl;
if (pctUserScore >= pctPassScore) {
cout << "Test Result: Pass" << endl;
}
else {
cout << "Test Result: Fail" << endl;
}
#include <iostream>
using namespace std;
int main() {
// declare variables
double maxScore, pctPassScore, userScore, pctUserScore;
//write code to input maxScore, pctPassScore, userScore
//determine pctUserScore
cout<<"Enter Maximum Test Score:"<<endl;
cin>>maxScore;
cout<<"Enter Percent Pass Score:"<<endl;
cin>>pctPassScore;
cout<<"Enter User Test Score:"<<endl;
cin>>userScore;
pctUserScore = (userScore / maxScore) * 100.0;
//determine test result
cout << "Result Summary" << endl << endl;
if (pctUserScore >= pctPassScore) {
cout << "Test Result: Pass" << endl;
}
else {
cout << "Test Result: Fail" << endl;
}
cout <<"User Test Score: "<<userScore<<endl;
cout <<"User Percent Score: "<<pctUserScore<<" %"<<endl;
cout <<"Maximum Score: "<<maxScore<<endl;
cout <<"Percent Pass Score: "<<pctPassScore<<" %"<<endl;
}
==========================
SEE OUTPUT
Thanks, PLEASE COMMENT if there is any
concern.