السلام عليكم
أنا عضوة يديدة أتمنى انكم تساعدوني ، دورت وااااايد على الحل بس للأسف ما لقيت ، وأتمنى ‘ني القاه عندكم وبأسرع وقت لأن باجر لازم اسلم البرنامج
عندي برنامج مسويته للطلبة أدخل اسماءهم وهم يلعبون لعبة حل مسائل الرياضيات وبعدين تطلع نتايجهم بالترتيب
اللي ابيه شاشات ملونة بس للاسف ما عرفت ولما اسل يوقولون ما يصير ، لأني أنا أستخدم برنامج اسمه TURBO سي بلس بلس
هذا البرنامج
#include<iostream.h>
#include<stdlib.h>
#include<cstring.h>
#include<iomanip.h>
#include<windows.h>
#include<conio.h>
struct stud_inf{ //structure contain the student informaition
string name;
int number;
int grade;
};
struct stud_inf classes[100]; //array of the students in the class
int number; //number of students in the class
//------------------------------------------------------------------------------
//This function takes from the teacher the students information and store thim in
//the array.
void enter_class()
{
int i;
int flag=1; //to determine if there are more students or not
for (i=0;flag==1;i++)
{
cout<< "\n enter the student name: ";
cin>>classes.name;
cout<< "\n enter the student number: ";
cin>> classes.number;
classes.grade=0; //inizialize the grade to zero
cout<< "\n are there more students? (y=1, n=0)";
cin>>flag;
}
number=i+1;
}
//------------------------------------------------------------------------------
//This student checks if the student name who wants to play the game is exists or
//not, if yes it will send his position in the array.
int find_student()
{
int i;
string name;
cout<<"\n Enter your name:";
cin>>name;
for(i=0;i<number;i++)
{
if(name==classes.name)
{
return i;
}
}
cout<<"\n The student is not exist";
return -1;
}
//------------------------------------------------------------------------------
//This function gives the student three simple multiplication equations and ask him
//to solve them, and save his grade in the array.
void The_game(int student)
{
int a, b, result; //a and b are the parameters of equation
int high=9; //the parameters are less than or equal 9
int i;
for(i=0;i<3;i++)
{
a=rand()%high+1; //function rand to give random numbers
b=rand()%high+1;
cout<<"\n How much is "<<a<<" times "<<b<<" ?";
cin>>result;
if(result==(a*b)) //correct answer
{
cout<<"\n very good\n";
classes[student].grade=classes[student].grade+10;
}
else //wrong answer
{
cout<<"\n No, wrong answer\n";
}
}
cout<<"\n your grade is\n "<<classes[student].grade;
}
//------------------------------------------------------------------------------
//This function sort the students of the class according to their grade:
void sort_grade()
{
int i,j,pos;
struct stud_inf biggest;
for( i=0;i<number;i++)
{
biggest.grade=classes.grade;
biggest.name=classes.name;
biggest.number=classes.number;
pos=i;
for(j=i+1;j<number;j++)
{
if(classes[j].grade>biggest.grade)
{
biggest.grade=classes[j].grade;
biggest.name=classes[j].name;
biggest.number=classes[j].number;
pos=j;
}
}
classes[pos].grade=classes.grade;
classes[pos].name=classes.name;
classes[pos].number=classes.number;
classes.grade=biggest.grade;
classes.name=biggest.name;
classes.number=biggest.number;
}
}
//-------------------------------------------------------------------------
//This function print out a list of the students names and grades:
void print_list()
{
int i;
cout<<"\n The order of students according to there grades:";
cout<<"\n Students Name Grade";
cout<<"\n ---------------------------------\n";
for(i=0;i<number;i++)
{
cout<<classes.name<<" "<<classes.grade<<endl;
}
}
//------------------------------------------------------------------------------
int main()
{
int op=0, student;
while(op!=4)
{
cout<<"\n Choose an option from the list:";
cout<<"\n 1:Enter the students of the class.";
cout<<"\n 2:Play the game.";
cout<<"\n 3:Print the list of students.";
cout<<"\n 4:quit";
cin>>op;
if(op==1)
{
enter_class();
}
else if(op==2)
{
student=find_student();
if (student!= -1)
{
The_game(student);
}
}
else if(op==3)
{
sort_grade();
print_list();
getch();
}
else
{
cout<<"Thank you ...";
break;
}
clrscr(); //To clear the screen after each operation
}
return 0;
}