Advertisement
MikiStrail

Задачи за вежбање за втор колоквиум - ООП Дел 2

May 31st, 2019
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 21.12 KB | None | 0 0
  1. 9. Фудбалска екипа
  2. #include <iostream>
  3. #include <cstring>
  4. using namespace std;
  5.  
  6. // vashiot kod ovde
  7. class FudbalskaEkipa{
  8. protected:
  9.     int golovi[10];
  10.     char imeTrener[100];
  11. public:
  12.    
  13.     FudbalskaEkipa(const char *imeTrener,int *golovi)
  14.     {
  15.         strcpy(this->imeTrener,imeTrener);
  16.         for(int i=0;i<10;i++)
  17.         {
  18.             this->golovi[i]=golovi[i];
  19.         }
  20.     }
  21.     FudbalskaEkipa &operator+=(int gol)
  22.     {
  23.         int tmp[10];
  24.         for(int i=1; i<10; i++)
  25.             golovi[i-1]=golovi[i];
  26.         golovi[9]=gol;
  27.         return *this;
  28.     }
  29.     virtual int uspeh()=0;
  30.     virtual ~FudbalskaEkipa(){};
  31.     char *getTrener()
  32.     {
  33.         return imeTrener;
  34.     }
  35.     virtual char *getIme()=0;
  36. };
  37. class Klub:public FudbalskaEkipa{
  38. private:
  39.     char *ime;
  40.     int brTituli;
  41. public:
  42.  
  43.     Klub(char *imeTrener,int *golovi,char *ime,int brTituli):FudbalskaEkipa(imeTrener,golovi)
  44.     {
  45.         this->ime=new char(strlen(ime));
  46.         strcpy(this->ime,ime);
  47.         this->brTituli=brTituli;
  48.     }
  49.  
  50.     ~Klub(){
  51.     delete[]ime;}
  52.     int uspeh()
  53.     {
  54.         int i,sum=0;
  55.         for(i=0;i<10;i++)
  56.         {
  57.             sum+=golovi[i];
  58.         }
  59.         sum*=3;
  60.         sum+=(brTituli*1000);
  61.         return sum;
  62.     }
  63.     char *getIme()
  64.     {
  65.         return ime;
  66.     }
  67.     bool operator>(Klub &k)
  68.     {
  69.         if(uspeh()>k.uspeh())
  70.             return true;
  71.         else return false;
  72.     }
  73.  
  74.  
  75.  
  76. };
  77. class Reprezentacija:public FudbalskaEkipa{
  78. private:
  79.     char *ime;
  80.     int brNastapi;
  81. public:
  82.     Reprezentacija(char *imeTrener,int *golovi,const char *ime,int brNastapi):FudbalskaEkipa(imeTrener,golovi)
  83.     {
  84.         this->ime=new char(strlen(ime));
  85.         strcpy(this->ime,ime);
  86.         this->brNastapi=brNastapi;
  87.  
  88.     }
  89.    
  90.      ~Reprezentacija(){
  91.     delete[]ime;}
  92.     int uspeh()
  93.     {
  94.         int i,sum=0;
  95.         for(i=0;i<10;i++)
  96.         {
  97.             sum+=golovi[i];
  98.         }
  99.         sum*=3;
  100.         sum+=(brNastapi*50);
  101.         return sum;
  102.     }
  103.     char *getIme()
  104.     {
  105.         return ime;
  106.     }
  107.     bool operator>(Reprezentacija &r)
  108.     {
  109.         if(uspeh()>r.uspeh())
  110.             return true;
  111.         else return false;
  112.     }
  113.  
  114. };
  115. ostream &operator<<(ostream &out,FudbalskaEkipa &e)
  116. {
  117.     FudbalskaEkipa *tmp=&e;
  118.  
  119.     out<<tmp->getIme()<<"\n"<<tmp->getTrener()<<"\n"<<tmp->uspeh()<<endl;
  120.     return out;
  121. }
  122. void najdobarTrener(FudbalskaEkipa **niza,int n){
  123.     int max=0,maxI;
  124.     for(int i=0;i<n;i++){
  125.         if(niza[i]->uspeh()>max){
  126.             max=niza[i]->uspeh();
  127.             maxI=i;
  128.         }
  129.     }
  130.     cout<<*niza[maxI];
  131. }
  132. int main() {
  133.     int n;
  134.     cin >> n;
  135.     FudbalskaEkipa **ekipi = new FudbalskaEkipa*[n];
  136.     char coach[100];
  137.     int goals[10];
  138.     char x[100];
  139.     int tg;
  140.     for (int i = 0; i < n; ++i) {
  141.         int type;
  142.         cin >> type;
  143.         cin.getline(coach, 100);
  144.         cin.getline(coach, 100);
  145.         for (int j = 0; j < 10; ++j) {
  146.             cin >> goals[j];
  147.         }
  148.         cin.getline(x, 100);
  149.         cin.getline(x, 100);
  150.         cin >> tg;
  151.         if (type == 0) {
  152.             ekipi[i] = new Klub(coach, goals, x, tg);
  153.         } else if (type == 1) {
  154.             ekipi[i] = new Reprezentacija(coach, goals, x, tg);
  155.         }
  156.     }
  157.     cout << "===== SITE EKIPI =====" << endl;
  158.     for (int i = 0; i < n; ++i) {
  159.         cout << *ekipi[i];
  160.     }
  161.     cout << "===== DODADI GOLOVI =====" << endl;
  162.     for (int i = 0; i < n; ++i) {
  163.         int p;
  164.         cin >> p;
  165.         cout << "dodavam golovi: " << p << endl;
  166.         *ekipi[i] += p;
  167.     }
  168.     cout << "===== SITE EKIPI =====" << endl;
  169.     for (int i = 0; i < n; ++i) {
  170.         cout << *ekipi[i];
  171.     }
  172.     cout << "===== NAJDOBAR TRENER =====" << endl;
  173.     najdobarTrener(ekipi, n);
  174.     for (int i = 0; i < n; ++i) {
  175.         delete ekipi[i];
  176.     }
  177.     delete [] ekipi;
  178.     return 0;
  179. }
  180.  
  181.  
  182.  
  183. 10. FINKI-Издавачка куќа
  184.  
  185. #include<iostream>
  186. #include<cstring>
  187. using namespace std;
  188.  
  189. class Book {
  190.     protected:
  191.     char ISBN[20];
  192.     char naslov[50];
  193.     char avtor[30];
  194.     int cena;
  195.    
  196.     public:
  197.     Book (char * i, char * n, char * a, int c) {
  198.         strcpy(ISBN,i); strcpy(naslov,n); strcpy(avtor,a); cena=c;
  199.     }
  200.    
  201.     virtual double bookPrice () = 0;
  202.    
  203.     virtual ~Book () {}
  204.    
  205.     friend ostream &operator << (ostream &out, Book &b) {
  206.         out<<b.ISBN<<": "<<b.naslov<<", "<<b.avtor<<" "<<b.bookPrice()<<endl;
  207.         return out;
  208.     }
  209.    
  210.     bool operator > (const Book &b){
  211.         return cena > b.cena;
  212.     }
  213.    
  214.     void setISBN (const char * i) {strcpy(ISBN,i); }
  215. };
  216.  
  217. class OnlineBook : public Book {
  218.     private:
  219.     char * url;
  220.     int golemina;
  221.    
  222.     public:
  223.     OnlineBook (char * i, char * n, char * a, int c, char *u, int g) : Book(i,n,a,c) {
  224.         url = new char [strlen(u)+1];
  225.         strcpy(url,u); golemina=g;
  226.     }
  227.    
  228.    // ~OnlineBook () {delete [] url; }
  229.    
  230.     double bookPrice () {
  231.         if (golemina>20)
  232.             return 1.2*cena;
  233.         else return cena;
  234.     }    
  235. };
  236.  
  237. class PrintBook : public Book {
  238.     private:
  239.     double masa;
  240.     bool zaliha;
  241.    
  242.     public:
  243.     PrintBook (char * i, char * n, char * a, int c, double m, bool z) : Book (i,n,a,c) {
  244.         masa=m; zaliha=z;
  245.     }
  246.    
  247.     double bookPrice () {
  248.         if (masa>0.7)
  249.             return 1.15*cena;
  250.         else
  251.             return cena;
  252.     }
  253. };
  254.  
  255. void mostExpensiveBook (Book ** books, int n) { //broj na online, broj na pecateni, najskapa kniga
  256.     int online=0, pecateni=0;
  257.     int maxcena=0,maxi;
  258.    
  259.    
  260.    
  261.     for (int i=0;i<n;i++) {
  262.        Book * tmp = dynamic_cast < OnlineBook *>(books[i]);
  263.         if (tmp)
  264.             ++online;
  265.         else ++pecateni;
  266.        
  267.         if (books[i]->bookPrice() > maxcena){
  268.             maxi=i;
  269.             maxcena=books[i]->bookPrice();
  270.         }
  271.     }
  272.     cout<<"FINKI-Education"<<endl;
  273.     cout<<"Total number of online books: "<<online<<endl;
  274.     cout<<"Total number of print books: "<<pecateni<<endl;
  275.     cout<<"The most expensive book is: "<<endl;
  276.     cout<<*books[maxi];
  277.    
  278. }
  279. int main(){
  280.  
  281.     char isbn[20], title[50], author[30], url[100];
  282.     int size, tip;
  283.     float price, weight;
  284.     bool inStock;
  285.     Book  **books;
  286.     int n;
  287.  
  288.     int testCase;
  289.     cin >> testCase;
  290.  
  291.     if (testCase == 1){
  292.         cout << "====== Testing OnlineBook class ======" << endl;
  293.         cin >> n;
  294.         books = new Book *[n];
  295.  
  296.         for (int i = 0; i < n; i++){
  297.             cin >> isbn;
  298.             cin.get();
  299.             cin.getline(title, 50);
  300.             cin.getline(author, 30);
  301.             cin >> price;
  302.             cin >> url;
  303.             cin >> size;
  304.             cout << "CONSTRUCTOR" << endl;
  305.             books[i] = new OnlineBook(isbn, title, author, price, url, size);
  306.             cout << "OPERATOR <<" << endl;
  307.             cout << *books[i];
  308.         }
  309.         cout << "OPERATOR >" << endl;
  310.         cout << "Rezultat od sporedbata e: " << endl;
  311.         if (*books[0] > *books[1])
  312.             cout << *books[0];
  313.         else
  314.             cout << *books[1];
  315.     }
  316.     if (testCase == 2){
  317.         cout << "====== Testing OnlineBook CONSTRUCTORS ======" << endl;
  318.         cin >> isbn;
  319.         cin.get();
  320.         cin.getline(title, 50);
  321.         cin.getline(author, 30);
  322.         cin >> price;
  323.         cin >> url;
  324.         cin >> size;
  325.         cout << "CONSTRUCTOR" << endl;
  326.         OnlineBook ob1(isbn, title, author, price, url, size);
  327.         cout << ob1 << endl;
  328.         cout << "COPY CONSTRUCTOR" << endl;
  329.         OnlineBook ob2(ob1);
  330.         cin >> isbn;
  331.         ob2.setISBN(isbn);
  332.         cout << ob1 << endl;
  333.         cout << ob2 << endl;
  334.         cout << "OPERATOR =" << endl;
  335.         ob1 = ob2;
  336.         cin >> isbn;
  337.         ob2.setISBN(isbn);
  338.         cout << ob1 << endl;
  339.         cout << ob2 << endl;
  340.     }
  341.     if (testCase == 3){
  342.         cout << "====== Testing PrintBook class ======" << endl;
  343.         cin >> n;
  344.         books = new Book *[n];
  345.  
  346.         for (int i = 0; i < n; i++){
  347.             cin >> isbn;
  348.             cin.get();
  349.             cin.getline(title, 50);
  350.             cin.getline(author, 30);
  351.             cin >> price;
  352.             cin >> weight;
  353.             cin >> inStock;
  354.             cout << "CONSTRUCTOR" << endl;
  355.             books[i] = new PrintBook(isbn, title, author, price, weight, inStock);
  356.             cout << "OPERATOR <<" << endl;
  357.             cout << *books[i];
  358.         }
  359.         cout << "OPERATOR >" << endl;
  360.         cout << "Rezultat od sporedbata e: " << endl;
  361.         if (*books[0] > *books[1])
  362.             cout << *books[0];
  363.         else
  364.             cout << *books[1];
  365.     }
  366.     if (testCase == 4){
  367.         cout << "====== Testing method mostExpensiveBook() ======" << endl;
  368.         cin >> n;
  369.         books = new Book *[n];
  370.  
  371.         for (int i = 0; i<n; i++){
  372.  
  373.             cin >> tip >> isbn;
  374.             cin.get();
  375.             cin.getline(title, 50);
  376.             cin.getline(author, 30);
  377.             cin >> price;
  378.             if (tip == 1) {
  379.  
  380.                 cin >> url;
  381.                 cin >> size;
  382.  
  383.                 books[i] = new OnlineBook(isbn, title, author, price, url, size);
  384.  
  385.             }
  386.             else {
  387.                 cin >> weight;
  388.                 cin >> inStock;
  389.  
  390.                 books[i] = new PrintBook(isbn, title, author, price, weight, inStock);
  391.             }
  392.         }
  393.  
  394.         mostExpensiveBook(books, n);
  395.     }
  396.  
  397.     for (int i = 0; i<n; i++) delete books[i];
  398.         delete[] books;
  399.     return 0;
  400. }
  401.  
  402.  
  403.  
  404. 12. Научни трудови
  405.  
  406. #include <iostream>
  407. #include <cstring>
  408. using namespace std;
  409.  
  410. class Exception {
  411. public:
  412.     void print() {
  413.         cout<<"Ne moze da se vnese dadeniot trud"<<endl;
  414.     }
  415. };
  416.  
  417.  
  418. class Trud {
  419. private:
  420.     char vid;
  421.     int godina;
  422.     static int J;
  423.     static int C;
  424. public:
  425.     Trud() {
  426.     }
  427.     Trud(char vid, int godina) {
  428.         this->vid = vid;
  429.         this->godina = godina;
  430.     }
  431.     Trud(const Trud &t) {
  432.         this->vid = t.vid;
  433.         this->godina = t.godina;
  434.     }
  435.  
  436.     ~Trud() {
  437.     }
  438.  
  439.     void setVid(char vid) {
  440.         this->vid = vid;
  441.     }
  442.     void setGodina(int godina) {
  443.         this->godina = godina;
  444.     }
  445.     char getVid() {
  446.         return vid;
  447.     }
  448.     int getGodina() {
  449.         return godina;
  450.     }
  451.     static void setJ(int j) {
  452.         J = j;
  453.     }
  454.     static void setC(int c) {
  455.         C = c;
  456.     }
  457.     int getC() {
  458.         return C;
  459.     }
  460.     int getJ() {
  461.         return J;
  462.     }
  463.  
  464.     friend istream &operator>>(istream &in, Trud &t) {
  465.         in>>t.vid;
  466.         in>>t.godina;
  467.         return in;
  468.     }
  469. };
  470. int Trud::C = 1;
  471. int Trud::J = 3;
  472.  
  473. class Student {
  474. protected:
  475.     char ime[30];
  476.     int index;
  477.     int godinaUpis;
  478.     int *oceni;
  479.     int brojOceni;
  480. public:
  481.     Student(char *ime="", int index =0, int godinaUpis=0, int *oceni=NULL, int brojOceni=0) {
  482.         strcpy(this->ime, ime);
  483.         this->index = index;
  484.         this->godinaUpis = godinaUpis;
  485.         this->oceni = new int[brojOceni];
  486.         for(int i=0; i<brojOceni; i++) {
  487.             this->oceni[i] = oceni[i];
  488.         }
  489.         this->brojOceni = brojOceni;
  490.     }
  491.     ~Student() {
  492.         delete []oceni;
  493.     }
  494.  
  495.     virtual float rang() {
  496.         int suma=0;
  497.         for(int i=0; i<brojOceni; i++) {
  498.             suma = suma + oceni[i];
  499.         }
  500.         return (float)suma/brojOceni;
  501.     }
  502.  
  503.     friend ostream &operator<<(ostream &out, Student &s) {
  504.         out<<s.index<<" "<<s.ime<<" "<<s.godinaUpis<<" "<<s.rang()<<endl;
  505.         return out;
  506.     }
  507.     int getGodinaUpis() {
  508.         return godinaUpis;
  509.     }
  510.  
  511.     int getIndeks() {
  512.         return index;
  513.     }
  514. };
  515.  
  516. class PhDStudent : public Student {
  517. private:
  518.     Trud *trudovi;
  519.     int brojTrudovi;
  520. public:
  521.     PhDStudent(char *ime="", int index =0, int godinaUpis=0, int *oceni=NULL, int brojOceni=0, Trud *trudovi=NULL, int brojTrudovi=0)
  522.         :Student(ime, index, godinaUpis, oceni, brojOceni) {
  523.         this->trudovi = new Trud[brojTrudovi];
  524.         int j=0;
  525.         for(int i=0; i<brojTrudovi; i++) {
  526.             try{
  527.             if(this->getGodinaUpis() > trudovi[i].getGodina())
  528.             throw Exception();
  529.               this->trudovi[j] = trudovi[i];
  530.               j++;
  531.     }
  532.             catch (Exception e) { e.print();}  
  533.            
  534.            
  535.         }
  536.         this->brojTrudovi = j;
  537.     }
  538.  
  539.     PhDStudent(const PhDStudent &p):Student(p) {
  540.         this->trudovi = new Trud[p.brojTrudovi];
  541.         for(int i=0; i<brojTrudovi; i++) {
  542.             this->trudovi[i] = p.trudovi[i];
  543.         }
  544.         this->brojTrudovi = p.brojTrudovi;
  545.     }
  546.  
  547.     PhDStudent &operator=(const PhDStudent &p) {
  548.         if(this != &p) {
  549.             delete []trudovi;
  550.             this->trudovi = new Trud[p.brojTrudovi];
  551.             for(int i=0; i<brojTrudovi; i++) {
  552.                 this->trudovi[i] = p.trudovi[i];
  553.             }
  554.             this->brojTrudovi = p.brojTrudovi;
  555.         }
  556.         return *this;
  557.     }
  558.  
  559.     ~PhDStudent() {
  560.         delete []trudovi;
  561.     }
  562.  
  563.     float rang() {
  564.         float r = Student::rang();
  565.  
  566.         for(int i=0; i<brojTrudovi; i++) {
  567.             if(trudovi[i].getVid()=='J' || trudovi[i].getVid()=='j')
  568.                 r += trudovi[i].getJ();
  569.             else if(trudovi[i].getVid()=='C' || trudovi[i].getVid()=='c')
  570.                 r += trudovi[i].getC();
  571.         }
  572.         return r;
  573.     }
  574.  
  575.     void operator+=(Trud &t) {
  576.         if(getGodinaUpis() > t.getGodina())
  577.             throw Exception();
  578.         this->trudovi[brojTrudovi] = t;
  579.         this->brojTrudovi++;
  580.     }
  581.  
  582. };
  583.  
  584. int main() {
  585.     int testCase;
  586.     cin >> testCase;
  587.  
  588.     int god, indeks, n, god_tr, m, n_tr;
  589.     int izbor; //0 za Student, 1 za PhDStudent
  590.     char ime[30];
  591.     int oceni[50];
  592.     char tip;
  593.     Trud trud[50];
  594.  
  595.     if (testCase == 1) {
  596.         cout << "===== Testiranje na klasite ======" << endl;
  597.         cin >> ime;
  598.         cin >> indeks;
  599.         cin >> god;
  600.         cin >> n;
  601.         for (int j = 0; j < n; j++)
  602.             cin >> oceni[j];
  603.         Student s(ime, indeks, god, oceni, n);
  604.         cout << s;
  605.  
  606.         cin >> ime;
  607.         cin >> indeks;
  608.         cin >> god;
  609.         cin >> n;
  610.         for (int j = 0; j < n; j++)
  611.             cin >> oceni[j];
  612.         cin >> n_tr;
  613.         for (int j = 0; j < n_tr; j++) {
  614.             cin >> tip;
  615.             cin >> god_tr;
  616.             Trud t(tip, god_tr);
  617.             trud[j] = t;
  618.         }
  619.         PhDStudent phd(ime, indeks, god, oceni, n, trud, n_tr);
  620.         cout << phd;
  621.     }
  622.     if (testCase == 2) {
  623.         cout << "===== Testiranje na operatorot += ======" << endl;
  624.         Student **niza;
  625.         cin >> m;
  626.         niza = new Student *[m];
  627.         for (int i = 0; i<m; i++) {
  628.             cin >> izbor;
  629.             cin >> ime;
  630.             cin >> indeks;
  631.             cin >> god;
  632.             cin >> n;
  633.             for (int j = 0; j < n; j++)
  634.                 cin >> oceni[j];
  635.  
  636.             if (izbor == 0) {
  637.                 niza[i] = new Student(ime, indeks, god, oceni, n);
  638.             } else {
  639.                 cin >> n_tr;
  640.                 for (int j = 0; j < n_tr; j++) {
  641.                     cin >> tip;
  642.                     cin >> god_tr;
  643.                     Trud t(tip, god_tr);
  644.                     trud[j] = t;
  645.                 }
  646.                 niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
  647.             }
  648.         }
  649.         // pecatenje na site studenti
  650.         cout << "\nLista na site studenti:\n";
  651.         for (int i = 0; i < m; i++)
  652.             cout << *niza[i];
  653.  
  654.         // dodavanje nov trud za PhD student spored indeks
  655.         Trud t;
  656.         cin >> indeks;
  657.         cin >> t;
  658.         int flag = 1;
  659.         for (int i = 0; i < m; i++) {
  660.             if ((*niza[i]).getIndeks() == indeks) {
  661.                 PhDStudent* nov = dynamic_cast<PhDStudent*>(niza[i]);
  662.                 if (nov != 0) {
  663.                     (*nov) += t;
  664.                     flag = 0;
  665.                     break;
  666.                 }
  667.             }
  668.         }
  669.         if (flag)
  670.             cout << "Ne postoi PhD student so indeks " << indeks << endl;
  671.  
  672.  
  673.         // pecatenje na site studenti
  674.         cout << "\nLista na site studenti:\n";
  675.         for (int i = 0; i < m; i++)
  676.             cout << *niza[i];
  677.     }
  678.     if (testCase == 3) {
  679.         cout << "===== Testiranje na operatorot += ======" << endl;
  680.         Student **niza;
  681.         cin >> m;
  682.         niza = new Student *[m];
  683.         for (int i = 0; i<m; i++) {
  684.             cin >> izbor;
  685.             cin >> ime;
  686.             cin >> indeks;
  687.             cin >> god;
  688.             cin >> n;
  689.             for (int j = 0; j < n; j++)
  690.                 cin >> oceni[j];
  691.  
  692.             if (izbor == 0) {
  693.                 niza[i] = new Student(ime, indeks, god, oceni, n);
  694.             } else {
  695.                 cin >> n_tr;
  696.                 for (int j = 0; j < n_tr; j++) {
  697.                     cin >> tip;
  698.                     cin >> god_tr;
  699.                     Trud t(tip, god_tr);
  700.                     trud[j] = t;
  701.                 }
  702.                 niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
  703.             }
  704.         }
  705.         // pecatenje na site studenti
  706.         cout << "\nLista na site studenti:\n";
  707.         for (int i = 0; i < m; i++)
  708.             cout << *niza[i];
  709.  
  710.         // dodavanje nov trud za PhD student spored indeks
  711.         Trud t;
  712.         cin >> indeks;
  713.         cin >> t;
  714.         int flag = 1;
  715.         for (int i = 0; i < m; i++) {
  716.             if ((*niza[i]).getIndeks() == indeks) {
  717.                 PhDStudent* nov = dynamic_cast<PhDStudent*>(niza[i]);
  718.                 if (nov != 0) {
  719.                     (*nov) += t;
  720.                     flag = 0;
  721.                     break;
  722.                 }
  723.             }
  724.         }
  725.         if (flag)
  726.             cout << "Ne postoi PhD student so indeks " << indeks << endl;
  727.  
  728.  
  729.         // pecatenje na site studenti
  730.         cout << "\nLista na site studenti:\n";
  731.         for (int i = 0; i < m; i++)
  732.             cout << *niza[i];
  733.     }
  734.     if (testCase == 4) {
  735.         cout << "===== Testiranje na isklucoci ======" << endl;
  736.         cin >> ime;
  737.         cin >> indeks;
  738.         cin >> god;
  739.         cin >> n;
  740.         for (int j = 0; j < n; j++)
  741.             cin >> oceni[j];
  742.         cin >> n_tr;
  743.         for (int j = 0; j < n_tr; j++) {
  744.             cin >> tip;
  745.             cin >> god_tr;
  746.             Trud t(tip, god_tr);
  747.             trud[j] = t;
  748.         }
  749.         PhDStudent phd(ime, indeks, god, oceni, n, trud, n_tr);
  750.         //cout<<"Ne moze da se vnese dadeniot trud"<<endl;
  751.         cout << phd;
  752.     }
  753.     if (testCase == 5) {
  754.         cout << "===== Testiranje na isklucoci ======" << endl;
  755.         Student **niza;
  756.         cin >> m;
  757.         niza = new Student *[m];
  758.         for (int i = 0; i<m; i++) {
  759.             cin >> izbor;
  760.             cin >> ime;
  761.             cin >> indeks;
  762.             cin >> god;
  763.             cin >> n;
  764.             for (int j = 0; j < n; j++)
  765.                 cin >> oceni[j];
  766.  
  767.             if (izbor == 0) {
  768.                 niza[i] = new Student(ime, indeks, god, oceni, n);
  769.             } else {
  770.                 cin >> n_tr;
  771.                 for (int j = 0; j < n_tr; j++) {
  772.                     cin >> tip;
  773.                     cin >> god_tr;
  774.                     Trud t(tip, god_tr);
  775.                     trud[j] = t;
  776.                 }
  777.                 niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
  778.             }
  779.         }
  780.         // pecatenje na site studenti
  781.         cout << "\nLista na site studenti:\n";
  782.         for (int i = 0; i < m; i++)
  783.             cout << *niza[i];
  784.  
  785.         // dodavanje nov trud za PhD student spored indeks
  786.         Trud t;
  787.         cin >> indeks;
  788.         cin >> t;
  789.         int flag = 1;
  790.         for (int i = 0; i < m; i++) {
  791.             if ((*niza[i]).getIndeks() == indeks) {
  792.                 PhDStudent* nov = dynamic_cast<PhDStudent*>(niza[i]);
  793.                 if (nov != 0) {
  794.                     try {
  795.                         flag = 0;
  796.                         (*nov) += t;
  797.                         break;
  798.                     } catch (Exception e) {
  799.                         e.print();
  800.                     }
  801.                 }
  802.             }
  803.         }
  804.         if (flag)
  805.             cout << "Ne postoi PhD student so indeks " << indeks << endl;
  806.  
  807.  
  808.         // pecatenje na site studenti
  809.         cout << "\nLista na site studenti:\n";
  810.         for (int i = 0; i < m; i++)
  811.             cout << *niza[i];
  812.     }
  813.     if (testCase == 6) {
  814.         cout << "===== Testiranje na static clenovi ======" << endl;
  815.         Student **niza;
  816.         cin >> m;
  817.         niza = new Student *[m];
  818.         for (int i = 0; i<m; i++) {
  819.             cin >> izbor;
  820.             cin >> ime;
  821.             cin >> indeks;
  822.             cin >> god;
  823.             cin >> n;
  824.             for (int j = 0; j < n; j++)
  825.                 cin >> oceni[j];
  826.  
  827.             if (izbor == 0) {
  828.                 niza[i] = new Student(ime, indeks, god, oceni, n);
  829.             } else {
  830.                 cin >> n_tr;
  831.                 for (int j = 0; j < n_tr; j++) {
  832.                     cin >> tip;
  833.                     cin >> god_tr;
  834.                     Trud t(tip, god_tr);
  835.                     trud[j] = t;
  836.                 }
  837.                 niza[i] = new PhDStudent(ime, indeks, god, oceni, n, trud, n_tr);
  838.             }
  839.         }
  840.         // pecatenje na site studenti
  841.         cout << "\nLista na site studenti:\n";
  842.         for (int i = 0; i < m; i++)
  843.             cout << *niza[i];
  844.  
  845.         int conf, journal;
  846.         cin >> conf;
  847.         cin >> journal;
  848.         Trud::setC(conf);
  849.         Trud::setJ(journal);
  850.  
  851.         // pecatenje na site studenti
  852.         cout << "\nLista na site studenti:\n";
  853.         for (int i = 0; i < m; i++)
  854.             cout << *niza[i];
  855.     }
  856.  
  857.     return 0;
  858. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement