Untitled
unknown
c_cpp
10 months ago
6.7 kB
23
Indexable
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
// Класс для клиента
class Client {
private:
string name;
string gender;
int age;
double weight;
int desiredVisits; // Желаемое число посещений
double budget; // Бюджет клиента
vector<string> sportPreferences; // Предпочтения по видам спорта
public:
Client(string name, string gender, int age, double weight, int visits, double budget, vector<string> prefs = {}) {
this->name = name;
this->gender = gender;
this->age = age;
this->weight = weight;
this->desiredVisits = visits;
this->budget = budget;
this->sportPreferences = prefs;
}
// Геттеры
string getName() const { return name; }
int getDesiredVisits() const { return desiredVisits; }
double getBudget() const { return budget; }
const vector<string>& getPreferences() const { return sportPreferences; }
};
// Класс для тренера
class Trainer {
public:
string name;
string sportType; // Вид занятия
string category; // Категория тренера
double ratePerSession; // Стоимость занятия
Trainer(string name, string sportType, string category, double rate) {
this->name = name;
this->sportType = sportType;
this->category = category;
this->ratePerSession = rate;
}
};
// Абстрактный тариф
class Tarif {
protected:
int id;
string name;
double baseCostPerDay; // Базовая стоимость за день
int validityDays; // Срок действия тарифа
public:
Tarif(int id, string name, double cost, int days) {
this->id = id;
this->name = name;
this->baseCostPerDay = cost;
this->validityDays = days;
}
virtual double computeCost(const Client& client) = 0; // Абстрактный метод расчета стоимости
string getName() const { return name; }
};
// Конкретный тариф
class RegularSession : public Tarif {
public:
RegularSession(int id, string name, double cost, int days) : Tarif(id, name, cost, days) {}
double computeCost(const Client& client) override {
return baseCostPerDay * client.getDesiredVisits(); // Стоимость = базовая * посещения
}
};
// Конкретный тариф
class GroupSession : public Tarif {
private:
string sportType;
Trainer* trainer; // Тренер для группы
int groupSize; // Размер группы
public:
GroupSession(int id, string name, double cost, int days, string sportType, Trainer* trainer, int groupSize)
: Tarif(id, name, cost, days) {
this->sportType = sportType;
this->trainer = trainer;
this->groupSize = groupSize;
}
double computeCost(const Client& client) override {
double base = baseCostPerDay * client.getDesiredVisits(); // Базовая стоимость
double trainerCost = (trainer ? trainer->ratePerSession / groupSize * client.getDesiredVisits() : 0); // Стоимость тренера на клиента
return base + trainerCost;
}
};
// Конкретный тариф
class PersonalSession : public Tarif {
private:
string sportType;
Trainer* trainer;
public:
PersonalSession(int id, string name, double cost, int days, string sportType, Trainer* trainer)
: Tarif(id, name, cost, days) {
this->sportType = sportType;
this->trainer = trainer;
}
double computeCost(const Client& client) override {
double base = baseCostPerDay * client.getDesiredVisits();
double trainerCost = (trainer ? trainer->ratePerSession * client.getDesiredVisits() : 0); // Полная стоимость тренера
return base + trainerCost;
}
};
// Класс компании
class Company {
private:
string name;
vector<Tarif*> tariffs;
vector<Trainer*> trainers;
public:
Company(string name) { this->name = name; }
void addTarif(Tarif* t) { tariffs.push_back(t); } // Добавить тариф
void addTrainer(Trainer* t) { trainers.push_back(t); } // Добавить тренера
void recommendTariffs(const Client& client) {
vector<pair<string, double>> costs;
// Рассчитать стоимость для каждого тарифа
for (auto t : tariffs) {
double cost = t->computeCost(client);
costs.push_back({ t->getName(), cost });
}
// Сортировка по возрастанию стоимости
sort(costs.begin(), costs.end(), [](auto& a, auto& b) { return a.second < b.second; });
// Вывод топ-3 тарифов
cout << "Топ 3 рекомендуемых тарифов для клиента " << client.getName() << ":\n";
for (int i = 0; i < min(3, (int)costs.size()); ++i) {
cout << i + 1 << ". " << costs[i].first << " - " << costs[i].second << " руб.\n";
}
}
};
// точка входа
int main() {
// Создаем тренеров
Trainer t1("Иванов", "Йога", "Профессионал", 500);
Trainer t2("Петрова", "Силовые", "Эксперт", 700);
Company gym("Крутая качалка");
// Создаем тарифы
RegularSession r1(1, "Базовый", 300, 30);
GroupSession g1(2, "Групповые занятия Йога", 200, 30, "Йога", &t1, 5);
PersonalSession p1(3, "Индивидуальные Силовые", 300, 30, "Силовые", &t2);
// Добавляем тарифы в компанию
gym.addTarif(&r1);
gym.addTarif(&g1);
gym.addTarif(&p1);
// Создаем клиентов
Client c1("Алексей", "М", 25, 75, 12, 10000, { "Йога" });
Client c2("Мария", "Ж", 30, 60, 8, 8000, {});
Client c3("Дмитрий", "М", 28, 80, 20, 15000, { "Силовые" });
// Вывод рекомендаций для клиентов
gym.recommendTariffs(c1);
cout << "------------------------\n";
gym.recommendTariffs(c2);
cout << "------------------------\n";
gym.recommendTariffs(c3);
}
Editor is loading...
Leave a Comment