Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct stu
- {
- int ID,avg;
- string name;
- float mark[6];
- };
- void inpt (stu &x)
- {
- int s=0;
- cout <<"Enter ID: ";
- cin >>x.ID;
- cout <<"Enter Name: ";
- cin >>x.name;
- for (int i=0;i<6;i++)
- {
- cout <<"Enter mark "<<i+1<<" of 6: ";
- cin >>x.mark[i];
- s+=x.mark[i];
- }
- x.avg=s/6;
- }
- void avgf (stu x[],int n)
- {
- int max=x[0].avg,a;
- for (int i=0;i<n;i++)
- if (max<x[i].avg)
- {
- max=x[i].avg;
- a=i;
- }
- cout <<x[a].name<<endl;
- cout <<"The average is: "<<max;
- }
- void prnt (stu x)
- {
- cout <<x.ID<<"\t";
- cout <<x.name<<"\t";
- for (int i=0;i<6;i++)
- cout <<x.mark[i]<<"\t";
- cout <<x.avg<<"\t";
- }
- int main ()
- {
- stu x[100];
- int i,n=0,m,o,X,ex;
- bool Q=false;
- cout <<"Enter 1 to Add, 2 to Input, 3 for the Average, 4 to Print, 5 to Print Choices, 6 to export to file, 7 to import, 0 to Exit!\n";
- while (!Q)
- {
- cout <<"Enter the number: ";
- cin >>o;
- switch (o)
- {
- case 1:
- cout <<"Enter number of students to add: ";
- cin >>m;
- n+=m;
- break;
- case 2:
- cout <<"Enter the number of the student you wish to edit (-1 to exit)";
- do
- {
- cin >>i;
- if (i==-1)
- break;
- inpt(x[i]);
- }
- while (true);
- break;
- case 3:
- avgf(x,n);
- break;
- case 4:
- cout <<"ID\t"<<"name\t";
- for (i=0;i<6;i++)
- cout <<"Mark"<<i<<"\t";
- cout <<"Avg\n";
- for (i=0;i<n;i++)
- {
- prnt(x[i]);
- cout <<endl;
- }
- break;
- case 0:
- Q=true;
- break;
- case 5:
- cout <<"Enter 1 to Add, 2 to Input, 3 for the Average, 4 to Print, 6 to export to file, 7 to import, 0 to Exit!\n";
- break;
- case 6:
- {
- ofstream F ("D:/prog/files/test/Red2.ass",ios::binary);
- cout <<"select the number of student to export";
- cin >>ex;
- F.write((char*)&x[ex].ID,sizeof(x[ex].ID));
- F.write((char*)&x[ex].name,sizeof(x[ex].name));
- F.write((char*)&x[ex].avg,sizeof(x[ex].avg));
- for (i=0;i<6;i++)
- F.write((char*)&x[ex].mark[i],sizeof(x[ex].mark[0]));
- F.close();
- cout <<"Done!";
- }
- break;
- case 7:
- {
- ifstream F ("D:/prog/files/test/Red2.ass",ios::binary);
- cout <<"select the number of student to import";
- cin >>ex;
- F.read((char*)&x[ex].ID,sizeof(x[ex].ID));
- F.read((char*)&x[ex].name,sizeof(x[ex].name));
- F.read((char*)&x[ex].avg,sizeof(x[ex].avg));
- for (i=0;i<6;i++)
- F.read((char*)&x[ex].mark[i],sizeof(x[ex].mark[0]));
- F.close();
- cout <<"Done!";
- }
- break;
- default:
- cout <<"WRONG\n";
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement