Start location LAB8
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
#include "Apartment.h"
|
||||
#include <iostream>
|
||||
|
||||
Apartment::Apartment() {
|
||||
rooms = 0;
|
||||
|
||||
std::cout << "Apartment created\n";
|
||||
}
|
||||
|
||||
Apartment::Apartment(double price,
|
||||
std::string address,
|
||||
int rooms)
|
||||
: Property(price, address) {
|
||||
|
||||
this->rooms = rooms;
|
||||
|
||||
std::cout << "Apartment created\n";
|
||||
}
|
||||
|
||||
void Apartment::addResident(Human* resident) {
|
||||
residents.push_back(resident);
|
||||
}
|
||||
|
||||
void Apartment::show() const {
|
||||
|
||||
std::cout
|
||||
<< "\nApartment\n"
|
||||
<< "Address: " << address << std::endl
|
||||
<< "Price: " << price << std::endl
|
||||
<< "Rooms: " << rooms << std::endl;
|
||||
|
||||
std::cout << "Residents:\n";
|
||||
|
||||
for (int i = 0; i < residents.size(); i++) {
|
||||
residents[i]->showInfo();
|
||||
}
|
||||
}
|
||||
|
||||
Apartment::~Apartment() {
|
||||
std::cout << "Apartment deleted\n";
|
||||
}
|
||||
|
||||
std::unique_ptr<Property> Apartment::clone() const {
|
||||
return std::make_unique<Apartment>(*this);
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef APARTMENT_H
|
||||
#define APARTMENT_H
|
||||
|
||||
#include "../Property/Property.h"
|
||||
#include "../Human/Human.h"
|
||||
#include <vector>
|
||||
|
||||
class Apartment : public Property {
|
||||
private:
|
||||
int rooms;
|
||||
std::vector<Human*> residents;
|
||||
|
||||
public:
|
||||
Apartment();
|
||||
Apartment(double price,
|
||||
std::string address,
|
||||
int rooms);
|
||||
|
||||
void addResident(Human* resident);
|
||||
|
||||
void show() const override;
|
||||
|
||||
~Apartment();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,38 @@
|
||||
#include "Car.h"
|
||||
#include <iostream>
|
||||
|
||||
Car::Car() {
|
||||
brand = "Unknown";
|
||||
horsepower = 0;
|
||||
|
||||
std::cout << "Car created\n";
|
||||
}
|
||||
|
||||
Car::Car(double price,
|
||||
std::string address,
|
||||
std::string brand,
|
||||
int horsepower)
|
||||
: Property(price, address) {
|
||||
|
||||
this->brand = brand;
|
||||
this->horsepower = horsepower;
|
||||
|
||||
std::cout << "Car created\n";
|
||||
}
|
||||
|
||||
void Car::show() const {
|
||||
|
||||
std::cout
|
||||
<< "\nCar\n"
|
||||
<< "Brand: " << brand << std::endl
|
||||
<< "Horsepower: " << horsepower << std::endl
|
||||
<< "Price: " << price << std::endl;
|
||||
}
|
||||
|
||||
Car::~Car() {
|
||||
std::cout << "Car deleted\n";
|
||||
}
|
||||
|
||||
std::unique_ptr<Property> Car::clone() const {
|
||||
return std::make_unique<Car>(*this);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef CAR_H
|
||||
#define CAR_H
|
||||
|
||||
#include "../Property/Property.h"
|
||||
|
||||
class Car : public Property {
|
||||
private:
|
||||
std::string brand;
|
||||
int horsepower;
|
||||
|
||||
public:
|
||||
Car();
|
||||
|
||||
Car(double price,
|
||||
std::string address,
|
||||
std::string brand,
|
||||
int horsepower);
|
||||
|
||||
void show() const override;
|
||||
|
||||
~Car();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
#include "City.h"
|
||||
#include <iostream>
|
||||
|
||||
City::City() {
|
||||
std::cout << "City created\n";
|
||||
}
|
||||
|
||||
City::City(const City& other) {
|
||||
std::cout << "City COPY\n";
|
||||
|
||||
for (const auto& p : other.properties) {
|
||||
properties.push_back(p->clone());
|
||||
}
|
||||
}
|
||||
|
||||
City& City::operator=(const City& other) {
|
||||
|
||||
std::cout << "City ASSIGN\n";
|
||||
|
||||
if (this == &other)
|
||||
return *this;
|
||||
|
||||
properties.clear();
|
||||
|
||||
for (const auto& p : other.properties) {
|
||||
properties.push_back(p->clone());
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
void City::addProperty(const Property& property) {
|
||||
properties.push_back(property.clone());
|
||||
}
|
||||
|
||||
void City::showAll() const {
|
||||
|
||||
std::cout << "\nCITY PROPERTY LIST\n";
|
||||
|
||||
for (const auto& p : properties) {
|
||||
p->show();
|
||||
}
|
||||
}
|
||||
|
||||
City::~City() {
|
||||
std::cout << "City destroyed\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef CITY_H
|
||||
#define CITY_H
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include "../Property/Property.h"
|
||||
|
||||
class City {
|
||||
private:
|
||||
std::vector<std::unique_ptr<Property>> properties;
|
||||
|
||||
public:
|
||||
City();
|
||||
|
||||
void addProperty(const Property& property);
|
||||
|
||||
void showAll() const;
|
||||
|
||||
City(const City& other);
|
||||
City& operator=(const City& other);
|
||||
|
||||
~City();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,39 @@
|
||||
#include "CountryHouse.h"
|
||||
#include <iostream>
|
||||
|
||||
CountryHouse::CountryHouse() {
|
||||
floors = 0;
|
||||
landArea = 0;
|
||||
|
||||
std::cout << "CountryHouse created\n";
|
||||
}
|
||||
|
||||
CountryHouse::CountryHouse(double price,
|
||||
std::string address,
|
||||
int floors,
|
||||
double landArea)
|
||||
: Property(price, address) {
|
||||
|
||||
this->floors = floors;
|
||||
this->landArea = landArea;
|
||||
|
||||
std::cout << "CountryHouse created\n";
|
||||
}
|
||||
|
||||
void CountryHouse::show() const {
|
||||
|
||||
std::cout
|
||||
<< "\nCountry House\n"
|
||||
<< "Address: " << address << std::endl
|
||||
<< "Floors: " << floors << std::endl
|
||||
<< "Land area: " << landArea << std::endl
|
||||
<< "Price: " << price << std::endl;
|
||||
}
|
||||
|
||||
CountryHouse::~CountryHouse() {
|
||||
std::cout << "CountryHouse deleted\n";
|
||||
}
|
||||
|
||||
std::unique_ptr<Property> CountryHouse::clone() const {
|
||||
return std::make_unique<CountryHouse>(*this);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
#ifndef COUNTRYHOUSE_H
|
||||
#define COUNTRYHOUSE_H
|
||||
|
||||
#include "../Property/Property.h"
|
||||
|
||||
class CountryHouse : public Property {
|
||||
private:
|
||||
int floors;
|
||||
double landArea;
|
||||
|
||||
public:
|
||||
CountryHouse();
|
||||
|
||||
CountryHouse(double price,
|
||||
std::string address,
|
||||
int floors,
|
||||
double landArea);
|
||||
|
||||
void show() const override;
|
||||
|
||||
~CountryHouse();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "Human.h"
|
||||
#include <iostream>
|
||||
|
||||
Human::Human() {
|
||||
name = "Unknown";
|
||||
surname = "Unknown";
|
||||
age = 0;
|
||||
|
||||
std::cout << "Human created\n";
|
||||
}
|
||||
|
||||
Human::Human(std::string name, std::string surname, int age) {
|
||||
this->name = name;
|
||||
this->surname = surname;
|
||||
this->age = age;
|
||||
|
||||
std::cout << "Human created: "
|
||||
<< name << " "
|
||||
<< surname << std::endl;
|
||||
}
|
||||
|
||||
std::string Human::getName() const {
|
||||
return name;
|
||||
}
|
||||
|
||||
std::string Human::getSurname() const {
|
||||
return surname;
|
||||
}
|
||||
|
||||
int Human::getAge() const {
|
||||
return age;
|
||||
}
|
||||
|
||||
void Human::showInfo() const {
|
||||
std::cout
|
||||
<< name << " "
|
||||
<< surname << ", age: "
|
||||
<< age << std::endl;
|
||||
}
|
||||
|
||||
Human::~Human() {
|
||||
std::cout << "Human deleted: "
|
||||
<< name << " "
|
||||
<< surname << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef HUMAN_H
|
||||
#define HUMAN_H
|
||||
|
||||
#include <string>
|
||||
|
||||
class Human {
|
||||
private:
|
||||
std::string name;
|
||||
std::string surname;
|
||||
int age;
|
||||
|
||||
public:
|
||||
Human();
|
||||
Human(std::string name, std::string surname, int age);
|
||||
|
||||
std::string getName() const;
|
||||
std::string getSurname() const;
|
||||
int getAge() const;
|
||||
|
||||
void showInfo() const;
|
||||
|
||||
~Human();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,31 @@
|
||||
#include "Owner.h"
|
||||
#include <iostream>
|
||||
|
||||
Owner::Owner() : Human() {
|
||||
std::cout << "Owner created\n";
|
||||
}
|
||||
|
||||
Owner::Owner(std::string name,
|
||||
std::string surname,
|
||||
int age)
|
||||
: Human(name, surname, age) {
|
||||
|
||||
std::cout << "Owner created\n";
|
||||
}
|
||||
|
||||
void Owner::addProperty(Property* property) {
|
||||
properties.push_back(property);
|
||||
}
|
||||
|
||||
void Owner::showProperties() const {
|
||||
|
||||
std::cout << "\nOWNER PROPERTY LIST\n";
|
||||
|
||||
for (int i = 0; i < properties.size(); i++) {
|
||||
properties[i]->show();
|
||||
}
|
||||
}
|
||||
|
||||
Owner::~Owner() {
|
||||
std::cout << "Owner deleted\n";
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef OWNER_H
|
||||
#define OWNER_H
|
||||
|
||||
#include "../Human/Human.h"
|
||||
#include "../Property/Property.h"
|
||||
#include <vector>
|
||||
|
||||
class Owner : public Human {
|
||||
private:
|
||||
std::vector<Property*> properties;
|
||||
|
||||
public:
|
||||
Owner();
|
||||
|
||||
Owner(std::string name,
|
||||
std::string surname,
|
||||
int age);
|
||||
|
||||
void addProperty(Property* property);
|
||||
|
||||
void showProperties() const;
|
||||
|
||||
~Owner();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#include "Property.h"
|
||||
#include <iostream>
|
||||
|
||||
Property::Property() {
|
||||
price = 0;
|
||||
address = "Unknown";
|
||||
}
|
||||
|
||||
Property::Property(double price, std::string address) {
|
||||
this->price = price;
|
||||
this->address = address;
|
||||
}
|
||||
|
||||
Property::~Property() {
|
||||
std::cout << "Property deleted\n";
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#ifndef PROPERTY_H
|
||||
#define PROPERTY_H
|
||||
|
||||
#include <string>
|
||||
#include <memory>
|
||||
|
||||
class Property {
|
||||
protected:
|
||||
double price;
|
||||
std::string address;
|
||||
|
||||
public:
|
||||
Property();
|
||||
Property(double price, std::string address);
|
||||
|
||||
virtual void show() const = 0;
|
||||
|
||||
virtual std::unique_ptr<Property> clone() const = 0;
|
||||
|
||||
virtual ~Property();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "PropertyFactory.h"
|
||||
#include "../Apartment/Apartment.h"
|
||||
#include "../Car/Car.h"
|
||||
#include "../CountryHouse/CountryHouse.h"
|
||||
|
||||
std::unique_ptr<Property> PropertyFactory::create(Type type) {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case APARTMENT:
|
||||
return std::make_unique<Apartment>(120000, "Moscow", 3);
|
||||
|
||||
case CAR:
|
||||
return std::make_unique<Car>(30000, "Garage", "BMW", 250);
|
||||
|
||||
case COUNTRY_HOUSE:
|
||||
return std::make_unique<CountryHouse>(500000, "Village", 2, 15.5);
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef PROPERTYFACTORY_H
|
||||
#define PROPERTYFACTORY_H
|
||||
|
||||
#include <memory>
|
||||
#include "../Property/Property.h"
|
||||
|
||||
class PropertyFactory {
|
||||
public:
|
||||
enum Type {
|
||||
APARTMENT,
|
||||
CAR,
|
||||
COUNTRY_HOUSE
|
||||
};
|
||||
|
||||
static std::unique_ptr<Property> create(Type type);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,43 @@
|
||||
#ifndef TAXRATES_H
|
||||
#define TAXRATES_H
|
||||
|
||||
namespace TAX_RATES {
|
||||
|
||||
// ==========================
|
||||
// НАЛОГИ ДЛЯ АВТОМОБИЛЕЙ
|
||||
// ==========================
|
||||
|
||||
const double CAR_TAX = 0.0007;
|
||||
|
||||
const double CAR_TRUCK_TAX = 0.007;
|
||||
|
||||
const double CAR_LUXURY_TAX = 0.027;
|
||||
|
||||
// ==========================
|
||||
// НАЛОГИ ДЛЯ КВАРТИР
|
||||
// ==========================
|
||||
|
||||
const double APARTMENT_TAX = 0.001;
|
||||
|
||||
const double APARTMENT_LUXURY_TAX = 0.004;
|
||||
|
||||
// ==========================
|
||||
// НАЛОГ ДЛЯ ДОМА
|
||||
// ==========================
|
||||
|
||||
const double COUNTRY_HOUSE_TAX = 0.01;
|
||||
|
||||
// ==========================
|
||||
// ГРАНИЦЫ
|
||||
// ==========================
|
||||
|
||||
const double LOW_HORSEPOWER = 100;
|
||||
|
||||
const double HIGH_HORSEPOWER = 200;
|
||||
|
||||
const unsigned int LIMIT_DISTANCE_FROM_CITY = 30;
|
||||
|
||||
const int LIMIT_APARTMENT_SQUARE = 100;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,18 @@
|
||||
#include "City/City.h"
|
||||
#include "Apartment/Apartment.h"
|
||||
#include "Car/Car.h"
|
||||
#include "CountryHouse/CountryHouse.h"
|
||||
#include <iostream>
|
||||
|
||||
int main() {
|
||||
|
||||
City city;
|
||||
|
||||
city.addProperty(*PropertyFactory::create(PropertyFactory::CAR));
|
||||
city.addProperty(*PropertyFactory::create(PropertyFactory::APARTMENT));
|
||||
city.addProperty(*PropertyFactory::create(PropertyFactory::COUNTRY_HOUSE));
|
||||
|
||||
city.showAll();
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user