Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Vozac{
- protected:
- char ime[100];
- int vozrast;
- int brTrki;
- bool veteran;
- public:
- Vozac(){}
- Vozac(char *i,int v,int b,bool ve){
- strcpy(ime,i);
- vozrast = v;
- brTrki = b;
- veteran = ve;
- }
- friend ostream& operator<< (ostream &out, const Vozac &v)
- {
- if(v.veteran)
- {
- return out<<v.ime<<endl<<v.vozrast<<endl<<v.brTrki<<endl<<"VETERAN"<<endl;
- }
- return out<<v.ime<<endl<<v.vozrast<<endl<<v.brTrki<<endl;
- }
- bool operator==(Vozac &v)
- {
- return this->zarabotuvacka()==v.zarabotuvacka();
- }
- virtual float zarabotuvacka(){}
- virtual float danok(){}
- };
- class Avtomobilist : public Vozac{
- protected:
- float cenaAvtomobil;
- public:
- Avtomobilist(){}
- Avtomobilist(char *i,int v,int b,bool ve,float c):Vozac(i,v,b,ve)
- {
- cenaAvtomobil = c;
- }
- float zarabotuvacka()
- {
- return cenaAvtomobil/5;
- }
- float danok()
- {
- if(brTrki>10)
- return zarabotuvacka()*0.15;
- return zarabotuvacka()*0.1;
- }
- };
- class Motociklist : public Vozac{
- protected:
- int mokjnostNaMotor;
- public:
- Motociklist(){}
- Motociklist(char *i,int v,int b,int ve,int m):Vozac(i,v,b,ve){
- mokjnostNaMotor = m;
- }
- float zarabotuvacka()
- {
- return mokjnostNaMotor * 20;
- }
- float danok()
- {
- if(veteran)
- return zarabotuvacka() * 0.25;
- return zarabotuvacka() * 0.2;
- }
- };
- int soIstaZarabotuvachka(Vozac **v,int n,Vozac *vozac)
- {
- int result = 0;
- for(int i=0;i<n;i++)
- {
- if(*vozac==*v[i])
- result ++;
- }
- return result;
- }
- // vashiot kod ovde
- int main() {
- int n, x;
- cin >> n >> x;
- Vozac **v = new Vozac*[n];
- char ime[100];
- int vozrast;
- int trki;
- bool vet;
- for(int i = 0; i < n; ++i) {
- cin >> ime >> vozrast >> trki >> vet;
- if(i < x) {
- float cena_avto;
- cin >> cena_avto;
- v[i] = new Avtomobilist(ime, vozrast, trki, vet, cena_avto);
- } else {
- int mokjnost;
- cin >> mokjnost;
- v[i] = new Motociklist(ime, vozrast, trki, vet, mokjnost);
- }
- }
- cout << "=== DANOK ===" << endl;
- for(int i = 0; i < n; ++i) {
- cout << *v[i];
- cout << v[i]->danok() << endl;
- }
- cin >> ime >> vozrast >> trki >> vet;
- int mokjnost;
- cin >> mokjnost;
- Vozac *vx = new Motociklist(ime, vozrast, trki, vet, mokjnost);
- cout << "=== VOZAC X ===" << endl;
- cout << *vx;
- cout << "=== SO ISTA ZARABOTUVACKA KAKO VOZAC X ===" << endl;
- cout << soIstaZarabotuvachka(v, n, vx);
- for(int i = 0; i < n; ++i) {
- delete v[i];
- }
- delete [] v;
- delete vx;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement