void menu()
{
char choice = 'z';
while (choice == 'z')
{
cout << "MENU:\na.\tList all the courses\nb.\tList all the students\nc.\tAdd a new course to the course list\nd.\tRemove a course from the course list\ne.\tList information of a course\nf.\tRegister a new student to the student list\ng.\tRemove a student from the student list\nh.\tRegister a course for a student\ni.\tDrop a course for a student\nj.\tList information of a student\nk.\tList all of a student's courses\nl.\tList all students enrolled in a course\nm.\tQuit\n\n";
cin >> choice;
if (choice == 'a')
{
listCourses();
choice = 'z';
}
elseif (choice == 'b')
{
listStudents();
choice = 'z';
}
elseif (choice == 'c')
{
string id;
CCourse add;
cout << "Type the course ID, title and number of units.\n";
cin >> id >> add.title >> add.units;
add.setId(id);
addCourse(add);
choice = 'z';
}
elseif (choice == 'd')
{
string id;
cout << "Enter a course ID to remove a course.\n";
cin >> id;
if (checkCourse)
{
removeCourse(id);
}
choice = 'z';
}
elseif (choice == 'e')
{
string id;
int i = 0;
cout << "Enter a course ID to see the information of a course.\n";
cin >> id;
while (i < 5 && Courses[i].getid() != id)
{
i++;
}
cout << Courses[i];
choice = 'z';
}
elseif (choice == 'f')
{
CStudent add;
cout << "Enter student informaiton to add a student.\n";
cin >> add;
addStudent(add);
choice = 'z';
}
elseif (choice == 'g')
{
string id;
cout << "Enter a student ID to delete a student.\n";
cin >> id;
if (checkStudent(id))
{
removeStudent(id);
}
choice = 'z';
}
elseif (choice == 'h')
{
string Student, add;
cout << "Enter the ID of a student to enroll in a course, and the ID of the course they are enrolling in.\n";
cin >> Student >> add;
if (checkStudent(Student))
{
if (checkCourse(add))
{
registerCourse(Student, add);
}
}
choice = 'z';
}
elseif (choice == 'i')
{
string Student, drop;
cout << "Enter the ID of a student to drop from a course, and the ID of the course they are dropping.\n";
cin >> Student >> drop;
if (checkStudent(Student))
{
if (checkCourse(drop))
{
dropCourse(Student, drop);
}
}
choice = 'z';
}
elseif (choice == 'j')
{
string id;
int i = 0;
cout << "Enter a student ID to see the information of a student.\n";
cin >> id;
if (checkStudent(id))
{
while (i < 10 && Students[i].getId() != id)
{
i++;
}
cout << Students[i];
}
choice = 'z';
}
elseif (choice == 'k')
{
string id;
cout << "Enter a student ID to see all of their classes.\n";
cin >> id;
if (checkStudent(id))
{
listStudentCourses(id);
}
choice = 'z';
}
elseif (choice = 'l')
{
string id;
cout << "Enter a course ID to see all the students enrolled in that class.\n";
cin >> id;
if (checkStudent(id))
{
listStudentsInCourse(id);
}
choice = 'z';
}
elseif (choice = 'm')
{
break;
}
else
choice = 'z';
}
}
Just some advice, a switch statement would be better suited for this rather than a lot of IF statements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
switch (choice)
{
case'a':
// do your stuff for a
break;
case'b':
// do your stuff for b
break;
case'c':
// do your stuff for c
break;
// .. and so on
};