In: Computer Science
c++ class homework
Topics
If/Else If statement
Description
Write a program that determines a student’s final grade in the course. The course had three tests (100 points each) and four assignments (also 100 points each). All the test scores make up 70% of the grade and all the assignments 30% of the grade.
The program asks the user to input one by one each of the test scores and each of the assignment scores. From these scores, it computes the percentage of total points obtained by the user. It then determines the user’s final grade according to the table below.
90%-100% A
80%-89.99% B
70%-79.99% C
60%-69.99% D
0%-59.99% F
At the end, the program displays a summary report including: the original tests scores, the original assignment scores, the overall percentage points earned by the user and the final grade.
Requirements
Do the assignment using if/else if statement (not multiple if statements)
Test Data
Use the test data in test run 1 and test run 2 below
(input values are in bold)
(It's OK if your output does not show decimal values in exactly the same way.)
Input Test Run 1
Enter Scores Test 1: 90
Enter Scores Test 2: 90
Enter Scores Test 3: 90
Enter Scores Assignment 1: 90
Enter Scores Assignment 2: 90
Enter Scores Assignment 3: 90
Enter Scores Assignment 4: 90
Output Test Run 1
Summary Report
Test Scores: 90.0, 90.0, 90.0
Assignment Scores: 90.0, 90.0, 90.0, 90.0
Overall Percentage: 90.0%
Final Grade: A
Input Test Run 2
Enter Scores Test 1: 70
Enter Scores Test 2: 72
Enter Scores Test 3: 68
Enter Scores Assignment 1: 66
Enter Scores Assignment 2: 68
Enter Scores Assignment 3: 72
Enter Scores Assignment 4: 74
Output Test Run 2
Summary Report
Test Scores: 70.0, 72.0, 68.0
Assignment Scores: 66.0, 68.0, 72.0, 74.0
Overall Percentage: 70.0%
Final Grade: C
Submit
Copy the following in a file and submit that file.
Final output of test runs.
All the C/C++ source code.
Sample Code
/*
Declare variables t1, t2 and t3 for storing test scores and a1, a2, a3 and a4 for storing assignment scores. The variable pct is used for storing overall percentage. The variable grade is used for scoring the final letter grade
*/
double t1, t2, t3, a1, a2, a3, a4, pct;
string grade;
//write code below to input one by one the test and assignment scores in the above variables
//compute the overall percentage scores
pct = ( ( (t1 + t2 + t3 ) / 3.0 ) * .70 ) + ( ( ( a1 + a2 + a3 + a4 ) / 4.0 ) * .30 );
//compute final grade on the basis of pct scores using if/else if statement
if (pct >= 90) {
grade = "A";
}
else if (pct >= 80) {
grade = "B";
}
else if (pct >= 70) {
grade = "C";
}
//complete the above if/else if statement
#include <iostream>
// To set the decimal precision of double upto 1
// To access setprecision() function
#include <iomanip>
using namespace std;
int main()
{
double t1, t2, t3, a1, a2, a3, a4, pct;
//Test Scores input
cout<<" Enter Scores Test 1:";
cin>>t1;
cout<<" Enter Scores Test 2:";
cin>>t2;
cout<<" Enter Scores Test 3:";
cin>>t3;
// Assignment Scores input
cout<<" Enter Scores Assignment 1:";
cin>>a1;
cout<<" Enter Scores Assignment 2:";
cin>>a2;
cout<<" Enter Scores Assignment 3:";
cin>>a3;
cout<<" Enter Scores Assignment 4:";
cin>>a4;
string grade;
pct = ( ( (t1 + t2 + t3 ) / 3.0 ) * .70 ) + ( ( ( a1 + a2 + a3 + a4
) / 4.0 ) * .30 );
// 90%-100%
if (pct >= 90) {
grade = "A";
}
// 80%-89.99%
else if (pct >= 80) {
grade = "B";
}
// 70%-79.99%
else if (pct >= 70) {
grade = "C";
}
// 60%-69.99%
else if (pct >= 60) {
grade = "D";
}
// 0%-59.99%
else{
grade = "F";
}
// Setting double precision upto 1 only
std::cout << std::fixed;
std::cout << std::setprecision(1);
cout<<"\n Summary Report";
cout<<"\n Test Scores:\t"<<t1<<",
"<<t2<<", "<<t3;
cout<<"\n Assignment
Scores:\t"<<a1<<", "<<a2<<",
"<<a3<<", "<<a4;
cout<<"\n Overall
Percentage:\t"<<pct<<"%";
cout<<"\n Final Grade:\t"<<grade;
return 0;
}
Test Run 1
:
Test Run 2: