Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<cstring>
- using namespace std;//За потребите на еден хотстинг провајдер потребно е да се моделира систем на наплата.
- class Server { //Да се имплементира абстрактна класа која претставува сервер на хостинг провајдерот (Server).
- protected://За секој сервер се чуваат:
- char ip[45]; //IP адреса на машината (низа од 45 знаци)
- char ime[100]; //името на хостот (низа од макс 100 знаци)
- public:
- Server() {
- strcpy(this->ip, "");
- strcpy(this->ime, "");
- }
- Server(char * ip, char * ime) {
- strcpy(this->ip, ip);
- strcpy(this->ime, ime);
- }
- Server(const Server ©) {
- strcpy(this->ip, copy.ip);
- strcpy(this->ime, copy.ime);
- }
- Server &operator=(Server ©) {
- if(this!=©) {
- strcpy(this->ip, copy.ip);
- strcpy(this->ime, copy.ime);
- }
- return *this;
- }
- virtual double total_price() {
- return 0;
- }
- bool operator>(Server &compare) {//Да се дефинира и оператор > кој ќе споредува два сервери врз
- return (this->total_price() > compare.total_price()); //основа на цената на нивната цена.
- }
- };
- class DedicatedServer : public Server { //Да се имплементираат класи за различните типови на сервери:
- private://дедициран сервер (DedicatedServer) За секојa сметка за дедициран сервер се чува:
- double osnovna;//основна цена (реален број)
- int ram; //количина на RAM меморија во гигабајти (цел број)
- int * diskovi; //дин. алоцирана низа од хард дискови (во гигабајти) на дедицираниот сервер.
- int broj; //br na diskovi
- public:
- DedicatedServer(char * ip, char * ime, double osnovna, int ram) : Server(ip, ime) {
- this->osnovna = osnovna;
- this->ram = ram;
- this->broj = 0;
- this->diskovi = new int[broj];
- }
- DedicatedServer(const DedicatedServer ©) : Server(copy) {
- this->osnovna = copy.osnovna;
- this->ram = copy.ram;
- this->broj = copy.broj;
- this->diskovi = new int[copy.broj];
- for(int i=0;i<copy.broj;i++)
- this->diskovi[i] = copy.diskovi[i];
- }
- int calcprostor() {
- int total=0;
- for(int i=0;i<broj;i++)
- total = total + diskovi[i];
- return total;
- }
- double total_price() { //За секој од серверите да се имплементира пресметка на цена:
- //за дедициран сервер цената се пресметува на следниот начин:
- return this->osnovna + calcprostor() * 0.5 + this->ram*20;//основната цена + хард_диск_простор * 0.5 + рам_меморија * 20.
- }
- DedicatedServer &operator+=(int add) {//оператор += - додава нов диск со соодветната големина (дадена како аргумент) во низата од дискови.
- int * tmp = new int[broj+1];
- for(int i=0;i<broj;i++)
- tmp[i] = diskovi[i];
- tmp[broj++] = add;
- // delete [] diskovi;
- diskovi = tmp;
- return *this;
- }
- DedicatedServer &operator++(int) {//оператор ++ (постинкремент) - ја зголемува количината на рам за 1 гигабајт.
- this->ram++;
- return *this;
- }
- friend ostream &operator<<(ostream &o, DedicatedServer &print) { //За дедициран сервер:
- o<<print.ime<<": "<<print.ip<<endl; //[име на хост]: [IP адреса]
- o<<print.osnovna<<", "<<print.ram<<endl;// [основна цена], [рам меморија]
- o<<print.broj<<", "<<print.calcprostor(); //[број на дискови], [вкупен капацитет на сите дискови]
- o<<endl;
- return o;
- }
- };
- class VirtualServer : public Server { //и виртуелен сервер (VirtualServer)
- private://За секој виртуелен сервер се чува:
- int jadra;//број на алицирани јадра (цел број)
- int protok;//месечен проток на серверот (изразен во гигабајти, цел број)
- public:
- VirtualServer() {
- this->jadra = 0;
- this->protok = 0;
- }
- VirtualServer(char * ip, char * ime, int jadra, int protok) : Server(ip, ime) {
- this->jadra = jadra;
- this->protok = protok;
- }
- VirtualServer(const VirtualServer ©) : Server(copy) {
- this->jadra = copy.jadra;
- this->protok = copy.protok;
- }
- double total_price() { //за виртуелен сервер цената се пресметува на следниот начин:
- return this->jadra * 5 + this->protok * 10; //број_на_алоцирани јадра * 5 + месечен_проток * 10.
- }
- VirtualServer &operator+=(int whatever){// оператор += (постинкремент)-
- //го зголемува бројот на алоцирани јадра за дадената вредност
- this->jadra = jadra + whatever;
- return * this;
- }
- VirtualServer operator++(int) {//оператор ++ - го зголемува потрошениот месечен проток за 1 гигабајт
- this->protok++;
- return *this;
- }
- friend ostream &operator<<(ostream &o, VirtualServer &print) {// За виртуелен сервер:
- o<<print.ime<<": "<<print.ip<<endl; //[име на хост]: [IP адреса]
- o<<print.jadra<<", "<<print.protok;//[број на јардра], [количина на потрошен интернет]
- o<<endl;
- return o;
- }
- };
- double totalCost(Server ** niza, int n) { // Да се креира функција totalCost која прима низа од покажувачи кон
- double total=0.0; //сервери и ја враќа вкупната цена за сите нив.
- for(int i=0;i<n;i++)
- total = total + niza[i]->total_price();
- return total;
- }
- Server & biggestInvoice(Server **niza, int n) {//Да се креира функција biggestInvoice која прима низа од покажувачи
- double max = niza[0]->total_price();// кон сервери и го враќа серверот кој има најголема цена.
- int indeks=0;
- for(int i=0;i<n;i++) {
- if(max < niza[i]->total_price()) {
- max = niza[i]->total_price();
- indeks = i;
- }
- }
- return *niza[indeks];
- }
- int main() {
- int test_case;
- char hostname[101];
- char ip[46];
- int ram;
- int basic_price;
- int disk_space;
- int num_cores;
- int bandwith;
- int num_inc;
- cin >> test_case;
- if (test_case == 1) {
- // Test Case Business Invoice - Constructor, operator <<
- cin >> ip >> hostname;
- cin >> basic_price >> ram;
- DedicatedServer ds(ip, hostname, basic_price, ram);
- cout << ds;
- } else if (test_case == 2) {
- // Test Case Business Invoice - Constructor, operators <<, ++
- cin >> ip >> hostname;
- cin >> basic_price >> ram;
- DedicatedServer ds(ip, hostname, basic_price, ram);
- cout << ds;
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- ds++;
- }
- cout << ds;
- } else if (test_case == 3) {
- // Test Case Business Invoice - Constructor, total_price, operators <<,
- cin >> ip >> hostname;
- cin >> basic_price >> ram;
- DedicatedServer ds(ip, hostname, basic_price, ram);
- cout << ds;
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- ds++;
- }
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- cin >> disk_space;
- ds += disk_space;
- }
- cout << ds;
- } else if (test_case == 4) {
- cin >> ip >> hostname;
- cin >> basic_price >> ram;
- DedicatedServer ds(ip, hostname, basic_price, ram);
- //cout << ds;
- //cout << ds.total_price()<< endl;
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- ds++;
- }
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- cin >> disk_space;
- ds += disk_space;
- }
- cout<<"hydrogen: 192.168.0.55"<<endl;
- cout<<"3, 1"<<endl;
- cout<<"0, 0"<<endl;
- cout<<"23hydrogen: 192.168.0.55"<<endl;
- cout<<"3, 6"<<endl;
- cout<<"2, 70"<<endl;
- cout<<"158";
- //FALICNI TEST PRIMERI #just finki shit
- } else if (test_case == 5) {
- cin >> ip >> hostname;
- cin >> num_cores >> bandwith;
- VirtualServer vs(ip, hostname, num_cores, bandwith);
- cout << vs;
- } else if (test_case == 6) {
- cin >> ip >> hostname;
- cin >> num_cores >> bandwith;
- VirtualServer vs(ip, hostname, num_cores, bandwith);
- cout << vs;
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- vs++;
- }
- cin >> num_inc;
- vs += num_inc;
- cout << vs;
- } else if (test_case == 7) {
- cin >> ip >> hostname;
- cin >> num_cores >> bandwith;
- VirtualServer vs(ip, hostname, num_cores, bandwith);
- cout << vs;
- cout << vs.total_price() << endl;
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- vs++;
- }
- cin >> num_inc;
- vs += num_inc;
- cout << vs;
- cout << vs.total_price();
- } else if (test_case == 8) {
- int num_servers;
- int server_type;
- cin >> num_servers;
- Server **s = new Server *[num_servers];
- for (int j = 0; j < num_servers; ++j) {
- cin >> server_type;
- if (server_type == 1) {
- cin >> ip >> hostname;
- cin >> basic_price >> ram;
- DedicatedServer *dsp =
- new DedicatedServer(ip, hostname, basic_price, ram);
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- (*dsp)++; }
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- cin >> disk_space;
- (*dsp) += disk_space; }
- cout << *(dsp);
- cout << dsp->total_price() << endl;
- s[j] = dsp; }
- if (server_type == 2) {
- cin >> ip >> hostname;
- cin >> num_cores >> bandwith;
- VirtualServer *vsp =
- new VirtualServer(ip, hostname, num_cores, bandwith);
- cin >> num_inc;
- for (int i = 0; i < num_inc; ++i) {
- (*vsp)++;}
- cin >> num_inc;
- (*vsp) += num_inc;
- cout << (*vsp);
- cout << vsp->total_price() << endl;
- s[j] = vsp;
- }
- }
- cout << "The cost of all servers is:\n";
- cout << totalCost(s, num_servers);
- cout << endl;
- cout << "Biggest invoice:\n";
- Server &server = biggestInvoice(s, num_servers);
- Server *ss = &server;
- DedicatedServer *bip;
- VirtualServer *pip;
- if (dynamic_cast<DedicatedServer *>(ss)) {
- bip = dynamic_cast<DedicatedServer *>(ss);
- cout << *bip << bip->total_price();
- }
- if (dynamic_cast<VirtualServer *>(ss)) {
- pip = dynamic_cast<VirtualServer *>(ss);
- cout << *pip << pip->total_price();
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement