7.7k views
5 votes
Write a C++ program that computes student grades for an assignment as a percentage given each student's score and the total points. The final score must be rounded up to the nearest whole value using the ceil function in the header file and displayed as a percentage. You must also display the floating-point result up to 5 decimal places. You must use at least 2 functions: one to print the last name of the student and another function to compute and print the percentage as well as "Excellent" if the grade is greater than 90, "Well Done" if the grade is greater than 80, "Good" if the grade is greater than 70, "Need Improvement" if the grade is greater than or equal to 60, and "Fail" if the grade is less than 50. The main function is responsible for reading the input file and passing the appropriate arguments to your functions.

User Euge
by
6.0k points

1 Answer

4 votes

Answer:

See Explaination

Step-by-step explanation:

/ Header files section

#include <iostream>

#include <fstream>

#include <iomanip>

#include <string>

#include <cmath>

using namespace std;

// start main function

int main()

{

// variables declaration

string fileName;

string lastName;

double score;

double total;

double grade;

string description;

// prompt the user to enter the input file name

cout << "Enter the input file name: ";

cin >> fileName;

// open the input file

ifstream infile;

infile.open(fileName);

// exit from the program if the input file does not open

if (!infile)

{

cout << fileName << " file cannot be opened!" << endl;

exit(1);

}

// repeat the loop for all students in the file

infile >> lastName;

while (infile)

{

infile >> score;

infile >> total;

// compute the grade

grade = score / total * 100;

// find the grade's description

if (grade > 90)

description = "Excellent";

else if (grade > 80)

description = "Well Done";

else if (grade > 70)

description = "Good";

else if (grade >= 60)

description = "Need Improvement";

else

description = "Fail";

// display the result of each student

cout << lastName << " " << setprecision(0) << fixed << round(grade) << "% " << setprecision(5) << fixed << (grade * 0.01) << " " << description << endl;;

infile >> lastName;

}

// close the input file

infile.close();

system("pause");

return 0;

} // end of main function

User Janderssn
by
5.8k points