Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- #include <fstream>
- using namespace std;
- typedef struct elev
- {
- char nume[100], prenume[100];
- int n1,n2;
- float media;
- };
- int main()
- {
- int n;
- elev aux, v[100];
- cout<<"Nr elevi: "; cin>>n;
- ifstream notein("note.txt");
- ifstream numein("nume.txt");
- ofstream fout("final.txt");
- for(int i=0; i<n; i++)
- {
- numein>>v[i].nume; numein>>v[i].prenume;
- notein>>v[i].n1; notein>>v[i].n2;
- v[i].media=(v[i].n1+v[i].n2)/2.00;
- v[i].media=int(v[i].media*100);
- v[i].media=float(v[i].media/100);
- }
- notein.close();
- numein.close();
- for(int i=0; i<n-1; i++)
- for(int j=i+1; j<n; j++)
- 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)
- {
- aux=v[i];
- v[i]=v[j];
- v[j]=aux;
- }
- for(int i=0; i<n-1; i++)
- for(int j=i+1; j<n; j++)
- if(v[i].media<v[j].media)
- {
- aux=v[i];
- v[i]=v[j];
- v[j]=aux;
- }
- for(int i=0; i<n; i++)
- fout<<v[i].nume<<" "<<v[i].prenume<<" "<<v[i].media<<endl;
- fout.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement