Question: Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each
Rework this project to include a class. As explained in class, your project should have its functionalities moved to a class, and then create each course as an object to a class that inherits all the different functionalities of the class.
You createclass function should be used as a constructor that takes in the name of the file containing the student list.
(This way different objects are created with different class list files.)
Here is the code I need you to alter.
#include
// Return choice return choice; } string convertLower(string s) { string loweredString = ""; // Iterate over each character of string // Convert it into lower case // Return loweredString for (int i = 0; i < s.size(); i++) { loweredString += tolower(s[i]); } return loweredString; } // Sort by name void sortByName(student studentArray[], int size) { for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { // Converts name at index i and j to lowers case string s1 = convertLower(studentArray[i].firstname); string s2 = convertLower(studentArray[j].firstname); // Compare them, if > 0 if ((s1.compare(s2)) > 0) { // Swap the students at i and j student temp = studentArray[i]; studentArray[i] = studentArray[j]; studentArray[j] = temp; } } } }
// Sort by city void sortByCity(student studentArray[], int size) { for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { // Convert city at index i and j to lower case string s1 = convertLower(studentArray[i].city); string s2 = convertLower(studentArray[j].city); // Compare them if ((s1.compare(s2)) > 0) { // Swap the students at i and j student temp = studentArray[i]; studentArray[i] = studentArray[j]; studentArray[j] = temp; } } } } // Sort by student ID void sortByID(student studentArray[], int size) { // Sort array using bubble sort for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { // If id at i > j, swap students at i and j if (studentArray[i].studid > studentArray[j].studid) { student temp = studentArray[i]; studentArray[i] = studentArray[j]; studentArray[j] = temp; } } } } // Sort by GPA void sortByGPA(student studentArray[], int size) { // Sort array using bubble sort for (int i = 0; i < size - 1; i++) { for (int j = i + 1; j < size; j++) { // If gpa at i > j, swap students at i and j if (studentArray[i].gpa > studentArray[j].gpa) { student temp = studentArray[i]; studentArray[i] = studentArray[j]; studentArray[j] = temp; } } } } // Displays the student list void displayData(student studentArray[], int size) { cout << endl; cout << left << setw(15) << "First Name" << setw(15) << "Last Name" << setw(15) << "Major" << setw(15) << "ID" << setw(15) << "GPA" << setw(15) << "Home City" << endl; cout << "---------------------------------------------------------------------------------------------" << endl; // Iterates loop size times and print first name, last name, major id, GPA and home city of student for (int i = 0; i < size; i++) { cout << left << setw(15) << studentArray[i].firstname << setw(15) << studentArray[i].lastname << setw(15) << studentArray[i].major << setw(15) << studentArray[i].studid << setw(15) << studentArray[i].gpa << setw(15) << studentArray[i].city << endl; } } void DropClass() { // drops the class for students that request char oldname[] = "temp.txt"; char newname[] = "studentRecords.txt"; int result; string line, name; cout << "Please Enter the student ID: "; cin >> name; ifstream myfile("studentRecords.txt"); ofstream temp; temp.open("temp.txt"); while (getline(myfile, line)) { if (line.substr(0, name.size()) != name) temp << line << endl; } cout << "The record with the name " << name << " has been deleted if it existed" << endl; myfile.close(); temp.close(); remove("studentRecords.txt"); rename(oldname, newname); } void RegisterClass() { student * ds; int n, i; cout << "Amount of student to be entered: "; cin >> n; ds = new student[n + 1]; if (ds == NULL) { cout << "Error!!!" << endl; exit(1); } //input data for (i = 0; i < n; i++) { cout << "Student #" << i << ": " << endl;
cout << "First Name: "; cin >> ds[i].firstname;
cout << endl << "Last Name: "; cin >> ds[i].lastname;
cout << endl << "Major: "; cin >> ds[i].major;
cout << endl << "StudentId: "; cin >> ds[i].studid;
cout << endl << "gpa: "; cin >> ds[i].gpa;
cout << endl << "phoneNumber: "; cin >> ds[i].phonenumber;
cout << endl << "Home: " << endl; cin >> ds[i].home; } for (i = 0; i < n - 1; i++) for (int j = i + 1; j < n; j++) if (ds[i].aver_grade < ds[j].aver_grade) { student temp = ds[i]; ds[i] = ds[j]; ds[j] = temp; } cout << setiosflags(ios::showpoint) << setprecision(1);
//display data for (i = 0; i < n; i++) cout << ds[i].MSV << setw(3) << ds[i].name << setw(5) << ds[i].name_class << endl << "Average Grade: " << ds[i].aver_grade; delete ds; } /* function sortbyfname { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), comparefirstname); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } function sortbylname { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), comparelastname); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } function sortbymajor { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), compareMajor); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } function sortbyid { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), comparestudentId); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } function sortbygpa { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), comparegpa); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } function sortbyphone { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), comparephoneNumber); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } function sortbyhome { student * ds; int n, i; for (i = 0; i < 100; ++i) cout("%s\t%s\t%s\t%d\t%d\t%s\t%s ", ds[i].FirstName, ds[i].LastName, ds[i].Major, ds[i].StudentId, ds[i].gpa, ds[i].phoneNumber, ds[i].Home); qsort(student, 100, sizeof(struct student), compareHome); for (i = 0; i < 3; ++i) cin("%s\t%s\t%s\t%d\t%d\t%s\t%s ", info[i].id, info[i].gender, info[i].name); } */ int comparefirstname(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int FirstNamecompare = strcmp(e1->firstname, e2->firstname); if (FirstNamecompare == 0) /* same FirstName so sort by Studentid */ return e1->studid - e2->studid; else return -FirstNamecompare; } int comparelastname(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int lastNamecompare = strcmp(e1->lastname, e2->lastname); if (lastNamecompare == 0) /* same LastName so sort by FirstName */ return e1->firstname - e2->firstname; else return -lastNamecompare; } int comparestudentId(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int studentidcompare = strcmp(e1->studid, e2->studid); if (studentidcompare == 0) /* same student id so sort by FirstName */ return 0; // you do not have two students with same id, you can omit this if block else return -studentidcompare; } int comparegpa(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int gpacompare = strcmp(e1->gpa, e2->gpa); if (gpacompare == 0) /* same gpa so sort by FirstName */ return e1->firstname - e2->firstname; else return -gpacompare; } int compareMajor(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int majorcompare = strcmp(e1->major, e2->major); if (majorcompare == 0) /* same major id so sort by FirstName */ return e1->firstname - e2->firstname; else return -majorcompare; } int comparephoneNumber(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int phonecompare = strcmp(e1->phonenumber, e2->phonenumber); if (phonecompare == 0) /* same phone so sort by FirstName */ return e1->firstname - e2->firstname; else return -phonecompare; } int compareHome(const void * s1, const void * s2) { struct student * e1 = (struct student *) s1; struct student * e2 = (struct student *) s2; int homecompare = strcmp(e1->home.c_str(), e2->home.c_str()); if (homecompare == 0) /* same home so sort by FirstName */ return e1->firstname - e2->firstname; else return -homecompare; } int main() { ifstream ifs("studentRecords.txt"); struct student records[25]; int studid; float gpa; long long phonenumber; string path = "studentRecords.txt"; string firstname, lastname, city, major; if (ifs.fail()) { cout << "Error opening student records file (studentRecords.txt)" << endl; exit(1); } // student s; int i = 0; while (!ifs.eof()) { ifs >> studid >> firstname >> lastname >> major >> gpa >> phonenumber >> city; records[i].studid = studid; records[i].firstname = firstname; records[i].lastname = lastname; records[i].major = major; records[i].gpa = gpa; records[i].phonenumber = phonenumber; records[i].city = city; i++; } cout << "Displaying Information," << endl; for (int j = 0; j < i; j++) { cout << records[j].studid << " "; cout << records[j].firstname << " "; cout << records[j].lastname << " "; cout << records[j].major << " "; cout << records[j].gpa << " "; cout << records[j].phonenumber << " "; cout << records[j].city << endl; } cout << endl; ifs.close(); DropClass(); char c; student studList[25]; //object of if stream to read from file std::ifstream openfile; //string content std::string getcontent; //do while loop do { //ask if user wants to continue cout << "Do you want to exit (y/n)?"; cin >> c; // if file opens read the file initialize student object add it to list and print it's content if (openfile.is_open()) { while (!openfile.eof()) { student * s = new student(); getline(openfile, getcontent); cout << getcontent << endl; } } //throw error if file does not open else { cout << "There was an error opening file. "; exit(0); } } while (c != 'y'); return 0; }
?When you are done. Please also send me the code for the class that will be inside the header file.
?Also please note, this is the information inside "studentrecord.txt"
First Name Last Name Major Student ID GPA Phone Number Home City Jane Porter Math 173894 3.9 4015388833 Arlington Clarke Griffith Bio 100100 4.0 3018100100 DC Craig Bellamy Ctec 128490 0.2 2403849399 Bowie Manny Rhodes Chem 183903 2.9 3203848499 Largo Robert Reyes Ctec 137940 3.4 4103948929 Bowie Alexis Rodrigues Hist 128739 3.2 3014732293 Fairfax Daniel Proctor Ctec 103848 2.5 3019382923 DC Oliver Kostermann Cosc 193338 3.8 2049238392 Lanham John Constantine Hist 183779 3.4 3103938493 Alexandria Nagisa Hiroyama Chem 129030 3.7 2402874748 Lanham Simone Xypher Bio 193830 4.0 3013849292 DC Jason Rundelhause Math 139480 0.9 2013874829 Bowie Abel Herrera Cosc 123999 1.5 3013983722 Falls Church Connor Angel Hist 197920 3.7 2402879302 Alexandria Monica Strauss Bio 110030 0.8 4010393849 Greenbelt Claire Matteo Hist 102837 3.1 2402884893 Largo Farida Ahmed Cosc 183920 3.0 3019389282 Arlington David Masterson Hist 127393 1.4 4102937498 Falls Church Chloe Gignac Cosc 188292 3.7 3102338229 Fairfax William Tucker Math 198339 0.5 3019912293 Greenbelt Daniela Moreira Ctec 139300 3.6 2402919933 DC Birgit Prinz Cosc 109022 3.9 2018473993 Bowie
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
