Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;
- class ISKLUCOK : public exception {};
- class Pateka {
- private:
- char *drzava;
- char ime[50];
- int rekord;
- public:
- Pateka () {}
- Pateka (char *dr,char *ime,int rek) {
- drzava = new char [strlen(dr)+1];
- strcpy(drzava,dr);
- strcpy(this->ime,ime);
- rekord = rek;
- }
- char *getDrzava () {
- return drzava;
- }
- char *getIme () {
- return ime;
- }
- int getRekord () {
- return rekord;
- }
- };
- class Trka {
- private:
- int pozicija;
- int vreme;
- Pateka p;
- public:
- Trka () {}
- Trka (int poz,int vr,Pateka p) {
- if(poz < 1 || poz > 6) throw ISKLUCOK();
- pozicija = poz;
- vreme = vr;
- this->p = p;
- }
- virtual Pateka getPateka () {
- return p;
- }
- int getRek () {
- return p.getRekord();
- }
- int getVreme () {
- return vreme;
- }
- int getPoz() {
- return pozicija;
- }
- };
- class Vozac {
- private:
- char tim[30];
- char ime[50];
- Trka rezultati[10];
- public:
- Vozac () {}
- Vozac (char *t,char *im,Trka *rezul) {
- strcpy(tim,t);
- strcpy(ime,im);
- for(int i=0; i<10; i++)
- rezultati[i]=rezul[i];
- }
- int Mesta () {
- int k=0;
- for(int i=0; i<10; i++) {
- if(rezultati[i].getPoz()<=3)
- k++;
- }
- return k;
- }
- Pateka getPateka (int i) {
- return rezultati[i].getPateka();
- }
- int getRez (int i) {
- return rezultati[i].getVreme();
- }
- int getRek (int i) {
- return rezultati[i].getRek();
- }
- int getPoz (int i) {
- return rezultati[i].getPoz();
- }
- friend ostream& operator << (ostream &x,Vozac &v) {
- x<<v.tim<<", "<<v.ime<<", "<<v.Mesta();
- return x;
- }
- char *getTim () {
- return tim;
- }
- char *getIme () {
- return ime;
- }
- };
- Pateka readPateka() {
- char drzava[30];
- char ime[50];
- int rekord;
- cin>>drzava>>ime>>rekord;
- return Pateka(drzava,ime,rekord);
- }
- Trka readTrka() {
- int finalpoz;
- int vreme;
- Pateka p;
- cin>>finalpoz>>vreme;
- p=readPateka();
- return Trka(finalpoz,vreme, p);
- }
- Vozac readVozac() {
- char tim[30];
- char ime[50];
- Trka rezultati[10];
- cin>>tim>>ime;
- for (int i=0; i<10; i++) {
- rezultati[i]=readTrka();
- }
- return Vozac(tim,ime, rezultati);
- }
- void shampionskiTim (Vozac *vozaci) {
- int suma=0, max = 0;
- char ime[20];
- for(int i=0; i<6; i++) {
- for(int j=0; j<10; j++) {
- if(vozaci[i].getPoz(j)==1) suma+=5;
- if(vozaci[i].getPoz(j)==2) suma+=3;
- if(vozaci[i].getPoz(j)==3) suma+=1;
- }
- if(max<suma && i%2!=0) {
- max=suma;
- strcpy(ime,vozaci[i].getTim());
- suma=0;
- }
- }
- cout<<ime<<"-"<<max;
- }
- void noviRekordi (Vozac *vozaci) {
- int flag = 1;
- for(int i=0; i<6; i++) {
- for(int j=0; j<10; j++) {
- if(vozaci[i].getRez(j) < vozaci[i].getRek(j) && vozaci[i].getPoz(j) == 1) {
- flag=0;
- Pateka p = vozaci[i].getPateka(j);
- cout<<vozaci[i];
- cout<<":"<<p.getDrzava()<<", "<<p.getIme()<<", "<<vozaci[i].getRez(j)<<endl;
- }
- }
- }
- if(flag) cout<< "NEMA NOVI REKORDI"<<endl;
- }
- int main() {
- int test_case;
- cin>>test_case;
- switch(test_case) {
- case 1: {
- cout<<"======TEST CASE 1======="<<endl;
- //proverka na klasata Pateka bez copy construktor/operator=
- char drzava[30];
- char ime[50];
- int rekord;
- cin>>drzava>>ime>>rekord;
- Pateka p(drzava,ime,rekord);
- cout<<p.getDrzava()<<" "<<p.getIme()<<" "<<p.getRekord()<<endl;
- }
- break;
- case 2: {
- cout<<"======TEST CASE 2======="<<endl;
- //proverka na klasata Pateka i potrebnite set get metodi
- Pateka *p1=new Pateka(readPateka());
- cout<<p1->getDrzava()<<" "<<p1->getIme();
- Pateka p2;
- p2 = (*p1);
- cout<<" "<<p2.getRekord()<<endl;
- delete p1;
- }
- break;
- case 3: {
- cout<<"======TEST CASE 3======="<<endl;
- //Proverka na klasata Trka
- //se pecatat drzavata kade bila trkata i vremeto za koe e zavrshena trkata
- Trka t=readTrka();
- cout<<t.getPateka().getDrzava()<<" "<<t.getVreme()<<endl;
- }
- break;
- case 4: {
- cout<<"======TEST CASE 4======="<<endl;
- //Proverka na klasata Vozac
- Vozac v=readVozac();
- cout<<v.getTim()<<" "<<v.getIme()<<endl;
- }
- break;
- case 5: {
- cout<<"======TEST CASE 5======="<<endl;
- //proverka na operator <<
- Vozac v=readVozac();
- cout<<v;
- }
- break;
- case 6: {
- cout<<"======TEST CASE 6======="<<endl;
- //proverka na isklucok
- try {
- Vozac v=readVozac();
- cout<<v.getIme();
- } catch (exception &e) {
- cout<<"ISKLUCOK: Nevalidna vrednost"<<endl;
- }
- }
- break;
- case 7: {
- cout<<"======TEST CASE 7======="<<endl;
- //testiraj shampionskiTim
- Vozac vozaci[6];
- for (int i=0; i<6; i++) vozaci[i]=readVozac();
- shampionskiTim(vozaci);
- }
- break;
- case 8: {
- cout<<"======TEST CASE 8======="<<endl;
- //testiraj noviRekordi
- Vozac vozaci[6];
- for (int i=0; i<6; i++) vozaci[i]=readVozac();
- noviRekordi(vozaci);
- }
- break;
- };
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment