Advertisement
Guest User

Red

a guest
Jan 25th, 2020
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.27 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. struct stu
  6. {
  7.     int ID,avg;
  8.     string name;
  9.     float mark[6];
  10. };
  11.  
  12. void inpt (stu &x)
  13. {
  14.     int s=0;
  15.     cout <<"Enter ID: ";
  16.     cin >>x.ID;
  17.     cout <<"Enter Name: ";
  18.     cin >>x.name;
  19.     for (int i=0;i<6;i++)
  20.     {
  21.     cout <<"Enter mark "<<i+1<<" of 6: ";
  22.     cin >>x.mark[i];
  23.     s+=x.mark[i];
  24.     }
  25.     x.avg=s/6;
  26. }
  27.  
  28. void avgf (stu x[],int n)
  29. {
  30.     int max=x[0].avg,a;
  31.     for (int i=0;i<n;i++)
  32.         if (max<x[i].avg)
  33.         {
  34.             max=x[i].avg;
  35.             a=i;
  36.         }
  37.     cout <<x[a].name<<endl;
  38.     cout <<"The average is: "<<max;
  39. }
  40.  
  41. void prnt (stu x)
  42. {
  43.     cout <<x.ID<<"\t";
  44.     cout <<x.name<<"\t";
  45.     for (int i=0;i<6;i++)
  46.         cout <<x.mark[i]<<"\t";
  47.     cout <<x.avg<<"\t";
  48. }
  49.  
  50. int main ()
  51. {
  52.     stu x[100];
  53.     int i,n=0,m,o,X,ex;
  54.     bool Q=false;
  55.     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";
  56.     while (!Q)
  57.     {
  58.         cout <<"Enter the number: ";
  59.         cin >>o;
  60.         switch (o)
  61.         {
  62.         case 1:
  63.             cout <<"Enter number of students to add: ";
  64.             cin >>m;
  65.             n+=m;
  66.             break;
  67.         case 2:
  68.             cout <<"Enter the number of the student you wish to edit (-1 to exit)";
  69.             do
  70.             {
  71.             cin >>i;
  72.             if (i==-1)
  73.                 break;
  74.             inpt(x[i]);
  75.             }
  76.             while (true);
  77.             break;
  78.         case 3:
  79.             avgf(x,n);
  80.             break;
  81.         case 4:
  82.             cout <<"ID\t"<<"name\t";
  83.             for (i=0;i<6;i++)
  84.                 cout <<"Mark"<<i<<"\t";
  85.             cout <<"Avg\n";
  86.             for (i=0;i<n;i++)
  87.             {
  88.                 prnt(x[i]);
  89.                 cout <<endl;
  90.             }
  91.             break;
  92.         case 0:
  93.             Q=true;
  94.             break;
  95.         case 5:
  96.             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";
  97.             break;
  98.         case 6:
  99.             {
  100.             ofstream F ("D:/prog/files/test/Red2.ass",ios::binary);
  101.             cout <<"select the number of student to export";
  102.             cin >>ex;
  103.             F.write((char*)&x[ex].ID,sizeof(x[ex].ID));
  104.             F.write((char*)&x[ex].name,sizeof(x[ex].name));
  105.             F.write((char*)&x[ex].avg,sizeof(x[ex].avg));
  106.             for (i=0;i<6;i++)
  107.                 F.write((char*)&x[ex].mark[i],sizeof(x[ex].mark[0]));
  108.             F.close();
  109.             cout <<"Done!";
  110.             }
  111.             break;
  112.         case 7:
  113.             {
  114.             ifstream F ("D:/prog/files/test/Red2.ass",ios::binary);
  115.             cout <<"select the number of student to import";
  116.             cin >>ex;
  117.             F.read((char*)&x[ex].ID,sizeof(x[ex].ID));
  118.             F.read((char*)&x[ex].name,sizeof(x[ex].name));
  119.             F.read((char*)&x[ex].avg,sizeof(x[ex].avg));
  120.             for (i=0;i<6;i++)
  121.                 F.read((char*)&x[ex].mark[i],sizeof(x[ex].mark[0]));
  122.             F.close();
  123.             cout <<"Done!";
  124.             }
  125.             break;
  126.         default:
  127.             cout <<"WRONG\n";
  128.         }
  129.     }
  130.     return 0;
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement