Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- class SportsCar;
- class Car
- {
- private:
- double speed;
- double weight;
- public:
- Car() {
- cout << "Enter car speed - "; cin >> speed;
- cout << "Enter car weight - "; cin >> weight;
- }
- double getWeight() { return weight; }
- int compare(const SportsCar& obj);
- };
- class SportsCar
- {
- private:
- double speed;
- double weight;
- string color;
- public:
- SportsCar() {
- cout << "Enter sports car speed - "; cin >> speed;
- cout << "Enter sports car weight - "; cin >> weight;
- cout << "Enter sports car color - "; cin >> color;
- }
- double getWeight() { return weight; }
- string getColor() { return color; }
- friend int Car :: compare(const SportsCar& obj);
- };
- int Car::compare(const SportsCar& obj) {
- if (this->speed > obj.speed)return 1;
- else if (this->speed < obj.speed)return 2;
- else return 0;
- }
- int main()
- {
- Car A;
- SportsCar B;
- if (A.compare(B) == 1)
- cout << "Car weight - " << A.getWeight() << endl;
- else if (A.compare(B) == 2)
- cout << "Sports car weight - " << B.getWeight() << endl;
- else
- cout << "Sports car color - " << B.getColor() << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment