Question
Need help with this program to use the standard template library list to store your data. Write a C++ object-oriented program to manage a file
Need help with this program to use the standard template library list to store your data.
Write a C++ object-oriented program to manage a file system for students at Norfolk State University:
First Name string
Last Name string
Student ID unsigned integer
Email string
GPA - float
The program will manipulate the student list based on students from the file students.dat
Class requirements
Create a student class or struct based on the student structure
Create a students class which contains two private members a pointer to a list of students and a function to print a students record. The students class will also provide the following functionality.
Load data from a data file into a student list
Retrieve and print a student from the student list
Insert a student into the student list
Delete a student from the student list
Print the contents of a student record
Print the contents for a list of students
Sort the student list by last Name
Sort the student list by GPA
Processing requirements
Load the students file students.dat
Create a menu to carry out the given operations
Implement input validation to avoid erroneous program errors
Structure of the file
students.dat First Name, Last Name, Student ID, Email, GPA
If you had a working program 1, then there is no need to change your main function. If you do not have a satisfactory working program, I can provide you with one.
Smith Jefferey 891789 j.smith@spartans.nsu.edu 3.75 Lee Jackson 3678902 j.lee@spartans.nsu.edu 3.66 Gonzales Mariana, 168790 m.gonzales18@spartans.nsu.edu 4.0 Jones Mike 8973125 m.jones143@spartans.nsu.edu 3.1 Williams Anita 2985465 a.williams@spartans.nsu.edu 3.64 Ronsinson Taylor 3278976 t.robinson@spartans.nsu.edu 3.55 Clark Allen 1094567 a.clark@spartans.nsu.edu 3.48 Turner Tavon 318796 t.turner@spartans.nsu.edu 3.2 Jenkins Nelson 289563 n.jenkins@spartans.nsu.edu 3.0
This is the code I have so far:
#include #include
using namespace std;
struct student { string firstName; string lastName; string email; float gpa; unsigned int studentID; //overloading < to compare two student objects bool operator < (const student& s) { if (s.lastName > lastName) return true; else return false; } //overloading == to compare two student objects bool operator == (const student& s) { if (s.lastName == lastName) return true; else return false; } }; typedef list
struct sort_gpa //overloading () to compare two student objects with ordering based on gpa { bool operator()(const student& s1, const student& s2) { if (s1.gpa < s2.gpa) return true; else return false; // return ( (s1.name < s2.name) ); } }; int main() {
string name; student temp; studentList students; int process; { // Menu options to carry out specific operations for student list cout << "Choose an option from this menu" << endl << endl; cout << "1. Retrieve and print a student from the student list " << endl; cout << "2. Insert a student into the student list " << endl; cout << "3. Delete a student from the student list " << endl; cout << "4. Print the contents of a student record " << endl; cout << "5. Print the contents for a list of students " << endl; cout << "6. View the students list sorted by last name " << endl; cout << "7. View the students list sorted by GPA " << endl; cout << "8. Exit the program" << endl; cin >> choice;
// Switch menu that carries out the specific operations for student list based on the user's input switch (choice) { case 1: retrieveStudent(); // break; case 2: insertStudent(); break; case 3: deleteStudent(); break; case 4: printStudent(); break; case 5: printList(); break; case 6: sortLastName(); break; case 7: sortGPA(); break; case 8: exit(0); default: cout << "Please enter a value 1-7" << endl; } } while (choice != 9);
return 0; } void loadList(studentList & students) { ifstream infile; infile.open("student.dat");
student temp;
while (!infile.eof() ) {
infile >> temp.lastName >> temp.firstName >> temp.studentID >>temp.email >> temp.gpa;//place data in the node students.push_back(temp); } infile.close(); cout << "************************************************************" << endl; } void retrieveStudent(studentList students) { student temp; cout <<"Please enter student to find "<
student temp; cout <<"Enter the student's info: "<
} void deleteStudent (studentList students) { student temp; cout << "Please enter student you wish to remove " << endl; cin>> temp.lastName; students.remove(temp); cout << "the new list: " << endl; print_list(students); cout << "************************************************************" << endl; } void printStudent (studentList students) { student temp; print_list(students); cout <<"Enter the student's last name whose record you wish to view: "<
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