You are on page 1of 6

Ilia lomidze bileti 2

1)

#include <iostream>

using namespace std;

class Lion;
class Tiger;

void compareWeights(const Lion& lion, const Tiger& 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;
}

friend void compareWeights(const Lion& lion, const Tiger& tiger);

float getWeight() const {


return weight;
}

float getBodyLength() const {


return bodyLength;
}

float getLeapLength() const {


return leapLength;
}
float getShoulderGirth() const {
return 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;
}

friend void compareWeights(const Lion& lion, const Tiger& tiger);

float getWeight() const {


return weight;
}

float getBodyLength() const {


return bodyLength;
}

float getLeapLength() const {


return leapLength;
}

float getShoulderGirth() const {


return shoulderGirth;
}
};
void compareWeights(const Lion& lion, const Tiger& tiger) {
if (lion.weight > tiger.weight) {
cout << "The lion weighs more. ";
cout << "The movement speed of the lion: " << lion.leapLength << endl;
} else if (lion.weight < tiger.weight) {
cout << "The tiger weighs more. ";
cout << "The movement speed of the tiger: " << tiger.leapLength << endl;
} else {
cout << "The weights are equal. ";
cout << "Lion's body length: " << lion.bodyLength << endl;
cout << "Lion's leap length: " << lion.leapLength << endl;
cout << "Lion's shoulder girth: " << lion.shoulderGirth << endl;
}
}

int main() {
Lion lion;
Tiger tiger;

compareWeights(lion, tiger);

return 0;
}

2)
#include <iostream>
#include <string>

using namespace std;

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;
}
};

class Car : public Vehicle {


protected:
int speed;
int cvl;

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;
}

void setSpeed(int newSpeed) {


if (newSpeed > 110)
speed = 60;
else
speed = newSpeed;
}
};

class Bus : public Car {


protected:
string color;
int passengers;

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;
}

void setPassengers(int newPassengers) {


passengers = newPassengers;
}
};

int main() {

Vehicle vehicle(1000.0, false);


cout << "Vehicle information:" << endl;
vehicle.print();
cout << endl;

Car* car = new Car(1200.0, true, 150, 4);


cout << "Car information:" << endl;
car->print();
cout << endl;

Bus* bus = new Bus(3000.0, false, 100, 8, "Red", 40);


cout << "Bus information:" << endl;
bus->print();
cout << endl;

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;

cout << "Updated Car information:" << endl;


car->print();
cout << endl;

cout << "Updated Bus information:" << endl;


bus->print();
cout << endl;

delete car;
delete bus;

return 0;
}

You might also like