spStructuresHW.cpp

#include <iostream> using std::cin; using std::cout; using std::endl; using std::istream; using std::ostream; #include <fstream> using std::ofstream; using std::ifstream; #include <iomanip> using std::left; using std::right; using std::setw; using std::setprecision; using std::fixed; #include <string> using std::string; #include <vector> using std::vector; #include <algorithm> using std::swap; #include <sstream> struct Course { string number; string title; int creditHours; }; struct CompletedCourse { string courceNumber; string courceName; int courceCreditHours; int qualityPointsEarned; float courceAverage; char letterGrade; // specify fields of a completed course }; struct Student { string studentName; int idNumber; string classification; int creditHours; int qualityPointsEarned; float gpa; vector<CompletedCourse> studentCompletedCourses; // specify fields of a student record }; int convertToQualityPoints(char letterGrade); char determineLetterGrade(double average); void readAndCalculateStudentData(istream& infile, const vector<Course>& allCourses, vector<Student>& allStudents); void readCourses(istream& infile, vector<Course>& courses); void sort(vector<Course>& courses); void sort(vector<Student>& students); void write(ostream& outfile, vector<Course> allCourses); void write(ostream& outfile, vector<Student> allStudents); // Complete only one of the following: // The getCourseIndexRecursively function is 5 points and serves as the homework for recursion. // If you cannot complete the recursive function, complete the getCourseIndex function. //vector<Course>::size_type // getCourseIndexRecursively //vector<Course>::size_type // getCourseIndex(const vector<Course>& courses, string courseNumber); int main() { // open courses.txt and read courses into a vector // sort the courses ascending by course number // write the courses to sortedCourses.txt in the same format as the input file // open students.txt and read students into a vector, calculating fields not found in the input file as the data is read // sort the students ascending by name // create a student report in the format shown in the assignment return 0; } int convertToQualityPoints(char letterGrade) { int qualityPoints; if (letterGrade == 'A') qualityPoints = 4; else if (letterGrade == 'B') qualityPoints = 3; else if (letterGrade == 'C') qualityPoints = 2; else if (letterGrade == 'D') qualityPoints = 1; else qualityPoints = 0; return qualityPoints; } char determineLetterGrade(double average) { char letterGrade; if (average > 90.0) letterGrade = 'A'; else if (average > 80.0) letterGrade = 'B'; else if (average > 70.0) letterGrade = 'C'; else if (average > 60.0) letterGrade = 'D'; else letterGrade = 'F'; return letterGrade; } // Must complete for [CO] (5 points) for recursion homework //vector<Course>::size_type getCourseIndexRecursively { // implement a recursive binary search to locate the course number in the Course vector // return the index of its location or the size of the vector to indicate the course number was not found } // Complete only if unable to complete getCourseIndexRecursively //vector<Course>::size_type getCourseIndex(const vector<Course>& courses, string courseNumber) { // implement a binary search to locate the course number in the Course vector // return the index of its location or the size of the vector to indicate the course number was not found } void readAndCalculateStudentData(istream& infile, const vector<Course>& allCourses, vector<Student>& allStudents) { Student oneStudent; while (getline(infile,oneStudent.name,';')) { // read and store the student's idNumber and classification string line; getline(infile, line); std::istringstream iss{line}; // initialize creditHoursCompleted and qualityPoints (in Student structure) in preparation of calculating as courses are read CompletedCourse oneCourse; while (getline(iss,oneCourse.number,';')) { // locate the course in the Courses vector (determine index) // get the course's title and credit hours from the Courses vector and store in the CompletedCourse structure // read and store the average the student made in the course in the CompletedCourse structure // determine the letter grade and quality points for the course and store in the CompletedCourse structure // add the CompletedCourse structure to the student's courses in the Student structure // update student's creditHoursCompleted and qualityPoints in the Student structure } // calculate the student's GPA // add the Student structure to the Student vector // clear the Student structure data as necessary } } void readCourses(istream& infile, vector<Course>& courses) { Course oneCourse; while (infile >> oneCourse.number) { infile.ignore(); infile >> oneCourse.creditHours; infile.ignore(); getline(infile,oneCourse.title); courses.push_back(oneCourse); } } void sort(vector<Course>& courses) { // add code that will sort the courses ascending by the course number } void sort(vector<Student>& students) { // add code that will sort the students ascending by name } void write(ostream& outfile, vector<Course> allCourses) { // for each course outfile << // code to access course number << " " << // code to access course credit hours << " " << // code to access course title << endl; } void write(ostream& outfile, vector<Student> allStudents) { // for each student { outfile << setprecision(1) << fixed << "Student Name: " << // code to access student's name << "\nID Number: " << // code to access student's id number << "\nClassification: " << // code to access student's classification << "\nCredit Hours Completed: " << // code to access student's credit hours << "\nQuality Points: " << // code to access student's quality points << "\nGPA: " << // code to access student's GPA // next two lines deliberately go past 80 characters as each line is a single line in the output file outfile << " " << setw(10) << left << "Course" << setw(60) << left << "Title" << setw(6) << right << "Credit" << setw(8) << right << "Quality" << setw(8) << right << "Average" << " Letter\n" << " " << setw(10) << left << "Number" << setw(60) << left << " " << setw(6) << right << "Hours" << setw(8) << right << "Points" << setw(8) << right << " " << " Grade\n"; // output a dashed line as shown in example output // for each completed course outfile << " " << setw(10) << left << // completed course's number << setw(60) << left << // completed course's title << setw(4) << right << // completed course's credit hours << setw(8) << right << // completed course's quality points << setw(8) << right << // completed course's average << setw(7) << right << // completed course's letter grade outfile << endl << endl; } outfile << endl << endl; }