Ok so this is what I am trying to do but seem to have a problem with my input loop because it keeps reading in only the first set of student data. I am also unsure where to put the cin.ignore because my getline function is not working. Please fogive me for all the code commented out I've just been having a tough time with this program. Any help you could give me I would greatly appreciate.
-thank you
Program Design: Your main function in the client program pgm6main.cpp should do the following:
1. Declare an array of Student objects that can hold up to 10 student's data.
2. Read in the data from the file pgm6.dat. Store the last name, first name, major, cumulative quality points, and cumulative credits in the next available element of the array. For each class the student has completed for the semester read in the letter grade and course credits. Pass these to the updateCumData member function to update the cumulative points and credits.
3. Call a function to display a menu and return a menu selection. For menu selections 1-4 call a function as described below to carry out the operation. The menu should look like this:
1. Print student list
2. Add new student
3. Change student major
4. Delete student
5. Quit
Enter selection (1-5):
#include "pgm6.h"
#include <iostream>
#include <fstream>
#include <iomanip>
using namespace std;
void displayMenu(Student[], int);
void printStudentList(Student[], int);
void addStudent();
void changeMajor();
void deleteStudent();
int main(){
int pstudentID, pcumPoints, pcumCredits, pCredits;
string plastName, pfirstName, pmajor, gradeLvl, pGrade;
ifstream indata;
int i = 0;
int filledCount;
//double GPA;
Student classMate[10];
indata.open("lib/pgm6.dat");
indata >> pstudentID; //prime the loop
while (!indata.eof() && i < 10){
classMate[i].setstudentID(pstudentID);
indata >> plastName;
classMate[i].setlastName(plastName);
indata >> pfirstName;
classMate[i].setfirstName(pfirstName);
getline (indata, pmajor);
classMate[i].setMajor(pmajor);
indata >> pcumPoints;
classMate[i].setcumPoints(pcumPoints);
indata >> pcumCredits;
classMate[i].setcumCredits(pcumCredits);
indata >> pGrade;
indata >> pCredits;
classMate[i].updateCumData(pGrade, pCredits);
i++;
filledCount++;
indata >> pstudentID;
} //end while
displayMenu(classMate, filledCount);
return 0;}
//************************************************
//Function to display menu of choices
//************************************************
void displayMenu(Student classMate[], int filledCount){
int choice;
cout << "1. Print student list" << endl;
cout << "2. Add new student" << endl;
cout << "3. Change student major" << endl;
cout << "4. Delete student" << endl;
cout << "5. Quit" << endl;
cout << endl;
cout << "Enter selection (1-5): " << endl;
cin >> choice;
if (choice == 1)
printStudentList (classMate, filledCount);
// else if (choice == 2)
// addStudent ();
// else if (choice == 3)
// changeMajor ();
// else if (choice == 4)
// deleteStudent ();
// else;
}
//************************************************
//Function to print student list
//************************************************
void printStudentList(Student classMate[], int filledCount){
cout << setw(15) << "StudentID";
cout << setw(15) << "Last Name";
cout << setw(15) << "First Name";
cout << setw(15) << "Major";
cout << setw(20) << "Quality Points";
cout << setw(15) << "Credits";
cout << setw(15) << "GPA";
cout << setw(15) << "Status" <<endl;
cout << "---------------------------------------------" <<endl;
int i;
for(i=0; i<filledCount; i++){
cout << setw(15) << classMate[i].getstudentID();
cout << setw(15) << classMate[i].getlastName();
cout << setw(15) << classMate[i].getfirstName();
cout << setw(15) << classMate[i].getMajor();
cout << setw(15) << classMate[i].getcumPoints();
cout << setw(23) << classMate[i].getcumCredits();
// cout << setw(20) << classMate[i].getGPA();
// cout << setw(15) << classMate[i].getStatus();
cout << "" << endl;
}//end loop
}// end function
and this is the output that i get when running it
1. Print student list
2. Add new student
3. Change student major
4. Delete student
5. Quit
Enter selection (1-5):
1
StudentID Last Name First Name Major Quality Points Credits GPA Status
---------------------------------------------
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason -1 2134901055
101 Young Jason