Question
I need help with this code it is a Programming exercise from C++ Programming (8th Edition) Chapter 9, Problem 2PE.This is my code so far,
I need help with this code it is a Programming exercise from C++ Programming (8th Edition) Chapter 9, Problem 2PE.This is my code so far, my issue is that the program is not accepting "input.txt" and "output.txt" it will not build successfully i need help please
#include
using namespace std;
struct studentType { string studentFName; string studentLName; char grade; int testScore; } students[20];
int readStudentData(ifstream& inputFile, studentType students[]); void getgrade(studentType students[], int n); void displayData(ofstream& outputFile, studentType students[], int n); void highestTestScore(ofstream& outputFile, studentType students[], int n); bool openInputFile(ifstream& inputFile, char filename[]); void openOutputFile(ofstream& outputFile, char filename[]);
int main() { int n; bool status;
ifstream inputFile; ofstream outputFile; status = openInputFile(inputFile, "input.txt"); if (status) { openOutputFile(outputFile, "output.txt");
n = readStudentData(inputFile, students); getgrade(students, n); displayData(outputFile, students, n); highestTestScore(outputFile, students, n);
outputFile.close();
inputFile.close(); } return 0; } bool openInputFile(ifstream& inputFile, char filename[]) { inputFile.open(filename); if (inputFile.fail()) { cout << "File did not open. Check it once again. "; return false; } return true;
} int readStudentData(ifstream& inputfile, studentType students[]) { int n = 0; inputFile >> students[n].studentFName >> students[n].studentLName >> students[n].testScore; while (inputFile) { n++; inputFile >> students[n].studentFName >> students[n].studentLName >> students[n].testScore; } return n; } void getgrade(studentType students[], int n) { int i; for (i = 0; i } void displayData(ofstream& out, studentType students[], int n) { out << "Last name, First_name, Score Grade "; out << "---------------------------------- "; cout << "Last name, First_name, Score Grade "; cout << "---------------------------------- "; for (int i = 0; i < n; i++) { out << setw(15) << left << students[i].studentLName << setw(15) << students[i].studentFName; out << setw(5) << students[i].testScore << setw(3) << students[i].grade << endl; cout << setw(10) << left << students[i].studentLName << setw(10) << students[i].studentFName; cout << setw(5) << students[i].testScore << setw(3) << students[i].grade << endl; } } void highestTestScore(ofstream& out, studentType students[], int n) { string fname = " "; string lname = " "; int max = 0, i; for (i = 1; i < n; i++) if (students[i].testScore > students[max].testScore) max = i; out << " Highest test score: " << students[max].testScore << endl; out << " Student names having the highest test score: " << endl; cout << " Highest test score: " << students[max].testScore << endl; cout << " Student names having the Highest test score: " << endl; for (i = 0; i cout << students[i].studentLName << "," << students[i].studentFName << endl; } cout << endl; } void openOutputFile(ofstream& outputFile, char filename[]) { outputFile.open(filename); }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started