When i choose switch case 1 and entered the details , it's showing me ! Segmentation fault. I feel like it's because of the array input. but how to avoid that or is there anyway tackle the issue ? Question - Based on Problem 1 and 2 above, modify the program so that it will display a menu for the user to choose either to; Add new students Display student list Add new course Display Course Offered The user can choose to safely exit/terminate the program. Problem 4 Based on Problem 1 until 3 above, modify the program so that the user will be able to modify the name of the selected student.
#include <iostream>
#include <string>
using namespace std;
struct Student{
string name , id , nickname;
};
struct Course{
string ccode, cname, clecturer;
};
int main() {
int i=0, c=0, ti=0, tc=0;
Student uniten[i];
Course cuniten[c];
cout << "\n \n" << endl;
int choice;
bool gameOn = true;
while (gameOn != false){
cout << "*******************************\n";
cout << " 1 - Add new students.\n";
cout << " 2 - Display student list.\n";
cout << " 3 - Add new course.\n";
cout << " 4 - Display course offered.\n";
cout << " 5 - Exit.\n";
cout << " Enter your choice and press return: ";
cin >> choice;
switch (choice)
{
case 1:
cout << "Add new students.\n";
i = i+1;
cout << "\n \n" << endl;
cout << "Student " << i << endl;
cout << "Enter Student ID: ";
cin >> (uniten[i].id);
cout << "Enter their Name: ";
cin >> uniten[i].name;
cout << "Enter their Nickname: ";
cin >> uniten[i].nickname;
cout << "\n \n" << endl;
break;
case 2:
cout << "Display Student List\n";
break;
case 3:
cout << "Add new course.\n";
c = c+1;
cout << "\n \n" << endl;
cout << "Course " << c << endl;
cout << "Enter Course Code: ";
cin >> (cuniten[c].ccode);
cout << "Enter Course Name: ";
cin >> cuniten[c].cname;
cout << "Enter Lecturer Name: ";
cin >> cuniten[c].clecturer;
break;
case 4:
cout << "Display Course List\n";
for (tc=0; tc<c; tc++) {
cout << "Course : " << cuniten[i].cname << " Course Code : " << cuniten[i].ccode << ", Lecturer name : " << cuniten[i].clecturer <<endl;
cout << "\n \n" << endl;
}
break;
case 5:
cout << "End of Program.\n";
gameOn = false;
break;
default:
cout << "Not a Valid Choice. \n";
cout << "Choose again.\n";
cin >> choice;
break;
}
}
}