برنامج طلاب والمطلوب الاجراءات التالية:
1- display class
2 - sort by name
3- sort by number
3- sort by grade
4- first in class
5- first in each subject
6- add new student
7- exit
المدخلات :
تحديد عدد الطلاب
ادخال الاسم و الرقم والدرجة
اذا ممكن بس اعرف ايش الفشال في البرنامج دا مع اني عملته بالمصفوفات بس ابغاه بالتراكيب
المحاولة:
[CODE]#include<iostream>
using namespace std;
void SortNames(struct student stu[n],int i)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(stu.name<stu[j].name)
{
string s=stu.name;
stu.name=stu[j].name;
stu[j].name=s;
float t=stu.grd;
stu.grd=stu[j].grd;
stu[j].grd=t;
int m=stu.num;
stu.num=stu[j].num;
stu[j].num=m;
}
for(i=0;i<n;i++)
{
cout<<"the name\t\t"<<"the number\t\t"<<"the grade\t\t";
cout<<stu.name<<stu.num<<stu.grd;
}
}
void Sortnumber(struct student stu[n],int i,int n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(stu.num<stu[j].num)
{
string s=stu.name;
stu.name=stu[j].name;
stu[j].name=s;
float t=stu.grd;
stu.grd=stu[j].grd;
stu[j].grd=t;
int m=stu.num;
stu.num=stu[j].num;
stu[j].num=m;
}
for(i=0;i<n;i++)
{
cout<<"the name\t\t"<<"the number\t\t"<<"the grade\t\t";
cout<<stu.name<<stu.num<<stu.grd;
}
}
void sortgrade(struct student stu[n],int i,int n)
{
for(int i=0;i<n;i++)
for(int j=0;j<n;j++)
if(stu.grd>stu[j].grd)
{
string s=stu.name;
stu.name=stu[j].name;
stu[j].name=s;
float t=stu.grd;
stu.grd=stu[j].grd;
stu[j].grd=t;
int m=stu.num;
stu.num=stu[j].num;
stu[j].num=m;
}
for(i=0;i<n;i++)
{
cout<<"the name\t\t"<<"the number\t\t"<<"the grade\t\t";
cout<<stu.name<<stu.num<<stu.grd;
}
}
int Searchname(struct student stu[n],int i,int n,char key)
{
for(int i=0;i<n;i++)
if(names==key)
{
cout<<"\n"<<"the name"<<"\t"<<"the number"<<"\t"<<"total"<<"\t"<<"mark"<<"\t"<<"average"<<"\t";
cout<<"\n"<<names<<"\t\t"<<a<<"\t\t"<<total<<"\t"<<mark<<"\t"<<x<<endl;
}
return 1;
// return -1;
}
int menu()
{
int choice;
cout<<"\nCHOOSE ONE OF THE FOLLOWING:";
cout<<"\n1-SHOW ALL INFORMATION FOR STUDENT.";
cout<<"\n2-NAMES IN SORTED .";
cout<<"\n3-NUMBER IN SORTED .";
cout<<"\n4-TOTAL IN SORTED .";
cout<<"\n5-SEARCH ABOUT NAME.";
cout<<"\n6-SEARCH ABOUT NUMBER.";
cout<<"\n7-EXIT.";
cin>>choice;
return choice;
}
main()
{
struct student stu[n]
{
char name;
float grd;
int num;
};
int n=100;
cout<<"Enter the number of student"<<endl;
cin>>n;
struct student stu[100];
int i;
for (i=0;i<n;i++)
{
cout<<"name of student["<<i+1<<"]";
cin>>stu.name;
cout<<"grade of student["<<i+1<<"]";
cin>>stu.grd;
cout<<"number of student["<<i+1<<"]";
cin>>stu.num;
}
while(true)
{
int choice;
choice=menu();
if(choice==0)
{
ntm(student stu[],i,n);
}
else if(choice==1)
{
SortNames(student stu[],i,n);
}
else if(choice==2)
{
Sortnumber(student stu[],i,n);
}
else if(choice==3)
{
sortTotal(student stu[],i,n);
}
else if(choice==4)
{
cout<<"\n\nEnter A Name To Be Searched For:";
cin>>key;
d=Searchname(stu[].name,stu[].num,stu[].grd,i,n);
if(d>=1)
cout<<"\nThe Name Is Found.\n"<<endl;
else
cout<<"\nThe Name Is Not Found.\n";
}
else if(choice==7)
break;
else
cout<<"\nBad Choice Try Again.\n";
}
}