Please note I am not trying to have someone do my homework for me. I just am struggling with this program and need help with the functions. I already read the file and created my list. Thanks and here's the assignment:
Program Summary
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
1. Create a student class or struct based on the student structure
2. Create a students class which contains two private members – a pointer to a list of students and a function to print a student’s record. The students class will also provide the following functionality.
a. Load data from a data file into a student list
b. Retrieve and print a student from the student list
c. Insert a student into the student list
d. Delete a student from the student list
e. Print the contents of a student record
f. Print the contents for a list of students
g. Sort the student list by last Name
h. Sort the student list by GPA
Processing requirements
1. Load the students file students.dat
2. Create a menu to carry out the given operations
3. Implement input validation to avoid erroneous program errors
Structure of the file
students.dat – First Name, Last Name, Student ID, Email, GPA
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
using namespace std;
#include <iostream>
#include <fstream>
#include<string>
struct student;
typedef student * studentptr;
struct studentType
{
int info;
studentType *link;
};
studentType *head, *tail;
struct student
{
string firstName;
string lastName;
unsigned int studentID;
string email;
float gpa;
studentptr next;
};
class studentsProc // Definition of class named studentsProc
{
public:
studentsProc();
void loadList(studentptr & students); // Function that loads data from a data file into a student list
void removeStudent(studentptr & students);
private:
student * students; // Pointer to the list of students
void printList() const; //Print the contents of the list
};
studentsProc::studentsProc()
{
head = NULL;
}
void studentsProc::loadList(studentptr & students)
{
ifstream infile;
infile.open("students.dat");
students = NULL; //head pointer points no where
student temp;
studentptr temp_ptr;
while (!infile.eof())
{
temp_ptr = new student;
infile >> temp_ptr->firstName >> temp_ptr->lastName >> temp_ptr->studentID >> temp_ptr->email >> temp_ptr->gpa;//place data in the node
temp_ptr->next = students;
students = temp_ptr;
}
infile.close();
}
int main()
{
return 0;
}
|