#include <iostream>
#include <list>
using namespace std;
enum grandChoice { TEACHER = 1, PUBLIC };
enum choice{ EXIT, CREATE, DELETE, MODIFY, VIEW };
class Student
{
public:
string rollNumber;
string name;
string surname;
int age;
string average;
string numberOfGroup;
Student(string rollNumber, string name, string surname, int age, string average, string numberOfGroup)
{
this->rollNumber = rollNumber;
this->name = name;
this->surname = surname;
this->age = age;
this->average = average;
this->numberOfGroup = numberOfGroup;
}
};
int main()
{
list<Student> students;
//initialization with some students;
students.push_back(Student("1", "John", "Smith", 18, "78", "N101"));
students.push_back(Student("2", "Alice", "Dows", 19, "84", "N101"));
string rollNumber_;
string name_;
string surname_;
int age_ ;
string average_;
string numberOfGroup_;
cout << "Press 1 for Teacher mode\n";
cout << "Press 2 for Student mode\n";
int choice1;
cin >> choice1;
switch (choice1)
{
case TEACHER:
{
bool flag = true;
while (flag)
{
system("cls");
cout << "1 - create student record\n";
cout << "2 - delete record\n";
cout << "3 - modify record\n";
cout << "4 - view all students\n";
cout << "0 - exit\n";
int choice2;
cin >> choice2;
switch (choice2)
{
{case CREATE:
system("cls");
cout << "enter roll number: ";
cin >> rollNumber_;
for (auto iter = students.begin(); iter != students.end(); iter++)
{
if (rollNumber_ == iter->rollNumber)
{
cout << "this number already exists\n";
exit(0);
}
}
cout << "enter name: ";
cin >> name_;
cout << "enter surname: ";
cin >> surname_;
cout << "enter age: ";
cin >> age_;
if (age_ < 6 || age_>100)
{
cout << "wrong input data";
exit(0);
}
cout << "enter average: ";
cin >> average_;
cout << "enter number of group: ";
cin >> numberOfGroup_;
students.push_back(Student(rollNumber_, name_, surname_, age_, average_, numberOfGroup_));
break;
}
{case DELETE:
system("cls");
bool flag2 = false;
cout << "enter number of the student: ";
string choice3;
cin >> choice3;
for (auto iter = students.begin(); iter != students.end(); iter++)
{
if (iter->rollNumber == choice3)
{
students.erase(iter);
flag2 = true;
break;
}
}
if (!flag2)
{
cout << "this number doesn't exist\n";
system("pause");
}
break;
}
{case MODIFY:
bool flag2 = false;
system("cls");
cout << "enter number of the student: ";
string choice4;
cin >> choice4;
for (auto iter = students.begin(); iter != students.end(); iter++)
{
if (iter->rollNumber == choice4)
{
cout << "enter rollnumber: ";
cin >> rollNumber_;
iter->rollNumber = rollNumber_;
cout << "enter name: ";
cin >> name_;
iter->name = name_;
cout << "enter surname: ";
cin >> surname_;
iter->surname = surname_;
cout << "enter age: ";
cin >> age_;
if (age_ < 6 || age_>100)
{
cout << "wrong input data";
exit(0);
}
iter->age = age_;
cout << "enter average: ";
cin >> average_;
iter->average = average_;
cout << "enter number of group: ";
cin >> numberOfGroup_;
iter->numberOfGroup = numberOfGroup_;
flag2 = true;
break;
}
}
if (!flag2)
{
cout << "no student found\n";
system("pause");
}
break;
}
{case VIEW:
system("cls");
for (auto iter = students.begin(); iter != students.end(); iter++)
{
cout << "\nrollnumber: " << iter->rollNumber;
cout << "\nname: " << iter->name;
cout << "\nsurname: " << iter->surname;
cout << "\nage: " << iter->age;
cout << "\naverage: " << iter->average;
cout << "\nnumber of group: " << iter->numberOfGroup;
cout << "\n";
}
system("pause");
break;
}
{case EXIT:
flag = false;
}
}
}
system("cls");
break;
}
case PUBLIC:
bool flag = true;
while (flag)
{
system("cls");
cout << "1 - View whole class\n";
cout << "2 - View record by roll number\n";
cout << "0 - exit\n";
int choice5;
cin >> choice5;
switch (choice5)
{
case 0:
flag = false;
system("cls");
break;
case 1:
system("cls");
for (auto iter = students.begin(); iter != students.end(); iter++)
{
cout << "\nrollnumber: " << iter->rollNumber;
cout << "\nname: " << iter->name;
cout << "\nsurname: " << iter->surname;
cout << "\nage: " << iter->age;
cout << "\naverage: " << iter->average;
cout << "\nnumber of group: " << iter->numberOfGroup;
cout << "\n";
}
system("pause");
break;
case 2:
system("cls");
cout << "enter number of the student: ";
string choice6;
cin >> choice6;
bool flag2 = false;
for (auto iter = students.begin(); iter != students.end(); iter++)
{
if (iter->rollNumber == choice6)
{
system("cls");
cout << "\nrollnumber: " << iter->rollNumber;
cout << "\nname: " << iter->name;
cout << "\nsurname: " << iter->surname;
cout << "\nage: " << iter->age;
cout << "\naverage: " << iter->average;
cout << "\nnumber of group: " << iter->numberOfGroup;
cout << "\n";
system("pause");
flag2 = true;
break;
}
}
if (!flag2)
{
cout << "this number doesn't exist\n";
system("pause");
}
break;
}
}
}
}
Comments
Leave a comment