Professional Documents
Culture Documents
Untitled Document
Untitled Document
1)
#include <iostream>
class Lion;
class Tiger;
class Lion {
private:
float weight;
float bodyLength;
float leapLength;
float shoulderGirth;
public:
Lion() {
cout << "Enter the weight of the lion: ";
cin >> weight;
cout << "Enter the body length of the lion: ";
cin >> bodyLength;
cout << "Enter the leap length of the lion: ";
cin >> leapLength;
cout << "Enter the shoulder girth of the lion: ";
cin >> shoulderGirth;
}
class Tiger {
private:
float weight;
float bodyLength;
float leapLength;
float shoulderGirth;
public:
Tiger() {
cout << "Enter the weight of the tiger: ";
cin >> weight;
cout << "Enter the body length of the tiger: ";
cin >> bodyLength;
cout << "Enter the leap length of the tiger: ";
cin >> leapLength;
cout << "Enter the shoulder girth of the tiger: ";
cin >> shoulderGirth;
}
int main() {
Lion lion;
Tiger tiger;
compareWeights(lion, tiger);
return 0;
}
2)
#include <iostream>
#include <string>
class Vehicle {
protected:
double weight;
bool rare;
public:
Vehicle(double weight, bool rare) : weight(weight), rare(rare) {
cout << "Vehicle constructor called." << endl;
}
virtual ~Vehicle() {
cout << "Vehicle destructor called." << endl;
}
void print() {
cout << "Weight: " << weight << " Rare: " << rare << endl;
}
};
public:
Car(double weight, bool rare, int speed, int cvl) : Vehicle(weight, rare), speed(speed), cvl(cvl)
{
cout << "Car constructor called." << endl;
}
~Car() {
cout << "Car destructor called." << endl;
}
void print() {
Vehicle::print();
cout << "Speed: " << speed << " CVL: " << cvl << endl;
}
public:
Bus(double weight, bool rare, int speed, int cvl, string color, int passengers) : Car(weight,
rare, speed, cvl), color(color), passengers(passengers) {
cout << "Bus constructor called." << endl;
}
~Bus() {
cout << "Bus destructor called." << endl;
}
void print() {
Car::print();
cout << "Color: " << color << " Passengers: " << passengers << endl;
}
int main() {
int newPassengers;
cout << "Enter new number of bus passengers: ";
cin >> newPassengers;
bus->setPassengers(newPassengers);
int newSpeed;
cout << "Enter new speed of the car: ";
cin >> newSpeed;
car->setSpeed(newSpeed);
cout << endl;
delete car;
delete bus;
return 0;
}