Andziev

МотоГП Шампионат

Aug 30th, 2016
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.70 KB | None | 0 0
  1. #include<iostream>
  2. #include<cstring>
  3. using namespace std;
  4.  
  5. class ISKLUCOK : public exception {};
  6.  
  7. class Pateka {
  8. private:
  9.     char *drzava;
  10.     char ime[50];
  11.     int rekord;
  12. public:
  13.     Pateka () {}
  14.     Pateka (char *dr,char *ime,int rek) {
  15.         drzava = new char [strlen(dr)+1];
  16.         strcpy(drzava,dr);
  17.         strcpy(this->ime,ime);
  18.         rekord = rek;
  19.     }
  20.     char *getDrzava () {
  21.         return drzava;
  22.     }
  23.     char *getIme () {
  24.         return ime;
  25.     }
  26.     int getRekord () {
  27.         return rekord;
  28.     }
  29. };
  30.  
  31. class Trka {
  32. private:
  33.     int pozicija;
  34.     int vreme;
  35.     Pateka p;
  36. public:
  37.     Trka () {}
  38.     Trka (int poz,int vr,Pateka p) {
  39.         if(poz < 1 || poz > 6) throw ISKLUCOK();
  40.         pozicija = poz;
  41.         vreme = vr;
  42.         this->p = p;
  43.     }
  44.     virtual Pateka getPateka () {
  45.         return p;
  46.     }
  47.     int getRek () {
  48.         return p.getRekord();
  49.     }
  50.     int getVreme () {
  51.         return vreme;
  52.     }
  53.     int getPoz() {
  54.         return pozicija;
  55.     }
  56. };
  57.  
  58. class Vozac {
  59. private:
  60.     char tim[30];
  61.     char ime[50];
  62.     Trka rezultati[10];
  63. public:
  64.     Vozac () {}
  65.     Vozac (char *t,char *im,Trka *rezul) {
  66.         strcpy(tim,t);
  67.         strcpy(ime,im);
  68.         for(int i=0; i<10; i++)
  69.             rezultati[i]=rezul[i];
  70.     }
  71.     int Mesta () {
  72.         int k=0;
  73.         for(int i=0; i<10; i++) {
  74.             if(rezultati[i].getPoz()<=3)
  75.                 k++;
  76.         }
  77.         return k;
  78.     }
  79.     Pateka getPateka (int i) {
  80.         return rezultati[i].getPateka();
  81.     }
  82.     int getRez (int i) {
  83.         return rezultati[i].getVreme();
  84.     }
  85.     int getRek (int i) {
  86.         return rezultati[i].getRek();
  87.     }
  88.     int getPoz (int i) {
  89.         return rezultati[i].getPoz();
  90.     }
  91.     friend ostream& operator << (ostream &x,Vozac &v) {
  92.         x<<v.tim<<", "<<v.ime<<", "<<v.Mesta();
  93.         return x;
  94.     }
  95.     char *getTim () {
  96.         return tim;
  97.     }
  98.     char *getIme () {
  99.         return ime;
  100.     }
  101. };
  102.  
  103. Pateka readPateka() {
  104.     char drzava[30];
  105.     char ime[50];
  106.     int rekord;
  107.     cin>>drzava>>ime>>rekord;
  108.     return Pateka(drzava,ime,rekord);
  109. }
  110.  
  111. Trka readTrka() {
  112.     int finalpoz;
  113.     int vreme;
  114.     Pateka p;
  115.     cin>>finalpoz>>vreme;
  116.     p=readPateka();
  117.     return Trka(finalpoz,vreme, p);
  118. }
  119.  
  120. Vozac readVozac() {
  121.     char tim[30];
  122.     char ime[50];
  123.     Trka rezultati[10];
  124.     cin>>tim>>ime;
  125.     for (int i=0; i<10; i++) {
  126.         rezultati[i]=readTrka();
  127.     }
  128.     return Vozac(tim,ime, rezultati);
  129. }
  130.  
  131. void shampionskiTim (Vozac *vozaci) {
  132.     int suma=0, max = 0;
  133.     char ime[20];
  134.     for(int i=0; i<6; i++) {
  135.         for(int j=0; j<10; j++) {
  136.            
  137.             if(vozaci[i].getPoz(j)==1) suma+=5;
  138.             if(vozaci[i].getPoz(j)==2) suma+=3;
  139.             if(vozaci[i].getPoz(j)==3) suma+=1;
  140.         }
  141.         if(max<suma && i%2!=0) {
  142.             max=suma;
  143.             strcpy(ime,vozaci[i].getTim());
  144.             suma=0;
  145.         }
  146.     }
  147.     cout<<ime<<"-"<<max;
  148. }
  149.  
  150. void noviRekordi (Vozac *vozaci) {
  151.     int flag = 1;
  152.     for(int i=0; i<6; i++) {
  153.         for(int j=0; j<10; j++) {
  154.             if(vozaci[i].getRez(j) < vozaci[i].getRek(j) && vozaci[i].getPoz(j) == 1) {
  155.                 flag=0;
  156.                 Pateka p = vozaci[i].getPateka(j);
  157.                 cout<<vozaci[i];
  158.                 cout<<":"<<p.getDrzava()<<", "<<p.getIme()<<", "<<vozaci[i].getRez(j)<<endl;
  159.             }
  160.         }
  161.     }
  162.     if(flag) cout<< "NEMA NOVI REKORDI"<<endl;
  163. }
  164.  
  165. int main() {
  166.     int test_case;
  167.     cin>>test_case;
  168.     switch(test_case) {
  169.  
  170.     case 1: {
  171.         cout<<"======TEST CASE 1======="<<endl;
  172.         //proverka na klasata Pateka bez copy construktor/operator=
  173.         char drzava[30];
  174.         char ime[50];
  175.         int rekord;
  176.         cin>>drzava>>ime>>rekord;
  177.         Pateka p(drzava,ime,rekord);
  178.         cout<<p.getDrzava()<<" "<<p.getIme()<<" "<<p.getRekord()<<endl;
  179.     }
  180.     break;
  181.  
  182.     case 2: {
  183.         cout<<"======TEST CASE 2======="<<endl;
  184.         //proverka na klasata Pateka i potrebnite set get metodi
  185.         Pateka *p1=new Pateka(readPateka());
  186.         cout<<p1->getDrzava()<<" "<<p1->getIme();
  187.         Pateka p2;
  188.         p2 = (*p1);
  189.         cout<<" "<<p2.getRekord()<<endl;
  190.         delete p1;
  191.     }
  192.     break;
  193.  
  194.     case 3: {
  195.         cout<<"======TEST CASE 3======="<<endl;
  196.         //Proverka na klasata Trka
  197.         //se pecatat drzavata kade bila trkata i vremeto za koe e zavrshena trkata
  198.         Trka t=readTrka();
  199.         cout<<t.getPateka().getDrzava()<<" "<<t.getVreme()<<endl;
  200.     }
  201.     break;
  202.  
  203.     case 4: {
  204.         cout<<"======TEST CASE 4======="<<endl;
  205.         //Proverka na klasata Vozac
  206.         Vozac v=readVozac();
  207.         cout<<v.getTim()<<" "<<v.getIme()<<endl;
  208.     }
  209.     break;
  210.  
  211.     case 5: {
  212.         cout<<"======TEST CASE 5======="<<endl;
  213.         //proverka na operator <<
  214.         Vozac v=readVozac();
  215.         cout<<v;
  216.     }
  217.     break;
  218.  
  219.     case 6: {
  220.         cout<<"======TEST CASE 6======="<<endl;
  221.         //proverka na isklucok
  222.         try {
  223.             Vozac v=readVozac();
  224.             cout<<v.getIme();
  225.         } catch (exception &e) {
  226.             cout<<"ISKLUCOK: Nevalidna vrednost"<<endl;
  227.         }
  228.  
  229.     }
  230.     break;
  231.  
  232.     case 7: {
  233.         cout<<"======TEST CASE 7======="<<endl;
  234.         //testiraj shampionskiTim
  235.         Vozac vozaci[6];
  236.         for (int i=0; i<6; i++) vozaci[i]=readVozac();
  237.         shampionskiTim(vozaci);
  238.     }
  239.     break;
  240.  
  241.     case 8: {
  242.         cout<<"======TEST CASE 8======="<<endl;
  243.         //testiraj noviRekordi
  244.         Vozac vozaci[6];
  245.         for (int i=0; i<6; i++) vozaci[i]=readVozac();
  246.         noviRekordi(vozaci);
  247.     }
  248.     break;
  249.     };
  250.     return 0;
  251. }
Advertisement
Add Comment
Please, Sign In to add comment