Question
using the following c++ code... #include #include #include #include #include using namespace std; #define MAX_STUDENTS 25 struct Studentdata { string FirstName; string LastName; string Major;
using the following c++ code...
#include
#include
#include
#include
#include
using namespace std;
#define MAX_STUDENTS 25
struct Studentdata {
string FirstName;
string LastName;
string Major;
int studentId;
double gpa;
string phoneNumber;
string Home;
};
void print(Studentdata *data, int n) {
cout << endl;
cout << setw(15) << "FirstName" << setw(15) << "LastName" << setw(10) << "Major" << setw(10) << "StudentID" << setw(5) << "GPA" << setw(12) << "PhoneNumber" << setw(15) << "Home" << endl;
for (int i = 0; i cout << setw(15) << data[i].FirstName << setw(15) << data[i].LastName << setw(10) << data[i].Major << setw(10) << data[i].studentId << setw(5) << data[i].gpa << setw(12) << data[i].phoneNumber << setw(15) << data[i].Home << endl; } cout << endl; } int main() { StudentData data[MAX_STUDENTS]; string filename; cout << "Enter filename: "; cin >> filename; ifstream in(filename.c_str()); if (in.fail()) { cout << "Unable to open " << filename << endl; exit(0); } int i = 0; StudentData temp; bool valid; while (!in.eof()) { valid = true; in >> temp.FirstName >> temp.LastName >> temp.Major >> temp.studentId >> temp.gpa >> temp.phoneNumber >> temp.Home; if (temp.studentId <= 100000 || temp.studentId >= 999999) { cout << temp.FirstName << " " << temp.LastName << " has invalid ID " << temp.studentId << endl; valid = false; } if (temp.phoneNumber.length() != 10) { cout << temp.FirstName << " " << temp.LastName << " has invalid phone number " << temp.phoneNumber << endl; valid = false; } if (temp.gpa>4.0 && temp.gpa<0) { cout << temp.FirstName << " " << temp.LastName << " has invalid gpa " << temp.gpa << endl; valid = false; } if (valid) { data[i] = temp; i++; } } print(data, i); cout << "Current number of students in the class: " << i << endl; return 0; } int RegisterClass{ StudentData *ds; int n,i; cout << "Amount of student to be entered: "; cin >> n; ds = new StudentData[n + 1]; if (ds == NULL) { cout << "Error!!!" << endl; exit(1); } //iput data for (i = 0; i < n; i++) { cout << "Student #" << i << ": " << endl; cout << "First Name: "; cin.get(ds[i].FirstName,20); cout << endl << "Last Name: "; cin.get(ds[i].LastName,3); cout << endl << "Major: "; cin.get(ds[i].Major,5); cout << endl << "StudentId: "; cin.get(ds[i].StudentId,5); cout << endl << "gpa: "; cin.get(ds[i].gpa,5); cout << endl << "phoneNumber: "; cin.get(ds[i].phoneNumber,5); 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) { StudentData 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; return 0; } function sortbyfname{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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{ StudentData *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(StudentData, 100, sizeof(struct StudentData), 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 StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)s2; int FirstNamecompare = strcmp(e1->FirstName, e2->FirstName); if (FirstNamecompare == 0) /* same FirstName so sort by Studentid */ return e1->StudentId - e2->StudentId; else return -FirstNamecompare; } int comparelastname(const void *s1, const void *s2) { struct StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)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 StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)s2; int studentidcompare = strcmp(e1->StudentId, e2->StudentId); if (studentidcompare == 0) /* same student id so sort by FirstName */ return e1->FirstName - e2->FirstName; else return -studentidcompare; } int comparegpa(const void *s1, const void *s2) { struct StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)s2; int gpacompare = strcmp(e1->gpa, e2->gpa); if (gpacompare == 0) /* same gpa so sort by FirstName */ return e1->Major - e2->Major; else return -gpacompare; } int compareMajor(const void *s1, const void *s2) { struct StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)s2; int majorcompare = strcmp(e1->Major, e2->Major); if (majorcompare == 0) /* same major id so sort by FirstName */ return e1->Major - e2->Major; else return -majorcompare; } int comparephoneNumber(const void *s1, const void *s2) { struct StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)s2; int phonecompare = strcmp(e1->phoneNumber, e2->phoneNumber); if (phonecompare == 0) /* same phone so sort by FirstName */ return e1->Major - e2->Major; else return -phonecompare; } int compareHome(const void *s1, const void *s2) { struct StudentData *e1 = (struct StudentData *)s1; struct StudentData *e2 = (struct StudentData *)s2; int homecompare = strcmp(e1->Home, e2->Home); if (homecompare == 0) /* same home so sort by FirstName */ return e1->Major - e2->Major; else return -homecompare; } //Insert of data cout << ds[i].MSV << setw(3) << ds[i].FirstName << setw(5) << ds[i].LastName << setw(5) << ds[i].Major << setw(5) << ds[i].StudentId << setw(5) << ds[i].gpa << setw(5) << ds[i].phoneNumber << setw(5) << ds[i].Home << endl; delete ds; return 0; ___________________________________ Please add the following functions UpdateInfo This is a function that allows the student the opportunity to update any of their information that might have changed or was entered incorrectly. It should give the user the chance to select which information to update, and allow them update it, it should then ask if the user has anything else to update, if they do, it repeats if they dont, print the new class list to reflect the updated data, and the class count. PrintClass This is a function that prints the entire student info in the class list, using the default sorting (by last name). It also displays the class count. DisplayGPA This is a function that takes from the user a certain GPA, and a choice, and displays the complete info of every student with GPA below or above that value depending on their choice. Also display a count for the number of students DisplayBestMajor This is a function that displays the name of the department with the highest average GPA for its students and the GPA average for the department. Also display a count for the number of students Please note: this is the information inside the text file. 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
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