السلام عليكم ورحمة الله وبركاته
طلب مني الدكتور مشروع نهائي للفصل هذا وهذا هو
السوال
Mid-term Project
Write a C++ program to read, save, sort, search and display the students’ ids, student names and marks of N students.
N=7 should be declared as a constant in your program. You must use arrays to store the students’ IDs, names and marks.
Note: an enhanced version of this program can be achieved after studying functions and structs.
Your program should display and execute a menu with the following options.
A switch statement must be used to execute the following menu options.
Menu
---------
1. Clear
2. Register a Student (Id, Name, Mark)
3. Display the student with a highest mark
4. Display the marks of all students
5. Display the percentage of the total mark received by each student
6. Sort all marks in ascending order
7. Sort all marks in descending order
8. Search for a student with a given id
9. Search for a student with a given name
10. Search for a student with a given mark
11. Exit
Explanation
1. Clear
This option initializes all the elements of the arrays to -1 to indicate that array is empty and names to null.
2. Register a Student (Id, Name, Mark)
This option reads and stores the student’s id, student’s name and student’s marks. The marks (float numbers) are entered from the keyboard.
3. Display the student with a highest mark
This option displays the student id, name and mark for a student with a highest mark.
4. Display the marks of all students
This option displays the students’ IDs, names, marks of all students.
5. Display the percentage of the total mark received by each student
This option displays the percentage of the total mark for all students.
6. Sort all marks in ascending order
This option sorts all marks in ascending order. You can use any sorting algorithm which uses at least two while loops and one if statement.
7. Sort all marks in descending order
This option sorts all marks in descending order. You can use any sorting algorithm which uses at least two while loops and one if statement.
8. Search for a student with a given id
This option searches for a student with a given id. The program asks the user to enter the id using the keyboard and searches for it. If an appropriate student is found, the program displays the message “student found” and displays the id, name and the mark otherwise it displays a message “no student found”.
9. Search for a student with a given name
This option searches for a student with a given name. The program asks the user to enter the name using the keyboard and searches for it. If an appropriate student is found, the program displays the message “student found” and displays the id, name and mark otherwise it displays a message “no student found”.
10. Search for a student with a given mark
This option searches for a student with a given mark. The program asks the user to enter the mark using the keyboard and searches for it. If an appropriate student is found, the program displays the message “student found” and displays the id, name and mark otherwise it displays a message “no student found”.
11. Exit
The program should display the message “Thanks for using this program”, and exit.
The whole program should work in a loop to enable the user to select an item from menu until the user chooses to exit.
وهاذي محاولتي للحل لكن اريد احد يوضح لي مالاخطاء في الحالة الثالثة
لان اريد ان اكمل البرنامج وارجوكم لان اختبارنا النهائي يوم السبت ويجب ان اخلص منه لكي يبقى لي فرصة لذاكر
هذا حلي
# include < iostream >
# include < string >
using namespace std ;
int main ( )
{
struct student
{
string name ; ,id;
float mark;
};
student x[7] ;
bool E;
cout << " This is Menu please Enter the number of the chosie\n " ;
cout << " 1. Clear \n " ;
cout << "2. Register a Student (Id, Name, Mark)\n " ;
cout<<"3:display the student with a highest mark\n";
cout<<"4:display the mark student\n";
cout<<"5:display the percentage of the total mark received by each student\n";
cout<<"6:sort all mark in ascending order\n";
cout<<"7:sort all mark in descending order\n";
cout<<"8:search for a student with give id\n ";
cout<<"9:search for a student with give name\n ";
cout<<"10:search for a student with give mark \n";
cout<<"11:Exit\n";
E = 1;
while(E){
int chosie ;
cin>> chosie ;
switch ( chosie )
{
case 1:
cout << " 1. Clear \n ";
for ( int i = 0 ; i<7 ; i++ )
{ x.name = " null " ;
x.id = " null " ;
x.mark = 0 ;
}
break;
case 2:
cout << "2. Register a Student (Id, Name, Mark)\n " ;
for ( int i = 0 ; i<7 ; i ++ )
{cout << " please enter your name " ;
cin >> x.name ;
cout << " please enter your id " ;
cin >> x.id ;
cout << " please enter your mark " ;
cin >> x.mark ;
if ( x.mark > 100 )
x.mark = 100 ;
}
break;
case 3 :
cout<<"3:display the student with a highest mark\n";
float mark
for (int k=0 ; k<7 ; k++)
{ if (mark[k]> max) max =mark [k]; }
cout << x.name << endl << x.id << endl << max << endl ;
}
break;
case 4 :
cout<<"4:display the mark student\n";
break;
case 5 :
cout<<"5:display the percentage of the total mark received by each student\n";
break;
case 6 :
cout<<"6:sort all mark in ascending order\n";
break;
case 7 :
cout<<"7:sort all mark in descending order\n";
break;
case 8 :
cout<<"8:search for a student with give id\n ";
break;
case 9 :
cout<<"9:search for a student with give name\n ";
break;
case 10 :
cout<<"10:search for a student with give mark \n";
break;
case 11 :
if (chosie == 11 )
E = 0;
cout << "\nThanks for using this program";
break;
default :
cout << " please chosie from this menue " ;
}
}
return 0;
}