Skip to content

Instantly share code, notes, and snippets.

@vlaleli
Created April 1, 2026 22:11
Show Gist options
  • Select an option

  • Save vlaleli/18f223ad802caf1c56299460fb0ec873 to your computer and use it in GitHub Desktop.

Select an option

Save vlaleli/18f223ad802caf1c56299460fb0ec873 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <memory>
using namespace std;
class DeviceImplementor {
public:
virtual ~DeviceImplementor() = default;
virtual string getDeviceType() const = 0;
virtual string getCharacteristics() const = 0;
};
class VideoCard : public DeviceImplementor {
private:
string model;
int memoryGB;
string chipset;
public:
VideoCard(const string& model, int memoryGB, const string& chipset)
: model(model), memoryGB(memoryGB), chipset(chipset) {}
string getDeviceType() const override {
return "Видеокарта";
}
string getCharacteristics() const override {
return "Модель: " + model +
"\nОбъем памяти: " + to_string(memoryGB) + " GB" +
"\nЧипсет: " + chipset;
}
};
class Processor : public DeviceImplementor {
private:
string model;
int cores;
double frequencyGHz;
public:
Processor(const string& model, int cores, double frequencyGHz)
: model(model), cores(cores), frequencyGHz(frequencyGHz) {}
string getDeviceType() const override {
return "Процессор";
}
string getCharacteristics() const override {
return "Модель: " + model +
"\nКоличество ядер: " + to_string(cores) +
"\nЧастота: " + to_string(frequencyGHz) + " GHz";
}
};
class HardDrive : public DeviceImplementor {
private:
string model;
int capacityGB;
string type;
public:
HardDrive(const string& model, int capacityGB, const string& type)
: model(model), capacityGB(capacityGB), type(type) {}
string getDeviceType() const override {
return "Жесткий диск";
}
string getCharacteristics() const override {
return "Модель: " + model +
"\nОбъем: " + to_string(capacityGB) + " GB" +
"\nТип: " + type;
}
};
class RAM : public DeviceImplementor {
private:
string model;
int capacityGB;
int frequencyMHz;
public:
RAM(const string& model, int capacityGB, int frequencyMHz)
: model(model), capacityGB(capacityGB), frequencyMHz(frequencyMHz) {}
string getDeviceType() const override {
return "Оперативная память";
}
string getCharacteristics() const override {
return "Модель: " + model +
"\nОбъем: " + to_string(capacityGB) + " GB" +
"\nЧастота: " + to_string(frequencyMHz) + " MHz";
}
};
class Report {
protected:
shared_ptr<DeviceImplementor> device;
public:
Report(shared_ptr<DeviceImplementor> device) : device(device) {}
virtual ~Report() = default;
virtual void printReport() const = 0;
};
class StandardReport : public Report {
public:
StandardReport(shared_ptr<DeviceImplementor> device) : Report(device) {}
void printReport() const override {
cout << "===== ОТЧЕТ ОБ УСТРОЙСТВЕ =====" << endl;
cout << "Тип устройства: " << device->getDeviceType() << endl;
cout << device->getCharacteristics() << endl;
cout << "===============================" << endl << endl;
}
};
class DetailedReport : public Report {
public:
DetailedReport(shared_ptr<DeviceImplementor> device) : Report(device) {}
void printReport() const override {
cout << "***** ДЕТАЛЬНЫЙ ОТЧЕТ *****" << endl;
cout << "Устройство: " << device->getDeviceType() << endl;
cout << "Характеристики:" << endl;
cout << device->getCharacteristics() << endl;
cout << "***************************" << endl << endl;
}
};
int main() {
shared_ptr<DeviceImplementor> gpu = make_shared<VideoCard>("NVIDIA RTX 4060", 8, "Ada Lovelace");
shared_ptr<DeviceImplementor> cpu = make_shared<Processor>("Intel Core i7-12700K", 12, 3.6);
shared_ptr<DeviceImplementor> hdd = make_shared<HardDrive>("Seagate Barracuda", 2000, "HDD");
shared_ptr<DeviceImplementor> ram = make_shared<RAM>("Kingston Fury Beast", 16, 3200);
StandardReport report1(gpu);
StandardReport report2(cpu);
DetailedReport report3(hdd);
DetailedReport report4(ram);
report1.printReport();
report2.printReport();
report3.printReport();
report4.printReport();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment