برنامه دریافت 20 درس از ۱۱ دانشجو و ذخیره - ویرایش - حذف و نمایش اونها
با کامپایلر gcc و minGW سازگار هستش

#include <iostream>
#include <cstdlib>
//#include <conio.h>

using namespace std;

void mainMenu();
void showData(int index,int showScores);
long getID(char *str);
int searchID(long goal);
void secondMenu();
void sortByID();
void sortByAverage();
void sortByTops();
void sortByFamily();
void storeStd(int seek);
void clrscr();
int std_count = 0, choice = 1;
long goal = 0;

struct student
{
long ID;
char name[10], family[15], tel[12];
float sum;
struct book
{
char name[15];
float score;
int multiple;
}books[20];
}students[11], reset_std, second_std;

int main (int argc, char *argv[])
{
mainMenu();
return 0;
}

void mainMenu()
{
cout << "\n [1]- Create a new student" << "\n [2]- Edit student" << "\n [3]- Delete student" << "\n [4]- Show student" << "\n [5]- Quit" << "\n" ;
cout << "\n Choose a number between 1 to 5 : ";
cin >> choice;
switch (choice)
{
case 1:
{
storeStd(std_count);
mainMenu();
break;
}
case 2:
{
clrscr();
int index = searchID(getID("Enter the ID to EDIT : "));
if (index != -1)
{
cout << "Student Found\n";
showData(index,1);
storeStd(index);
}
else
cout << "Student Not Found\n";
mainMenu();
break;
}
case 3:
{
clrscr();
int index = searchID(getID("Enter the student`s NAME to DELETE : "));
if (index != -1)
{
students[index] = reset_std;
cout << "Student deleted successfully";
}
else
cout << "Student Not Found\n";
mainMenu();
break;
}
case 4:
{
clrscr();
secondMenu();
break;
}
case 5: exit(0);
default:
{
mainMenu();
break;
}
}
}

void showData(int index,int showScores)
{
cout << "\n ID : " << students[index].ID;
cout << "\n Name : " << students[index].name;
cout << "\n Family : " << students[index].family;
cout << "\n ";
if (students[index].tel[0] == '0' && students[index].tel[1] == '9')
cout << "Mobile : ";
else
cout << "Tel number: 0831-";
cout << students[index].tel;
cout << "\n Average : " << students[index].sum;
cout << "\n";
if (showScores == 1)
{
for(int i = 0; i <= 19; i++)
{
cout << "\n Book : " << students[index].books[i].name;
cout << "\n Grade :" << students[index].books[i].score;
cout << "\n Rate : " << students[index].books[i].multiple << "\n";
}
}
}

void sortByID()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].ID > students[j].ID)
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
showData(i,0);
}
}

void sortByAverage()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].sum < students[j].sum)
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
showData(i,0);
}
}

void sortByFamily()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].family[0] > students[j].family[0])
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
showData(i,0);
}
}

void sortByTops()
{
for (int i = 0; i <=10; i++)
{
for (int j = i; j <= 10; j++)
{
if(students[i].sum < students[j].sum)
{
second_std = students[i];
students[i] = students[j];
students[j] = second_std;
}
}
}
showData(0,0);
showData(1,0);
showData(2,0);
}

long getID(char *str)
{
int id;
cout << "\n " << str;
cin >> id;
return id;
}

int searchID(long goal)
{
for(int i=0; i <= 10; i++)
{
if (students[i].ID == goal)
{
return i;
}
}
return -1;
}

void secondMenu()
{
cout << "\n [1]- Show the list sorted by Family" << "\n [2]- Show the list sorted by ID" << "\n [3]- Show the list sorted by Grade" << "\n [4]- Show 3 best students" << "\n [5]- Exit" << "\n" ;
cout << "\n Choose a number between 1 to 5 : ";
cin >> choice;
switch (choice)
{
case 1:
{
sortByFamily();
secondMenu();
break;
}
case 2:
{
sortByID();
secondMenu();
break;
}
case 3:
{
clrscr();
sortByAverage();
secondMenu();
break;
}
case 4:
{
sortByTops();
secondMenu();
break;
}
case 5:
{
mainMenu();
break;
}
default:
{
clrscr();
secondMenu();
break;
}
}
}

void storeStd(int seek)
{
float x = 0;
long multiple = 0;
clrscr();
cout << " Enter ID : ";
cin >> students[seek].ID;
cout << "\t Enter Name : ";
cin >> students[seek].name;
cout << "\t Enter Family : ";
cin >> students[seek].family;
cout << "\t Enter Tel : ";
cin >> students[seek].tel;
for(int i = 0; i <= 19; i++)
{
cout << "\n Enter the Book`s Name : ";
cin >> students[seek].books[i].name;
cout << "\t Enter Grade : ";
cin >> students[seek].books[i].score;
cout << "\t Enter Rate : ";
cin >> students[seek].books[i].multiple;
multiple += students[seek].books[i].multiple;
x += (students[seek].books[i].score * students[seek].books[i].multiple);
}
students[seek].sum = x / multiple;
if (seek >= std_count)
std_count ++;
}

void clrscr()
{
for (int i = 0; i < 60; i++)
cout << endl;
}