Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Vehicle
- {
- protected:
- float mass;
- int width;
- int height;
- public:
- Vehicle(float mass=0.0 , int width = 0 , int height = 0 )
- {
- this->mass=mass;
- this->width=width;
- this->height=height;
- }
- Vehicle(const Vehicle &v)
- {
- this->mass=v.mass;
- this->width=v.width;
- this->height=v.height;
- }
- float getMass(){return this->mass;}
- int getWidth(){return this->width;}
- int getHeight(){return this->height;}
- virtual int dailyPrice()=0;
- };
- class Automobile : public Vehicle
- {
- private:
- int n ;
- public:
- Automobile(float mass=0.0 , int width = 0 , int height = 0 , int n = 0 ) : Vehicle(mass,width, height)
- {
- this-> n = n ;
- }
- Automobile (const Automobile &a) : Vehicle(a)
- {
- this->n=a.n;
- }
- int dailyPrice()
- {
- if(n<5){return 100;}
- else return 130;
- }
- };
- class Bus : public Vehicle
- {
- private:
- int n ;
- public:
- Bus(float mass=0.0 , int width = 0 , int height = 0 , int n = 0 ) : Vehicle(mass,width, height)
- {
- this-> n = n ;
- }
- Bus (const Bus &b) : Vehicle(b)
- {
- this->n=b.n;
- }
- int dailyPrice()
- {
- return n*5;
- }
- };
- class Truck :public Vehicle
- {
- private:
- float max;
- public:
- Truck(float mass=0 , int width = 0 , int height = 0 , float max= 0 ) : Vehicle(mass,width, height)
- {
- this-> max= max ;
- }
- Truck (const Truck &t) : Vehicle(t)
- {
- this->max=t.max;
- }
- int dailyPrice()
- {
- return (mass + max) * 0.02;
- }
- };
- class Parking
- {
- protected:
- Vehicle **vehicle;
- int n ;
- public:
- Parking (){
- vehicle= new Vehicle*[100];
- n=0;
- }
- Parking(Vehicle ** vehicle , int n)
- {
- this->n=n;
- this->vehicle=new Vehicle*[n];
- for(int i = 0 ; i < n ; i ++)
- {
- vehicle[i]=vehicle[i];
- }
- }
- Parking operator+=(Vehicle *v)
- {
- vehicle[n]=v;
- n++;
- return *this;
- }
- float totallMass()
- {
- float sum=0.0;
- for(int i = 0 ; i < n ; i++)
- {
- sum+=vehicle[i]->getMass();
- }
- return sum;
- }
- int vehiclesWiderThan(int width)
- {
- int count=0;
- for(int i = 0 ; i < n ; i ++)
- {
- if(vehicle[i]->getWidth()>width)
- {
- count++;
- }
- }
- return count;
- }
- void print()
- {
- int count = 0, count1=0, count2=0;
- for(int i = 0 ; i< n ; i ++)
- {
- Automobile *a=dynamic_cast<Automobile*>(vehicle[i]);
- {
- if (a!=0){count++;}
- }
- Bus *b=dynamic_cast<Bus*>(vehicle[i]);
- {
- if(b!=0){count1++;}
- }
- Truck *t=dynamic_cast<Truck*>(vehicle[i]);
- {
- if(t!=0){count2++;}
- }
- }
- cout<<"Automobiles: "<<count<<endl<<"Busses: "<<count1<<endl<<"Trucks: "<<count2<<endl;
- }
- int greaterMaxWeightThan(Vehicle &v)
- {
- int count=0;
- for(int i = 0 ; i < n ; i++)
- {
- Truck *t=dynamic_cast<Truck*>(vehicle[i]);
- if(t!=0)
- {
- if(v.getMass()<vehicle[i]->getMass())
- {
- count++;
- }
- }
- }
- return count;
- }
- int dailyProfit()
- {
- int profit = 0 ;
- for(int i = 0; i < n ; i ++)
- {
- profit+=vehicle[i]->dailyPrice();
- }
- return profit;
- }
- ~Parking()
- {
- /*for(int i = 0 ; i < n ; i ++)
- {
- delete vehicle[i];
- }
- delete []vehicle;
- */
- }
- };
- int main() {
- Parking p;
- int n;
- cin >> n;
- int width, height, broj;
- float mass, max_weight;
- for (int i = 0; i < n; i++) {
- int type;
- cin >> type;
- if (type == 1) {
- cin >> mass >> width >> height >> broj;
- Automobile *a = new Automobile(mass, width, height, broj);
- p += a;
- }
- if (type == 2) {
- cin >> mass >> width >> height >> broj;
- p += new Bus(mass, width, height, broj);
- }
- if (type == 3) {
- cin >> mass >> width >> height >> max_weight;
- p += new Truck(mass, width, height, max_weight);
- }
- }
- p.print();
- cout << "\nDaily profit: " << p.dailyProfit() << endl;
- cout << "Total mass: " << p.totallMass() << endl;
- cout << "Number wider then 5 is: " << p.vehiclesWiderThan(5) << endl;
- Automobile a(1200, 4, 3, 5);
- cout << "Number of trucks with max weight larger then the automobile is: " << p.greaterMaxWeightThan(a) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement