Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- using namespace std;
- struct TStudent
- {
- string meno,priez,znamka;
- int rodnecS; };
- int rok(int rc)
- {
- int RR;
- RR = (rc/10000);
- if (RR<12) return (RR + 2000);
- else return (RR + 1900);
- }
- void VypisDatum(int c)
- {
- cout << " ";
- cout << c % 100;
- cout << ". ";
- cout << (c / 100) % 50;
- cout << ". ";
- cout << rok(c);
- }
- int JeZena(int c)
- {
- if (c % 10000 > 5000)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- int PorovnajStudentov(TStudent *s1, TStudent *s2)
- {
- if ((s1->priez) < (s2->priez))
- return 1;
- else
- if (s1->priez > s2->priez)
- return 0;
- else if (s1->meno < s2->meno)
- return 1;
- else if (s1->meno > s2->meno)
- return 0;
- else{
- int r1 = rok(s1->rodnecS);
- int r2 = rok(s2->rodnecS);
- if (r1<r2)
- return 1;
- else if (r1>r2)
- return 0;
- else
- return 0;}
- }
- void InsertionSort(TStudent **pole, int pocet)
- {
- int i, j;
- TStudent* tmp;
- for (i = 1; i<pocet; i++)
- {
- for (j = i, tmp = pole[i]; (j>0) && PorovnajStudentov(tmp, pole[j - 1]); j--)
- pole[j] = pole[j - 1];
- pole[j] = tmp;
- }
- }
- void vypis_studenta(TStudent *s)
- {
- cout << s->priez;
- cout <<" "<< s->meno << " ";
- cout << s->znamka ;
- if (s->rodnecS >= 100000)
- {
- cout <<" "<< "rodne cislo" << " " << s->rodnecS << " ";
- }
- else
- {
- cout <<" "<< "rodnecilo" << " " << s->rodnecS << " ";
- }
- if (JeZena(s->rodnecS) == 1)
- {
- cout << "zena, narodena" << " ";
- }
- else
- {
- cout << "muz, narodeny" << " ";
- }
- VypisDatum(s->rodnecS);
- cout << endl;
- }
- void vypis_studentov(TStudent **st, int poc)
- {
- for (int i = 0; i < poc; i++)
- {
- vypis_studenta(st[i]);
- }
- }
- int main()
- {
- TStudent** studenti = new TStudent*[100];
- char pohlavie;
- int rodneM, pocet;
- string meno, priezvisko, znamka, znamka_vvv;
- int hladany_rok;
- ifstream vstup;
- vstup.open("studenti.txt");
- for (pocet=0; vstup >> meno >> priezvisko >> znamka >> rodneM; pocet++)
- {
- studenti[pocet] = new TStudent();
- studenti[pocet]->meno = meno;
- studenti[pocet]->priez = priezvisko;
- studenti[pocet]->znamka = znamka;
- studenti[pocet]->rodnecS = rodneM;
- }
- cout << " neusporiadany zoznam " << pocet << " studentov zo suboru 'studenti.txt'" << endl;
- vypis_studentov(studenti, pocet);
- cout << endl;
- InsertionSort(studenti, pocet);
- cout << "USPORIADANY zozn. " << pocet << " studentov zo sub 'studenti.txt' funkciou 'insertionSort'" << endl;
- vypis_studentov(studenti, pocet);
- cout << endl;
- cout << "---------------------------------------------------" << endl;
- cout << "vlozte rok narodenia hladanych studentov:";
- cin >> hladany_rok;
- if (hladany_rok >= 1912 && hladany_rok <= 2011)
- {
- cout << "vlozte znamku, ktoru maju mat hladani studenti: ";
- cin >> znamka_vvv;
- cout << endl;
- TStudent** najdeni = new TStudent*[pocet];
- int Najdeny_p = 0;
- for (int i = 0; i < pocet; i++)
- {
- if (rok(studenti[i]->rodnecS) == hladany_rok && studenti[i]->znamka == znamka_vvv)
- {
- najdeni[Najdeny_p] = studenti[i]; Najdeny_p++;
- }
- }
- cout << "narodenie '";
- cout << hladany_rok;
- cout << "' so znamkou '";
- cout << znamka_vvv;
- cout << " ";
- cout << Najdeny_p;
- cout << endl;
- vypis_studentov(najdeni, Najdeny_p);
- }
- for (int i = 0; i <pocet; i++)
- delete studenti[i];
- delete[] studenti;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement