Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<string>
- #include<sstream>
- using namespace std;
- class PC
- {
- public:
- string operatingSystem, model;
- int ramSlots, pcieSlots, cpu, totalRamSlots, gbPerRam, ssd, cost, gpu, afterb;
- virtual void Upgrade(string line) = 0;
- virtual void Print() = 0;
- PC(string m, string os, int rams, int pcies, int c, int totalRams, int gbPer, int s, int co, int g, int ab)
- {
- model = m;
- operatingSystem = os;
- ramSlots = rams;
- pcieSlots = pcies;
- cpu = c;
- totalRamSlots = totalRams;
- gbPerRam = gbPer;
- ssd = s;
- cost = co;
- gpu = g;
- afterb = ab;
- }
- };
- class HomePC: public PC
- {
- public:
- HomePC(string _model) : PC(model, "MacOS", 2, 0, 2, 1, 4, 256, 800, 0, 0)
- {
- this->model = _model;
- }
- void Upgrade(string line)
- {
- string tempcpu, tempTotalRamSlots, tempgbPerRam, del = " ";
- stringstream ss;
- int r = 1;
- tempcpu = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempTotalRamSlots = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempgbPerRam = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- if(tempcpu != "1" && tempcpu != "2" && tempcpu != "4" && tempcpu != "6" && tempcpu != "8")
- {
- cout << "Error: Wrong CPU cores number." << endl;
- r = 0;
- }
- if(tempTotalRamSlots != "2")
- {
- cout << "Error: Wrong RAM slots number." << endl;
- r = 0;
- }
- if(tempgbPerRam != "2" && tempgbPerRam != "4" && tempgbPerRam != "8" && tempgbPerRam != "16" && tempgbPerRam != "32" && tempgbPerRam != "64" && tempgbPerRam != "128")
- {
- cout << "Error: Wrong GB per RAM number." << endl;
- r = 0;
- }
- if(r == 1)
- {
- ss.clear();
- ss.str(tempcpu);
- ss >> cpu;
- ss.clear();
- ss.str(tempTotalRamSlots);
- ss >> totalRamSlots;
- ss.clear();
- ss.str(tempgbPerRam);
- ss >> gbPerRam;
- }
- }
- void Print()
- {
- cout << "Model: " << model << endl;
- cout << "Operating System: " << operatingSystem << endl;
- cout << "CPU: " << cpu << endl;
- cout << "Motherboard: " << ramSlots << ", " << pcieSlots << endl;
- cout << "RAM: " << totalRamSlots << ", " << gbPerRam << endl;
- cout << "SSD: " << ssd << "GB" << endl;
- cout << "Cost: " << cost << "EUR" << endl;
- }
- };
- class GamingPC: public PC
- {
- public:
- GamingPC(string _model) : PC(model, "Windows", 4, 2, 6, 2, 8, 1024, 1300, 1, 0)
- {
- this->model = _model;
- }
- void Upgrade(string line)
- {
- string tempcpu, tempTotalRamSlots, tempgbPerRam, tempgpu, del = " ";
- stringstream ss;
- int r = 1;
- tempcpu = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempTotalRamSlots = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempgbPerRam = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempgpu = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- if(tempcpu != "1" && tempcpu != "2" && tempcpu != "4" && tempcpu != "6" && tempcpu != "8")
- {
- cout << "Error: Wrong CPU cores number." << endl;
- r = 0;
- }
- if(tempTotalRamSlots != "2" && tempTotalRamSlots != "4")
- {
- cout << "Error: Wrong RAM slots number." << endl;
- r = 0;
- }
- if(tempgbPerRam != "2" && tempgbPerRam != "4" && tempgbPerRam != "8" && tempgbPerRam != "16" && tempgbPerRam != "32" && tempgbPerRam != "64" && tempgbPerRam != "128")
- {
- cout << "Error: Wrong GB per RAM number." << endl;
- r = 0;
- }
- if(tempgpu != "0" && tempgpu != "1" && tempgpu != "2")
- {
- cout << "Error: Wrong GPU number." << endl;
- r = 0;
- }
- if(r == 1)
- {
- ss.clear();
- ss.str(tempcpu);
- ss >> cpu;
- ss.clear();
- ss.str(tempTotalRamSlots);
- ss >> totalRamSlots;
- ss.clear();
- ss.str(tempgbPerRam);
- ss >> gbPerRam;
- ss.clear();
- ss.str(tempgpu);
- ss >> gpu;
- }
- }
- void Print()
- {
- cout << "Model: " << model << endl;
- cout << "Operating System: " << operatingSystem << endl;
- cout << "CPU: " << cpu << endl;
- cout << "Motherboard: " << ramSlots << ", " << pcieSlots << endl;
- cout << "RAM: " << totalRamSlots << ", " << gbPerRam << endl;
- cout << "SSD: " << ssd << "GB" << endl;
- cout << "GPU: " << gpu << endl;
- cout << "Cost: " << cost << "EUR" << endl;
- }
- };
- class WorkstationPC: public PC
- {
- public:
- WorkstationPC(string _model) : PC(model, "Linux", 8, 1, 6, 4, 16, 2048, 1600, 0, 0)
- {
- this->model = _model;
- }
- void Upgrade(string line)
- {
- string tempcpu, tempTotalRamSlots, tempgbPerRam, tempgpu, tempafterb, del = " ";
- stringstream ss;
- int r = 1;
- tempcpu = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempTotalRamSlots = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempgbPerRam = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempgpu = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- tempafterb = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- if(tempcpu != "1" && tempcpu != "2" && tempcpu != "4" && tempcpu != "6" && tempcpu != "8")
- {
- cout << "Error: Wrong CPU cores number." << endl;
- r = 0;
- }
- if(tempTotalRamSlots != "2" && tempTotalRamSlots != "4" && tempTotalRamSlots != "6" && tempTotalRamSlots != "8")
- {
- cout << "Error: Wrong RAM slots number." << endl;
- r = 0;
- }
- if(tempgbPerRam != "2" && tempgbPerRam != "4" && tempgbPerRam != "8" && tempgbPerRam != "16" && tempgbPerRam != "32" && tempgbPerRam != "64" && tempgbPerRam != "128")
- {
- cout << "Error: Wrong GB per RAM number." << endl;
- r = 0;
- }
- if(tempgpu != "0" && tempgpu != "1")
- {
- cout << "Error: Wrong GPU number." << endl;
- r = 0;
- }
- if(tempafterb != "0" && tempafterb != "1")
- {
- cout << "Error: Wrong Afterburner number. 1" << endl;
- r = 0;
- } else if(gpu == 0 && tempafterb == "1")
- {
- cout << "Error: Wrong Afterburner number. 2" << endl;
- r = 0;
- }
- if(r == 1)
- {
- ss.clear();
- ss.str(tempcpu);
- ss >> cpu;
- ss.clear();
- ss.str(tempTotalRamSlots);
- ss >> totalRamSlots;
- ss.clear();
- ss.str(tempgbPerRam);
- ss >> gbPerRam;
- ss.clear();
- ss.str(tempgpu);
- ss >> gpu;
- ss.clear();
- ss.str(tempafterb);
- ss >> afterb;
- }
- }
- void Print()
- {
- cout << "Model: " << model << endl;
- cout << "Operating System: " << operatingSystem << endl;
- cout << "CPU: " << cpu << endl;
- cout << "Motherboard: " << ramSlots << ", " << pcieSlots << endl;
- cout << "RAM: " << totalRamSlots << ", " << gbPerRam << endl;
- cout << "SSD: " << ssd << "GB" << endl;
- cout << "GPU: " << gpu << endl;
- cout << "Afterburner: " << afterb << endl;
- cout << "Cost: " << cost << "EUR" << endl;
- }
- };
- int main()
- {
- string line, cmd, del = " ";
- vector<PC*> pcList;
- int i;
- while(getline(cin, line))
- {
- cmd = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- if(cmd == "new")
- {
- string type, model;
- type = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- model = line.substr(0, line.find(del));
- if(type == "homepc")
- {
- HomePC* homepc = new HomePC(model);
- pcList.push_back(homepc);
- }
- else if(type == "gamingpc")
- {
- GamingPC* gamingpc = new GamingPC(model);
- pcList.push_back(gamingpc);
- }
- else if(type == "workstationpc")
- {
- WorkstationPC* workstationpc = new WorkstationPC(model);
- pcList.push_back(workstationpc);
- }
- } else if(cmd == "upgrade")
- {
- string model;
- model = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- for(i = 0; i < pcList.size(); i++)
- {
- if(pcList[i]->model == model)
- {
- pcList[i]->Upgrade(line);
- }
- }
- } else if(cmd == "delete")
- {
- string model;
- model = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- for(i = 0; i < pcList.size(); i++)
- {
- if(pcList[i]->model == model)
- {
- //pcList[i].erase(pcList.begin(), pcList.end());
- }
- }
- } else if(cmd == "print")
- {
- cout << endl;
- string type;
- type = line.substr(0, line.find(del));
- line.erase(0, line.find(del) + del.length());
- for(i = 0; i < pcList.size(); i++)
- {
- if(type == "homepc")
- {
- if(pcList[i]->operatingSystem == "MacOS")
- pcList[i]->Print();
- } else if(type == "gamingpc")
- {
- if(pcList[i]->operatingSystem == "Windows")
- pcList[i]->Print();
- } else if(type == "workstationpc")
- {
- if(pcList[i]->operatingSystem == "Linux")
- pcList[i]->Print();
- }
- cout << endl;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment