У меня есть текстовый файл со списком игр, и каждые 2 игры относятся к разным категориям
League Of Legends MMO
World Of Warcraft MMO
Civilization Strategy
Hearthstone Strategy
Street Fighter Arcade
PacMan Arcade
Beat Saber AR
Superhot AR
У меня есть 4 дочерних класса, которые называются MMO, Strategy, Arcade и AR. Каждая из категорий (arcade, mmo, et c.) Имеет свою собственную функцию polymorphi c для получения цены, например, добавление ежемесячной платы et c.
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
class Game {
string Name;
string Description;
Game(string Name, string Description);
};
//PC inherits Game
class PC : public Game {
string Name;
string Description;
PC():Game(Name,Description)
};
// MMO inherits PC
class MMO : public PC {
string Name;
string Description;
double basePrice;
double monthlyFee;
MMO():PC(Name,Description)
//Polymorphic function declaration
virtual double getMonthlyCost() {
monthlyFee = 14.99;
}
};
//Strategy inherits PC
class Strategy : public PC {
string Name;
string Description;
double basePrice;
double monthlyFee;
Strategy():PC(Name, Description)
double getMonthlyCost() {
basePrice* monthlyFee;
}
};
class Console {
string Name;
string Description;
Console(string Name, string Description);
};
//Arcade inherits Console
class Arcade : public Console {
string Name;
string Description;
double basePrice;
Arcade():Console(Name, Description)
double getMonthlyCost() {
basePrice + (basePrice * 0.10);
}
};
//AR inherits Console
class AR : public Console {
string Name;
string Description;
double costOfEquipment;
double basePrice;
AR():Console(Name, Description)
double getMonthlyCost() {
costOfEquipment + basePrice;
}
};
. Мой вопрос как бы я go рассортировал игры из текстового файла по их соответствующим категориям, чтобы их можно было рассчитать с использованием их соответствующей функции getMonthlyCost?
Я открыт для любой критики и комментариев!