46.3k views
1 vote
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.

1 Answer

3 votes

Answer:

See Explaination

Step-by-step explanation:

#include <iostream>

#include <string>

#include <fstream>

#include <cmath>

#include <iomanip>

#include <sstream>

using namespace std;

float compute(float mark1,float mark2){

return mark1/mark2*100;

}

void printPercent(string name,float mark1,float mark2){

float percent;

percent=compute(mark1,mark2);

int percentWhole;

percentWhole = ceil(percent);

cout<<name<<" "<<percentWhole<<"% "<<percent;

if(percent>90){

cout<<" Excellent";

}else if(percent>80){

cout<<" Well Done";

}else if(percent>70){

cout<<" Good";

}else if(percent>60){

cout<<" Need Improvement";

}else if(percent<60){

cout<<" Fail";

}

cout<<endl;

}

void processFile(char fileName[20]){

ifstream infile;

string line;//for read line

cout<<"Loading the file........"<<fileName<<endl;

cout<<"File scan done........"<<endl;

infile.open (fileName);

string name;

float mark1,mark2;

if (infile.is_open())

{

while( infile>>name>>mark1>>mark2 ) {

printPercent(name,mark1,mark2);

}

infile.close(); //close file

}

else //if file not found show the below message

{

cout << "Sorry, we could not find the file." << endl;

}

}

int main( )

{

cout << fixed << showpoint << setprecision(3);

string line;//for read line

cout<<"Loading the file........"<<endl;

char fileName[20];

cout<<"Enter file name : ";

cin>>fileName;

processFile(fileName);

return 0;

}

User Nitzan
by
6.4k points