Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function.cpp
- #include<iostream>
- #include<string>
- #include "Header.h"
- void Automate::plusSumMoney()
- {
- cout << "You gave: " << money << " $";
- cout << "Please, give plus " << differntly << "$ for good sales!";
- double h;
- cin >> h;
- this->money += h;
- }
- void Automate::Display::Menuchoice()
- {
- cout << "1.Korona...............5(dollars)" << endl;
- cout << "2.Milka..............12.5(dollars)" << endl;
- cout << "3.Snikers.............4.5(dollars)" << endl;
- cout << "4.Nuts................3.8(dollars)" << endl << endl;
- cout << "Please, make your choice..." << endl << endl;
- }
- void Automate::Display::setMassege(string massege)
- {
- this->massege = massege;
- }
- string Automate::Display::printMassege()
- {
- return this->massege;
- }
- int Automate::getChoise()
- {
- return this->choise;
- }
- double Automate::getMoney()
- {
- return this->money;
- }
- Automate::Automate()
- {
- this->money = 0;
- this->numbersweets = 20;
- this->choise = 0;
- this->differntly = 0;
- }
- Automate::~Automate()
- {
- cout << "keep kalm!";
- }
- void Automate::MenuforYou()
- {
- display.Menuchoice();
- }
- void Automate::printMassege()
- {
- display.printMassege();
- }
- void Automate::getMoneyFromuser(User & user)
- {
- cout << "Пожалуйста внесите кюпюры номиналом 1 2 5 10 или 20 доларов" << endl;
- cout << "Для завершения введите 0" << endl;
- this->setMoney(user.giveMoney());
- }
- void Automate::getChoiseFromUser(User & user)
- {
- cout << "Введите номер товара: "<<endl;
- choise = user.doChoise();
- }
- void Automate::giveSweets(Sweets & sweets, Automate & automate)
- {
- cout << sweets.obgortka(automate);
- }
- bool Automate::checkMoneyPrize()
- {
- switch (this->choise)
- {
- case (1):
- {
- if (money < 5) { plusSumMoney(); }
- else if (money >= 5) { cout << "Оплата прошла успешно!"<<endl; }
- this->differntly = money - 5;
- return true;
- break;
- }
- case (2):
- {
- if (money < 12.5) { plusSumMoney(); }
- else if (money >= 12.5) { cout << "Оплата прошла успешно!"<<endl; }
- this->differntly = money - 12.5;
- return 1;
- break;
- }
- case (3):
- {
- if (money < 4.5) { plusSumMoney(); }
- else if (money >= 4.5) { cout << "Оплата прошла успешно!"<<endl; }
- this->differntly = money - 4.5;
- return 1;
- break;
- }
- case (4):
- {
- if (money < 3.8) plusSumMoney();
- else if (money >= 3.8) cout << "Оплата прошла успешно!"<<endl;
- this->differntly = money - 3.8;
- return 1;
- break;
- }
- default: cout << "Система сломана беги!"; break;
- }
- }
- void Automate::plusSweets()
- {
- if (this->numbersweets <= 3) this->numbersweets += 25;
- }
- void Automate::setMoney(double money)
- {
- this->money = money;
- }
- double Automate::getDifferently()
- {
- return this->differntly;
- }
- Sweets::Sweets()
- {
- this->name = "Chocolate";
- this->price = 20;
- }
- Sweets::~Sweets()
- {
- cout << "I am working";
- }
- void Sweets::setName(string name)
- {
- this->name = name;
- }
- string Sweets::getname()
- {
- return this->name;
- }
- void Sweets::setPrice(double price)
- {
- this->price = price;
- }
- double Sweets::getPrice()
- {
- return price;
- }
- string Sweets::obgortka(Automate & automate)
- {
- if ((automate.getChoise() == 1) && (automate.checkMoneyPrize() == true))
- {
- return "Sweets |>Korona<| Приятного апетита! ";
- }
- else if ((automate.getChoise() == 2) && (automate.checkMoneyPrize() == true))
- {
- return "Sweets |>Milka<| Приятного апетита! ";
- }
- else if ((automate.getChoise() == 3) && (automate.checkMoneyPrize() == true))
- {
- return "Sweets |>Snikers<| Приятного апетита! ";
- }
- else if ((automate.getChoise() == 4) && (automate.checkMoneyPrize() == true))
- {
- return "Sweets |>Nuts<| Приятного апетита! ";
- }
- }
- User::User()
- {
- this->usermoney = 1000;
- this->usersweets = 0;
- this->userchoice = 0;
- }
- User::~User()
- {
- cout << "I am working";
- }
- void User::setUserMoney()
- {
- cout << "Сколько у меня денег???"<<endl;
- cin >> usermoney;
- }
- double User::getUserMoney()
- {
- return this->usermoney;
- }
- void User::setUserSweets(double usersweets)
- {
- this->usersweets = usersweets;
- }
- double User::getUserSweets()
- {
- return this->usersweets;
- }
- double User::giveMoney()
- {
- double summa = 0;
- int k;
- do
- {
- cin >> k;
- if (k == 1 || k == 2 || k == 10 || k == 20 || k == 5)
- {
- this->usermoney -= k;
- summa += k;
- }
- else if (k != 0)
- cout << "Пожалуйста внесите кюпюры номиналом 1 2 5 10 или 20 доларов, попробуйте ещё раз!" << endl;
- } while (k != 0);
- return summa;
- }
- int User::doChoise()
- {
- int g;
- do {
- cin >> g;
- if (g < 1 || g > 4)
- {
- cout << "Неверний ответ! Попробуйте ещё раз!"<<endl;
- }
- } while (g < 1 || g > 4);
- this->userchoice = g;
- return userchoice;
- }
- void User::getSdacha(Automate & automate)
- {
- cout << "Ваша сдача" << automate.getDifferently() << " $. Незабудьте забрать сдачу!"<<endl;
- this->sdacha = automate.getDifferently();
- }
- Header.h
- #include<iostream>
- #include<string>
- using namespace std;
- class Automate;
- class Candy
- {
- protected:
- double price;
- };
- class Sweets : public Candy
- {
- private:
- string name;
- public:
- Sweets();
- ~Sweets();
- void setName(string name);
- string getname();
- void setPrice(double price);
- double getPrice();
- string obgortka(Automate& automate);
- };
- class User
- {
- private:
- double usermoney;
- int usersweets;
- int userchoice;
- double sdacha;
- public:
- User();
- ~User();
- void setUserMoney();
- double getUserMoney();
- void setUserSweets(double usersweets);
- double getUserSweets();
- //void setUserChoice(double userchoice);
- //double getUserChoice();
- double giveMoney();
- int doChoise();
- void getSdacha(Automate& automate);
- };
- class Automate
- {
- private:
- double money;
- double numbersweets;
- int choise;
- double differntly;
- void plusSumMoney();
- class Display
- {
- private:
- string massege;
- public:
- void Menuchoice();
- void setMassege(string massege);
- string printMassege();
- };
- Display display;
- public:
- int getChoise();
- double getMoney();
- Automate();
- ~Automate();
- void MenuforYou();
- void printMassege();
- void getMoneyFromuser(User& user);
- void getChoiseFromUser(User& user);
- bool checkMoneyPrize();
- void giveSweets(Sweets& sweets, Automate& automate);
- void plusSweets();
- void setMoney(double money);
- //double getMoney() { return this->money; }
- double getDifferently();
- };
- source.cpp
- #include<iostream>
- #include<string>
- #include"Header.h"
- int main()
- {
- setlocale(LC_ALL, "ru");
- Automate a;
- Sweets c;
- User u;
- u.setUserMoney();
- a.MenuforYou();
- a.getMoneyFromuser(u);
- a.getChoiseFromUser(u);
- a.checkMoneyPrize();
- c.obgortka(a);
- a.giveSweets(c, a);
- u.getSdacha(a);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement