Start location LAB8

This commit is contained in:
2026-05-14 09:17:54 +03:00
commit 0e74a9eb90
29 changed files with 645 additions and 0 deletions
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
+2
View File
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module classpath="CMake" type="CPP_MODULE" version="4" />
+10
View File
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="MaterialThemeProjectNewConfig">
<option name="metadata">
<MTProjectMetadataState>
<option name="userId" value="-51ab2c09:19e209689d2:-7dc7" />
</MTProjectMetadataState>
</option>
</component>
</project>
+7
View File
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Lab8.iml" filepath="$PROJECT_DIR$/.idea/Lab8.iml" />
</modules>
</component>
</project>
Generated
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
+24
View File
@@ -0,0 +1,24 @@
cmake_minimum_required(VERSION 4.0)
project(Lab8)
set(CMAKE_CXX_STANDARD 20)
add_executable(Lab8
src/main.cpp
src/Property/Property.cpp
src/Property/Property.h
src/Apartment/Apartment.cpp
src/Apartment/Apartment.h
src/Car/Car.cpp
src/Car/Car.h
src/CountryHouse/CountryHouse.cpp
src/CountryHouse/CountryHouse.h
src/Owner/Owner.cpp
src/Owner/Owner.h
src/TaxRates/TaxRates.h
src/Human/Human.cpp
src/Human/Human.h
src/City/City.cpp
src/City/City.h
src/PropertyFactory/PropertyFactory.cpp
src/PropertyFactory/PropertyFactory.h)
+2
View File
@@ -0,0 +1,2 @@
# hi
**I am a** circle
+42
View File
@@ -0,0 +1,42 @@
@startuml
class Property {
# double price
# string address
+ show()
+ clone()
}
class Apartment {
- int rooms
+ show()
+ clone()
}
class Car {
- string brand
- int horsepower
+ show()
+ clone()
}
class CountryHouse {
- int floors
- double landArea
+ show()
+ clone()
}
class City {
- vector<Property>
+ addProperty()
+ showAll()
}
Property <|-- Apartment
Property <|-- Car
Property <|-- CountryHouse
City o-- Property
@enduml
View File
View File
+45
View File
@@ -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);
}
+26
View File
@@ -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
+38
View File
@@ -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);
}
+24
View File
@@ -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
+49
View File
@@ -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";
}
+25
View File
@@ -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
+39
View File
@@ -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);
}
+24
View File
@@ -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
+45
View File
@@ -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;
}
+25
View File
@@ -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
+31
View File
@@ -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";
}
+26
View File
@@ -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
+16
View File
@@ -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";
}
+23
View File
@@ -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
+21
View File
@@ -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;
}
+18
View File
@@ -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
+43
View File
@@ -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
+18
View File
@@ -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;
}