This commit is contained in:
Andrey Kassaev 2024-03-04 20:30:45 +04:00
commit 7e4ee3d522
16 changed files with 164 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*/*
OOP*

1
Car.cpp Normal file
View File

@ -0,0 +1 @@
#include "Car.h"

29
Car.h Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include "Transport.h"
#include <string>
#include <iostream>
class Car : Transport
{
public:
std::string make;
std::string model;
int year;
Car(TransportMode value, std::string make, std::string model, int year) : Transport(value) {
this->make = make;
this->model = model;
this->year = year;
};
void getInfo() {
std::cout << "Car Info:\n" << \
"Make: " << this->make << "\n" <<\
"Model: " << this->model << "\n" <<\
"Year: " << this->year << "\n\n";
};
void move() override {
std::cout << "Car is moving...\n";
};
};

1
CarDriver.cpp Normal file
View File

@ -0,0 +1 @@
#include "CarDriver.h"

20
CarDriver.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include "Car.h"
#include "Driver.h"
class CarDriver
{
public:
Car* car;
Driver* driver;
CarDriver(Car &car, Driver &driver) {
this->car = &car;
this->driver = &driver;
}
virtual void driveCar() = 0;
};

1
Driver.cpp Normal file
View File

@ -0,0 +1 @@
#include "Driver.h"

20
Driver.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
#include <iostream>
#include <string>
class Driver
{
public:
std::string name;
int age;
Driver(std::string name, int age) {
this->name = name;
this->age = age;
}
void getInfo() {
std::cout << "Driver Info:\n" << \
"Name: " << this->name << "\n" << \
"Age: " << this->age << "\n\n";
}
};

29
Main.cpp Normal file
View File

@ -0,0 +1,29 @@
#pragma once
#include "Car.h"
#include "Driver.h"
#include "TransportMode.h"
#include "ServiceCarDriver.h"
#include "TaxiDriver.h"
int main() {
Car car1(TransportMode::Land, "Lada", "Largus", 2019);
Driver driver1("Philipp Kirkorov", 56);
Car car2(TransportMode::Land, "Lada", "Kalina", 2012);
Driver driver2("Nikolay Baskov", 47);
ServiceCarDriver serviceCarDriver(car1, driver1, "Pyaterochka+");
serviceCarDriver.driveCar();
serviceCarDriver.car->getInfo();
serviceCarDriver.driver->getInfo();
TaxiDriver taxiDriver(car2, driver2, true);
taxiDriver.driveCar();
taxiDriver.car->getInfo();
taxiDriver.driver->getInfo();
system("pause");
return 0;
};

1
ServiceCarDriver.cpp Normal file
View File

@ -0,0 +1 @@
#include "ServiceCarDriver.h"

17
ServiceCarDriver.h Normal file
View File

@ -0,0 +1,17 @@
#pragma once
#include "CarDriver.h"
class ServiceCarDriver : public CarDriver
{
public:
std::string companyName;
ServiceCarDriver(Car& car, Driver& driver, std::string companyName): CarDriver(car, driver) {
this->companyName = companyName;
};
void driveCar() override {
std::cout << "Driving " << this->companyName << "'s car\n";
};
};

1
TaxiDriver.cpp Normal file
View File

@ -0,0 +1 @@
#include "TaxiDriver.h"

22
TaxiDriver.h Normal file
View File

@ -0,0 +1,22 @@
#pragma once
#include "CarDriver.h"
class TaxiDriver :
public CarDriver
{
public:
bool checkersOn;
TaxiDriver(Car& car, Driver& driver, bool checkersOn) : CarDriver(car, driver) {
this->checkersOn = checkersOn;
};
void driveCar() override {
std::cout << "Driving Taxi Car with Checkers " << (this->checkersOn? "ON\n" : "OFF\n");
}
void tellStory() {
std::cout << "Zolotay chasha zolotaya! Napolnyet aromatom chaya!...\n";
}
};

1
Transport.cpp Normal file
View File

@ -0,0 +1 @@
#include "Transport.h"

13
Transport.h Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "TransportMode.h"
class Transport
{
public:
TransportMode mode;
Transport(TransportMode value) {
mode = value;
};
virtual void move() = 0;
};

1
TransportMode.cpp Normal file
View File

@ -0,0 +1 @@
#include "TransportMode.h"

5
TransportMode.h Normal file
View File

@ -0,0 +1,5 @@
#pragma once
enum class TransportMode {
Land, Air, Water
};