Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 #include #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 studentList; //student_list is another name for list typedef studentList:: iterator list_it; //list_it is another name for list::iterator void load_list(studentList); void print_list(studentList); void retrieveStudent(studentList); void addStudent(studentList); void deleteStudent(studentList); void printStudent (studentList); void printStudentList (studentList); void sortLastName (studentList); void sortGPA (studentList); struct sort_lastName //overloading () to compare two student objects with ordering based on name { bool operator()(const student& s1, const student& s2) { if (s1.lastName < s2.lastName) return true; else return false; } };

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 "<> temp.lastName; list_it it = find (students.begin(), students.end(), temp); cout << "Last name: " << it-> lastName << " " << "First name: " << it-> firstName << endl; cout << "************************************************************" << endl; } void insertStudent(studenList students) { student temp; cout << endl; cout <<"Enter the new students info you want to list: "<> temp.firstName; cout << "First name: "; cin>> temp.lastName; cout << "Student ID: "; cin>> temp.studentID; cout << "E-mail: "; cin>> temp.email; cout << "GPA: "; cin>> temp.gpa; students.push_front(temp); cout << "The new list you want to include: " << endl; print_list(students); cout << "************************************************************" << endl; } void addStudent (studentList students) {

student temp; cout <<"Enter the student's info: "<> temp.firstName; cout << "First name: "; cin>> temp.lastName; cout << "Student ID: "; cin>> temp.studentID; cout << "E-mail: "; cin>> temp.email; cout << "GPA: "; cin>> temp.gpa; students.push_front(temp); cout << "The new list including the sdded student: " << endl; print_list(students); cout << "************************************************************" << endl;

} 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: "<> temp.lastName; list_it it = find (students.begin(), students.end(), temp); cout << "Last name: " << it->lastName << " " << "First name: " << it->firstName << " " << "Student ID: " << it->studentID << " " << "E-mail: " << it->email << " " << "GPA: " << it->gpa << endl; cout << "************************************************************" << endl; } void printStudentList (studentList students) { for (list_it s = students.begin(); s != students.end(); s++) cout << "Last name: " << it->lastName << " " << "First name: " << it->firstName << " " << "Student ID: " << it->studentID << " " << "E-mail: " << it->email << " " << "GPA: " << it->gpa << endl; cout << "************************************************************" << endl; } void sortLastName(studentList students) { students.sort(sort_LastName()); cout << "Sort list by Last Name: " << endl; print_list(students); } // Function definition students gpa void sortGPA(studentList students) { students.sort(sort_GPA()); cout << "Sort list by GPA: " << endl; print_list(students); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Support For Data Mining Applications Discovering Knowledge With Inductive Queries Lnai 2682

Authors: Rosa Meo ,Pier L. Lanzi ,Mika Klemettinen

2004th Edition

3540224793, 978-3540224792

More Books

Students also viewed these Databases questions

Question

Identify the five steps of the consumer decision process.

Answered: 1 week ago

Question

The Functions of Language Problems with Language

Answered: 1 week ago

Question

The Nature of Language

Answered: 1 week ago