Alright, so I'm a bit lost as to what to do next with this and am looking for some direction. The assignment sheet is as follows:
CSC 265 – Fall 2009 – Program 1
Due: Thursday October 8, 10 minutes before class starts
Write a header file, implementation file, and main program in which you create a Student class, and then use your class in a menu-driven program. The menu should contain:
1. Create New Student
2. Delete Student (by ID number)
3. Display All students
4. Search for Student (by ID number)
5. QuitUsers will be able to enter in students first and last name, address, and current GPA (ex. 3.8). The ID number will be randomly assigned with a value between 1 and 9999.
Basically, after you create the Student class, you will use it in a main program that works with an array of Students. Make the array size 30, and make sure all input/output is neat and fully error checked.
What to submit:
Submit source code via email. If you are absent, it is still your responsibility to submit on time. Put group members’ last names in the subject line.Keep in mind the following:
• Name your source files student.h, student.cpp, and main.cpp.
• With invalid data, your program should respond appropriately.
• Each function prototype should have a description, preconditions, and postconditions.
• Test your code when you think you are finished. Try to break it. After you are done trying to break it, I will then try.Good Luck! Remember, questions are encouraged.
What I have thus far:
student.h
#ifndef STUDENT_H
#define STUDENT_H
using namespace std;
class Student
{
public:
// CONSTRUCTOR
Student();
// MODIFICATION MEMBER FUNCTIONS
void setID (const int);
void setAddress (const string);
void setFName (const string);
void setLName (const string);
void setGPA (const float);
// CONSTANT MEMBER FUNCTIONS
float getGPA (void) const;
string getFName (void) const;
string getLName (void) const;
string getAddress (void) const;
int getID (void) const;
void display (void) const;
private:
int ID;
float GPA;
string Address;
string FName;
string LName;
};
#endif
student.cpp
#include <iostream>
#include <string>
#include "student.h"
using namespace std;
// CONSTRUCTOR
Student::Student()
{
ID = 0;
GPA = 0;
Address = "";
FName = "";
LName = "";
}
// MODIFICATION MEMBER FUNCTIONS
void Student::setID (const int value)
{
for(int index=0; index<20; index++)
{
value = (rand()%10)+1;
}
if(value>0 && value<9999)
ID = value;
}
void Student::setAddress (const string value)
{
cout << "Please enter new student's address: ";
cin >> value;
if(value != "")
Address = value;
else
cout << "Please enter a valid address!";
}
void Student::setFName (const string value)
{
cout << "Please enter new student's first name: ";
cin >> value;
if(value != "")
FName = value;
else
cout << "Please enter student's first name!";
}
void Student::setLName (const string value)
{
cout << "Please enter new student's last name: ";
cin >> value;
if(value != "")
LName = value;
else
cout << "Please enter student's last name!";
}
void Student::setGPA(const int value)
{
cout << "Please enter new student's GPA (ex: 3.8): ";
cin >> value;
if(value > 0 && value < 4)
pages = value;
else
cout << "Please enter a valid GPA for the student!";
}
// CONSTANT MEMBER FUNCTIONS
int Student::getGPA(void) const
{
return GPA;
}
int Student::getID(void) const
{
return ID;
}
string Student::getFName(void) const
{
return FName;
}
string Student::getLName(void) const
{
return LName;
}
string Student::getAddress(void) const
{
return Address;
}
void Student::display(void) const
{
cout << "ID: " << ID << endl;
cout << "Name: " << FName << " " << LName << endl;
cout << "Address: " << Address << endl;
cout << "GPA: " << GPA << endl;
}
main.cpp
#include <iostream>
#include <string>
#include "student.h"
using namespace std;
int main(void)
{
Student students[30];
int term = 0;
int searchID = 0;
do
{
for (int j=0; j<30; j++)
{
cout << "MENU" << endl;
cout << "1. Create New Student" << endl;
cout << "2. Delete Student (by ID Number)" << endl;
cout << "3. Display All Students" << endl;
cout << "4. Search for Student (by ID Number)" << endl;
cout << "5. Quit" << endl;
cin >> menuChoice;
if (menuChoice == 1)
{
students[j].setID();
students[j].setFName();
students[j].setLName();
students[j].setAddress();
students[j].setGPA();
}
else if (menuChoice == 2)
{
students[j].setID(0);
students[j].setFName("");
students[j].setLName("");
students[j].setAddress("");
students[j].setGPA(0);
}
else if (menuChoice == 3)
{
for (int k=0; k<j; k++)
{
students[k].display();
}
}
else if (menuChoice == 4)
{
cout << "Which student are you looking for? (Please enter their ID Number) ";
cin >> searchID;
students[searchID].display();
}
else if (menuChoice = 5)
{
term = 1;
}
else
cout << "Please enter in a correct menu choice: ";
}
}while(term == 0);
system("pause");
return 0;
}
Any help will be greatly appreciated!!! It is definitely possible that I could be doing something entirely wrong. It's just been so long since I've taken a programming course.