Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Money.h
- #ifndef _MONEY_H_
- #define _MONEY_H_
- typedef double lf;
- class Money
- {
- public:
- virtual ~Money() = 0;
- virtual lf get_money() = 0;
- virtual void set_money(lf) = 0;
- virtual lf del() = 0;
- void add(Money*);
- };
- class Ruble : public Money
- {
- public:
- ~Ruble() override;
- lf get_money() override;
- void set_money(lf) override;
- lf del() override;
- private:
- lf currency = 1;
- lf collect;
- };
- class Dollar : public Money
- {
- public:
- ~Dollar() override;
- lf get_money() override;
- void set_money(lf) override;
- lf del() override;
- private:
- lf currency = 69.29;
- lf collect;
- };
- class Euro : public Money
- {
- public:
- ~Euro() override;
- lf get_money() override;
- void set_money(lf) override;
- lf del() override;
- private:
- lf currency = 77.84;
- lf collect;
- };
- #endif//_MONEY_H_
- //Money.cpp
- #include "Money.h"
- lf Ruble::get_money()
- {
- const lf get = collect;
- return get;
- }
- void Ruble::set_money( const lf set )
- {
- collect = set;
- }
- lf Ruble::del()
- {
- return currency;
- }
- Ruble::~Ruble() = default;
- lf Dollar::get_money()
- {
- const lf get = collect;
- return get;
- }
- void Dollar::set_money( const lf set )
- {
- collect = set;
- }
- lf Dollar::del()
- {
- return currency;
- }
- Dollar::~Dollar() = default;
- lf Euro::get_money()
- {
- const lf get = collect;
- return get;
- }
- void Euro::set_money( const lf set )
- {
- collect = set;
- }
- lf Euro::del()
- {
- return currency;
- }
- Euro::~Euro() = default;
- Money::~Money() = default;
- void Money::add(Money* a)
- {
- set_money(a -> get_money() * a -> del() / del() + get_money());
- }
- //main.cpp
- #include "Money.h"
- #include <cstdio>
- int main()
- {
- Ruble r;
- Dollar d;
- Euro e;
- lf rub = 0, dol = 0, ero = 0;
- int choice = 0;
- std::printf("The amount of rubles: ");
- std::scanf("%lf", &rub);
- r.set_money(rub);
- std::printf("The amount of dollars: ");
- std::scanf("%lf", &dol);
- d.set_money(dol);
- std::printf("The amount of euro: ");
- std::scanf("%lf", &ero);
- e.set_money(ero);
- do
- {
- std::printf("Transfer to a single currency Select 1) RUBLE 2) DOLLAR 3) EURO: ");
- std::scanf("%d", &choice);
- if(choice > 3) std::printf("Incorrect input\n");
- }
- while(choice > 3);
- switch (choice)
- {
- case 1:
- r.add(&d);
- r.add(&e);
- std::printf("%lf rubles", r.get_money());
- break;
- case 2:
- d.add(&r);
- d.add(&e);
- std::printf("%lf dollars", d.get_money());
- break;
- default:
- e.add(&r);
- e.add(&d);
- std::printf("%lf euros", e.get_money());
- break;
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment