SHARE
TWEET

Vozac

a guest May 21st, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. #include<string.h>
  3. #include <cmath>
  4. using namespace std;
  5.  
  6. class Vozac{
  7. protected:
  8.     char ime[100];
  9.     int vozrast;
  10.     int trki;
  11.     bool veteran;
  12.  
  13.  
  14. public:
  15.     Vozac(){
  16.      strcpy(ime,"");
  17.      vozrast=0;
  18.      trki=0;
  19.      veteran=false;
  20.     }
  21.     Vozac(char *ime1,int vozrast1,int trki1, bool veteran1){
  22.      strcpy(ime,ime1);
  23.      vozrast=vozrast1;
  24.      trki=trki1;
  25.      veteran=veteran1;
  26.     }
  27.     ~Vozac(){}
  28.     friend ostream& operator<<(ostream &out,Vozac &v){
  29.      out<<v.ime<<endl<<v.vozrast<<endl<<v.trki<<endl;
  30.      if(v.veteran){
  31.         cout<<"VETERAN"<<endl;;
  32.      }
  33.    
  34.      return out;
  35.     }
  36.     bool operator ==(Vozac &v){
  37.      if(zarabotuvacka()==v.zarabotuvacka()){
  38.         return true;
  39.      }else{
  40.      return false;
  41.      }
  42.     }
  43.    virtual float zarabotuvacka()=0;
  44.       virtual float danok()=0;
  45. };
  46.  
  47. class Avtomobilist:public Vozac{
  48. private:
  49.     float cenaAvtomobil;
  50. public:
  51.     Avtomobilist(){
  52.     cenaAvtomobil=0;
  53.     }
  54.     Avtomobilist(char *ime1,int vozrast1,int trki1, bool veteran1,float cenaAvtomobil1)
  55.     :Vozac(ime1,vozrast1,trki1,veteran1){
  56.     cenaAvtomobil=cenaAvtomobil1;
  57.     }
  58. float zarabotuvacka(){
  59.      return cenaAvtomobil/5;
  60.     }
  61.     float danok(){
  62.     if(trki>10){
  63.         return zarabotuvacka()*0.15;
  64.     }else{
  65.         return zarabotuvacka()*0.10;
  66.     }
  67.     }
  68.  
  69. };
  70.  
  71.  
  72. class Motociklist:public Vozac{
  73. private:
  74.     int mokjnost;
  75. public:
  76.     Motociklist(){
  77.     mokjnost=0;
  78.     }
  79.     Motociklist(char *ime1,int vozrast1,int trki1, bool veteran1,int mokjnost1)
  80.     :Vozac(ime1,vozrast1,trki1,veteran1){
  81.     mokjnost=mokjnost1;
  82.     }
  83.     float zarabotuvacka(){
  84.      return mokjnost*20;
  85.     }
  86.       float danok(){
  87.     if(veteran){
  88.         return zarabotuvacka()*0.25;
  89.     }else{
  90.         return zarabotuvacka()*0.20;
  91.     }
  92.     }
  93.  
  94. };
  95.  
  96. int soIstaZarabotuvachka(Vozac **vozaci,int n, Vozac *vozac){
  97. int brojac=0;
  98. for(int i=0;i<n;i++){
  99.     if(*(vozaci[i])==*(vozac)){ //se sporeduvaat kako objekti so *
  100.             brojac++;
  101.     }
  102. }
  103. return brojac;
  104.  
  105. }
  106. int main() {
  107.     int n, x;
  108.     cin >> n >> x;
  109.     Vozac **v = new Vozac*[n];
  110.     char ime[100];
  111.     int vozrast;
  112.     int trki;
  113.     bool vet;
  114.     for(int i = 0; i < n; ++i) {
  115.         cin >> ime >> vozrast >> trki >> vet;
  116.         if(i < x) {
  117.             float cena_avto;
  118.             cin >> cena_avto;
  119.             v[i] = new Avtomobilist(ime, vozrast, trki, vet, cena_avto);
  120.         } else {
  121.             int mokjnost;
  122.             cin >> mokjnost;
  123.             v[i] = new Motociklist(ime, vozrast, trki, vet, mokjnost);
  124.         }
  125.     }
  126.     cout << "=== DANOK ===" << endl;
  127.     for(int i = 0; i < n; ++i) {
  128.         cout << *v[i];
  129.         cout << v[i]->danok() << endl;
  130.     }
  131.     cin >> ime >> vozrast >> trki >> vet;
  132.     int mokjnost;
  133.     cin >> mokjnost;
  134.     Vozac *vx = new Motociklist(ime, vozrast, trki, vet, mokjnost);
  135.     cout << "=== VOZAC X ===" << endl;
  136.     cout << *vx;
  137.     cout << "=== SO ISTA ZARABOTUVACKA KAKO VOZAC X ===" << endl;
  138.     cout << soIstaZarabotuvachka(v, n, vx);
  139.     for(int i = 0; i < n; ++i) {
  140.         delete v[i];
  141.     }
  142.     delete [] v;
  143.     delete vx;
  144.     return 0;
  145. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top