Question: #include #include #include #include using namespace std; / / function to print the last name of the student void printLastName ( string name ) {

#include
#include
#include
#include
using namespace std;
// function to print the last name of the student
void printLastName(string name){
cout << name.substr(name.find_last_of("")+1)<<"";
}
// function to compute and print the grade percentage and letter grade
void computeGrade(int score, int total){
double percentage =(double)score / total *100.0;
double roundedPercentage = ceil(percentage *100000.0)/100000.0;
cout << roundedPercentage <<"%";
if (percentage >=90){
cout << "Excellent" << endl;
}
else if (percentage >=80){
cout << "Well Done" << endl;
}
else if (percentage >=70){
cout << "Good" << endl;
}
else if (percentage >=60){
cout << "Need Improvement" << endl;
}
else {
cout << "Fail" << endl;
}
}
int main(){
// open input file
ifstream myfile ("students.txt");
if (!input.is_open()){
cerr << "Failed to open file." << endl;
return 1;
}
// read data for each student
string name;
int score, total;
for (int i =0; i <10; i++){
input >> name >> score >> total;
// compute and print the grade for the student
printLastName(name);
computeGrade(score, total);
}
// close input file
input.close();
return 0;
}
I cannot get this program to import the file. What am I doing wrong ?I have the file saved as students in that same folder.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!