Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <algorithm>
- using namespace std;
- struct uczen
- {
- char imie[50];
- char nazwisko[100];
- float punkty;
- };
- void sort(unsigned n, uczen tab[]);
- void wypisz(unsigned n, uczen tab[]);
- int main()
- {
- cout<<"Odczytuje z pliku Wyniki.txt: "<<endl;
- uczen tab[100];
- int tab1[100];
- char nazwa[50];
- cout<<"Podaj nazwe ";
- cin>>nazwa;
- ofstream zapis("wynikSort.txt");
- ifstream odczyt(nazwa);
- int i;
- int j;
- int k;
- int m;
- while(!odczyt.eof())
- {
- odczyt>>tab[j].imie;
- odczyt>>tab[j].nazwisko;
- odczyt>>tab[j].punkty;
- j++;
- }
- odczyt.close();
- unsigned n=j;
- cout<<"Wyniki: "<<endl;
- for(int j=0;j<n;j++)
- {
- cout<<tab[j].imie<<" "<<tab[j].nazwisko<<" "<<tab[j].punkty<<endl;
- }
- cout<<"Wyniki posortowane to: "<<endl;
- sort(n,tab);
- wypisz(n,tab);
- }
- void sort(unsigned n, uczen tab[])
- {
- uczen pom;
- for(int i=0;i<n;i++)
- for(int j=0;j<n;j++)
- {
- if(tab[j].punkty>tab[j+1].punkty)
- {
- pom=tab[j];
- tab[j]=tab[j+1];
- tab[j+1]=pom;
- }
- }
- }
- void wypisz(unsigned n, uczen tab[])
- {
- for(int j=0;j<n;j++)
- {
- cout<<tab[j].imie<<" "<<tab[j].nazwisko<<" "<<tab[j].punkty<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement