|
this is the code and srry for my delay:
#include <iostream> #include <string> using namespace std;
struct student { int seatnumber; string name; string adress; float marks[6]; }; void input(int i,student s[]) { cout<<endl; cout<<"Enter the name of student("<<i+1<<"):"; cin<<s[i].seatnumber; cin.ignore(); cout<<"Enter the name of student("<<i+1<<"):"; getline(cin,s[i].name); cout<<"Enter the adress of student("<<i+1<<"):"; getline(cin,s[i].adress); cout<<"Enter 6 marks of student ("<<i+1<<"):"; for(int i=0;i<6;i++) { cin>>s[i].marks[i]; } } void edit(student s[],int i) { int choice; char again; do { cout<<"\n to edit the seat number of student("<<i+1<<"):(press 1)"; cout<<"\n to edit the name of student("<<i+1<<"):(press 2)"; cout<<"\n to edit the adress of student("<<i+1<<"):(press 3)"; cout<<"\n to edit the marks of student("<<i+1<<"):(press 4)"; cout<<"\n\n Enter the number u want to do:"; cin>>choise; switch(choise) { case 1: { cout<<"\n Enter the new seat number of student ("<<i+1<<"):"; cin>>s[i].seatnumber; break; } case 2: { cout<<"\n Enter the new name of student ("<<i+1<<"):"; cin>>s[i].ignore(); getline(cin,s[i].name); break; } case 3: { cout<<"\n Enter the new adress of student ("<<i+1<<"):"; cin>>s[i].ignore(); getline(cin,s[i].adress); break; } case 4: { cout<<"\Enter the new marks of student("<<i+1<<")" for(int h=0;h<6;h++); { cin>>s[i].marks[h]; } break; } default: cout<<"\n Error!!\n u must choice (1 or 2 or 3 or 4)\n"; } cout<<"\n do u want edit another data in this student (y or n):"; { cin>> again; } while(again!='n'); } void output(int i,student s[]) { cout<<"\n"; cout<<"the seat number of student("<<i+1<<")is:"; cout<<s[i].seatnumber; cout<<"the name of student("<<i+1<<")is:"; cout<<s[i].name; cout<<"the adress of student("<<i+1<<")is:"; cout<<s[i].adress; cout<<endl; cout<<"the 6 marks of student("<<i+1<<")is:\n"; for(int i=0;i<6;i++) { cout<<s[i].marks[i]<<endl; } } void main() { int n_students; int choice; char again; cout<<"Enter the number of students:"; cin>>n_students; student *s; s=new student [n_students]; //input student for (int i=0;i<n_students;i++) { input(i,s); } do { //choice of equation cout<<"\n\n\n"; cout<<"to add a new student(press 1)\n"; cout<<"to edit the data of student(press 2)\n"; cout<<"to calculate the total marks or grades of a certain student(press 3)\n"; cout<<"to search for student any display his data (press 4)\n"; cout<<"to calculate the avarge marks of student in a certain course (press 5)\n"; cout<<"\n Enter the number u want to do:"; cin>>choice; switch (choice) { case 1: { student *temp; temp = new student[n_student]; for(int t=0;t<n_student;t++) { temp[t]=s[t]; } delete[]s; n_student=n_student+1; s=new student[n_student]; for(int t=0;t<n_student-1;t++) { s[t]=temp[t]; } input(n_students-1,s); break; } case 2: { int n_edit,counter; cout<<"\n Enter teh seat number of student u want to edit:"; cin>>n_edit; for(counter=0;counter<n_student;counter++) { if(s[counter].seatnumber==n_edit) break; } edit(s,counter); break; } case 3: { int n_total,r; float total=0; cout<<"\n enter the seat number of student u want to calculate the total marks:"; cin>>n_total; for(r=0;r<n_student;r++) { if(s[r].seatnumber==n_total) break; } for(int j=0;j<6;j++) { total+=s[r].marks[j]; } cout<<"the total marks of student("<<r+1<<")is:"<<total<<endl; break; } case 4: { int n_search,p; cout<<"\n Enter the seat number of student u want to search:"; cin>>n_search; for(p=0;p<n_student;p++) { if(s[p].seatnumber==n_search) break; } cout"\n the date of this student is:\n"; output(p,s); break; } case 5: { int sum=0,number; cout<<"\n what is the number of course that u want calculate the average marks of student in it\n"; cin>>number; for(int h=0;h<n_students;h++) { sum+=[h].marks[number-1]; } float avg =sum/6.0; cout<<sum/n_students<<endl; break; } default: { cout<<"\n Error !! \n u must choice(1 or 2 or 3 or 4 or 5)\n"; } } cout<<"\n \n whould you like to do another operation (y/n):"<<endl; cin>>again; } while (again != 'n'); delete []s; }
|