#include<bits/stdc++.h>
using namespace std;
class Car{
protected:
int id;
string name;
int zujin;
public:
Car(){}
~Car(){}
Car(int id_, string name_, int zujin_){
this->id = id_;
this->name = name_;
this->zujin = zujin_;
}
};
class Keche: public Car{
protected:
int zaikeliang;
public:
Keche(){}
~Keche(){}
Keche(int id_, string name_, int zujin_, int zaikeliang_){
this->id = id_;
this->name = name_;
this->zujin = zujin_;
this->zaikeliang = zaikeliang_;
}
int getId(){
return this->id;
}
string getName(){
return this->name;
}
int getZujin(){
return this->zujin;
}
int getZaikeliang(){
return this->zaikeliang;
}
};
class Huoche: public Car{
protected:
double zaihuoliang;
public:
Huoche(){}
~Huoche(){}
Huoche(int id_, string name_, int zujin_, double zaihuoliang_){
this->id = id_;
this->name = name_;
this->zujin = zujin_;
this->zaihuoliang = zaihuoliang_;
}
int getId(){
return this->id;
}
string getName(){
return this->name;
}
int getZujin(){
return this->zujin;
}
double getZaihuoliang(){
return this->zaihuoliang;
}
};
class Pikache:public Keche, public Huoche{
public:
Pikache(){}
~Pikache(){}
Pikache(int id_, string name_, int zujin_, int zaikeliang_, double zaihuoliang_){
Keche::id = id_;
Keche::name = name_;
Keche::zujin = zujin_;
this->zaikeliang = zaikeliang_;
this->zaihuoliang = zaihuoliang_;
}
int getId(){
return Keche::id;
}
string getName(){
return Keche::name;
}
int getZujin(){
return Keche::zujin;
}
int getZaikeliang(){
return this->zaikeliang;
}
double getZaihuoliang(){
return this->zaihuoliang;
}
};
int main()
{
Keche keche1(1,"A",800,5);
Keche keche2(2,"B",400,5);
Keche keche3(3,"C",800,5);
Keche keche4(4,"D",1300,51);
Keche keche5(5,"E",1500,55);
Pikache pikache6(6,"F",500,5,0.45);
Pikache pikache7(7,"G",450,5,2.0);
Huoche huoche8(8,"H",200,3);
Huoche huoche9(9,"I",1500,25);
Huoche huoche10(10,"J",2000,35);
int checknum;
cin >> checknum;
if(checknum)
{
int N;
cin >> N;
int sum_zaikeliang = 0;
double sum_zaihuoliang = 0;
int sum_zujin = 0;
while(N--)
{
int m,n;
cin >> m >> n;
switch(m)
{
case 1:
sum_zaikeliang += keche1.getZaikeliang() * n;
sum_zujin += keche1.getZujin() * n;
break;
case 2:
sum_zaikeliang += keche2.getZaikeliang() * n;
sum_zujin += keche2.getZujin() * n;
break;
case 3:
sum_zaikeliang += keche3.getZaikeliang() * n;
sum_zujin += keche3.getZujin() * n;
break;
case 4:
sum_zaikeliang += keche4.getZaikeliang() * n;
sum_zujin += keche4.getZujin() * n;
break;
case 5:
sum_zaikeliang += keche5.getZaikeliang() * n;
sum_zujin += keche5.getZujin() * n;
break;
case 6:
sum_zaikeliang += pikache6.getZaikeliang() * n;
sum_zaihuoliang += pikache6.getZaihuoliang() * n;
sum_zujin += pikache6.getZujin() * n;
break;
case 7:
sum_zaikeliang += pikache7.getZaikeliang() * n;
sum_zaihuoliang += pikache7.getZaihuoliang() * n;
sum_zujin += pikache7.getZujin() * n;
break;
case 8:
sum_zaihuoliang += huoche8.getZaihuoliang() * n;
sum_zujin += huoche8.getZujin() * n;
break;
case 9:
sum_zaihuoliang += huoche9.getZaihuoliang() * n;
sum_zujin += huoche9.getZujin() * n;
break;
default:
sum_zaihuoliang += huoche10.getZaihuoliang() * n;
sum_zujin += huoche10.getZujin() * n;
break;
}
}
printf("%d %.2lf %d\n",sum_zaikeliang, sum_zaihuoliang, sum_zujin);
}
else
{
cout << "0 " << "0.00 " << "0" << endl;
}
return 0;
}
【id:297】【10分】J. OOP租车系统(多重继承)
最新推荐文章于 2024-10-20 18:34:06 发布