Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <sstream>
- #include <cstdlib>
- using namespace std;
- struct student
- {
- string imie;
- string nazwisko;
- int ocena;
- };
- void wczytaj_dane_studentow(string sciezka,struct student* &studenci, int &liczba_studentow);
- //int podzialFlagaPolski(struct student* studenci, int rozmiar);
- int flagapolska(struct student x[], short n);
- void wys (struct student x[], int p, int k);
- int flagafrancuska(struct student x[], short n, int *ko);
- int main()
- {
- student* st = nullptr;
- int liczba_studentow;
- int k,*ko, p;
- ko = new int;
- wczytaj_dane_studentow("studenci.csv", st, liczba_studentow);
- for (int i = 0; i< liczba_studentow; i++)
- cout << st[i].imie<<" "<<st[i].nazwisko<<" "<<st[i].ocena<<endl;
- k=flagapolska( st, liczba_studentow);
- cout << "Zdali studenci :\n\n";
- wys (st, 0, k+1);
- cout << "" << endl;
- cout << "" << endl;
- cout << "Nie zdali studenci :\n\n";
- wys (st, k+1, liczba_studentow);
- p=flagafrancuska( st, liczba_studentow, ko);
- cout << "reszta 0 :\n\n";
- wys (st, 0, p+1);
- cout << "" << endl;
- cout << "" << endl;
- cout << "reszta 1 :\n\n";
- wys (st, p+1, *ko);
- cout << "" << endl;
- cout << "" << endl;
- cout << "reszta 2 :\n\n";
- wys (st, *ko, liczba_studentow);
- return 0;
- }
- void wczytaj_dane_studentow(string sciezka,struct student* &studenci, int &liczba_studentow)
- {
- if (studenci!=nullptr)
- return;
- ifstream plik;
- plik.open(sciezka);
- string linia;
- plik >> liczba_studentow; //wczytanie l. studentow z pliku
- studenci = new student[liczba_studentow];
- plik>>linia; //dokonczenie wczytywania linijki z l. studentow z pliku
- string temp_ocena,temp_imie,temp_nazwisko;
- for(int i=0; i<liczba_studentow; i++)
- {
- plik>>linia;
- istringstream ss(linia);
- getline(ss, temp_imie, ';');
- getline(ss, temp_nazwisko, ';');
- getline(ss, temp_ocena);
- studenci[i].imie = temp_imie;
- studenci[i].nazwisko = temp_nazwisko;
- studenci[i].ocena = atoi(temp_ocena.c_str());
- }
- plik.close();
- }
- /*int podzialFlagaPolski(struct student* studenci, int liczba_studentow){
- int i=0;
- int j=liczba_studentow-1;
- while(i<j){
- while(studenci[i].ocena <= 10 and i<liczba_studentow-1){
- i++;}
- while(studenci[j].ocena > 10 and j>=0){
- j--;}
- if(i<j){
- swap(studenci[i], studenci[j]);
- i++;
- j--;}
- }
- if(studenci[i].ocena<=10){ return i+1;}
- else{return i;}
- } */
- int flagapolska(struct student x[], short n)
- {
- int p=0, k=n-1;
- int ind;
- while(p<k)
- {
- while(p<n-1 && x[p].ocena>=10) p++;
- while(k>=0 && x[k].ocena < 10) k--;
- if(p<k)
- {
- swap(x[p],x[k]);
- ind = k;
- }
- if(x[p].ocena > 10) ind=p;
- else ind=p-1;
- }
- return k;
- }
- void wys (struct student* x, int p, int k)
- {
- for(int i=p; i<k; i++)
- {
- cout << "imie: " << x[i].imie << " ocena = " << x[i].ocena << endl;
- }
- }
- int flagafrancuska(struct student x[], short n, int* ko)
- {
- int p=-1,s=0 ,k=n;
- while(s<k)
- {
- if(x[s].ocena%3 == 0){
- p++;
- swap(x[p], x[s]);
- s++;}
- else{
- if(x[s].ocena%3==2){
- k--;
- swap(x[k], x[s]);}
- else s++;
- }
- }
- *ko=k;
- return p;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement