SHARE
TWEET

ex14

a guest Mar 26th, 2019 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <cstring>
  3. #include <fstream>
  4.  
  5. using namespace std;
  6.  
  7. typedef struct elev
  8. {
  9.     char nume[100], prenume[100];
  10.     int n1,n2;
  11.     float media;
  12. };
  13.  
  14. int main()
  15. {
  16.     int n;
  17.     elev aux, v[100];
  18.     cout<<"Nr elevi: "; cin>>n;
  19.     ifstream notein("note.txt");
  20.     ifstream numein("nume.txt");
  21.     ofstream fout("final.txt");
  22.     for(int i=0; i<n; i++)
  23.     {
  24.         numein>>v[i].nume; numein>>v[i].prenume;
  25.         notein>>v[i].n1; notein>>v[i].n2;
  26.         v[i].media=(v[i].n1+v[i].n2)/2.00;
  27.         v[i].media=int(v[i].media*100);
  28.         v[i].media=float(v[i].media/100);
  29.     }
  30.     notein.close();
  31.     numein.close();
  32.     for(int i=0; i<n-1; i++)
  33.         for(int j=i+1; j<n; j++)
  34.             if(strcmp(v[i].nume,v[j].nume)==1 || strcmp(v[i].nume,v[j].nume)==0 && strcmp(v[i].prenume,v[j].prenume)==1)
  35.             {
  36.                 aux=v[i];
  37.                 v[i]=v[j];
  38.                 v[j]=aux;
  39.             }
  40.     for(int i=0; i<n-1; i++)
  41.         for(int j=i+1; j<n; j++)
  42.             if(v[i].media<v[j].media)
  43.             {
  44.                 aux=v[i];
  45.                 v[i]=v[j];
  46.                 v[j]=aux;
  47.             }
  48.     for(int i=0; i<n; i++)
  49.         fout<<v[i].nume<<" "<<v[i].prenume<<"  "<<v[i].media<<endl;
  50.     fout.close();
  51.     return 0;
  52. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top