paranid5

Money

Jun 25th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.52 KB | None | 0 0
  1. //Money.h
  2.  
  3. #ifndef _MONEY_H_
  4. #define _MONEY_H_
  5.  
  6. typedef double lf;
  7.  
  8. class Money
  9. {
  10.  public:
  11.     virtual ~Money()                   = 0;
  12.     virtual lf get_money()             = 0;
  13.     virtual void set_money(lf)         = 0;
  14.     virtual lf del()                   = 0;
  15.     void add(Money*);
  16. };
  17.  
  18. class Ruble : public Money
  19. {
  20.  public:
  21.     ~Ruble()                   override;
  22.     lf get_money()             override;
  23.     void set_money(lf)         override;
  24.     lf del()                   override;
  25.    
  26.  
  27.  private:
  28.     lf currency = 1;
  29.     lf collect;
  30. };
  31.  
  32. class Dollar : public Money
  33. {
  34.  public:
  35.     ~Dollar()                  override;
  36.     lf get_money()             override;
  37.     void set_money(lf)         override;
  38.     lf del()                   override;
  39.    
  40.  
  41.  private:
  42.     lf currency = 69.29;
  43.     lf collect;
  44. };
  45.  
  46. class Euro : public Money
  47. {
  48.  public:
  49.     ~Euro()                    override;
  50.     lf get_money()             override;
  51.     void set_money(lf)         override;
  52.     lf del()                   override;
  53.    
  54.  
  55.  private:
  56.     lf currency = 77.84;
  57.     lf collect;
  58. };
  59.  
  60. #endif//_MONEY_H_
  61.  
  62.  
  63.  
  64. //Money.cpp
  65.  
  66. #include "Money.h"
  67.  
  68. lf Ruble::get_money()
  69. {
  70.     const lf get = collect;
  71.     return get;
  72. }
  73.  
  74. void Ruble::set_money( const lf set )
  75. {
  76.     collect = set;
  77. }
  78.  
  79. lf Ruble::del()
  80. {
  81.     return currency;
  82. }
  83.  
  84. Ruble::~Ruble() = default;
  85.  
  86.  
  87.  
  88. lf Dollar::get_money()
  89. {
  90.     const lf get = collect;
  91.     return get;
  92. }
  93.  
  94. void Dollar::set_money( const lf set )
  95. {
  96.     collect = set;
  97. }
  98.  
  99. lf Dollar::del()
  100. {
  101.     return currency;
  102. }
  103.  
  104. Dollar::~Dollar() = default;
  105.  
  106.  
  107.  
  108. lf Euro::get_money()
  109. {
  110.     const lf get = collect;
  111.     return get;
  112. }
  113.  
  114. void Euro::set_money( const lf set )
  115. {
  116.     collect = set;
  117. }
  118.  
  119. lf Euro::del()
  120. {
  121.     return currency;
  122. }
  123.  
  124. Euro::~Euro() = default;
  125.  
  126.  
  127.  
  128. Money::~Money() = default;
  129.  
  130. void Money::add(Money* a)
  131. {
  132.     set_money(a -> get_money() * a -> del() / del() + get_money());
  133. }
  134.  
  135.  
  136.  
  137.  
  138. //main.cpp
  139.  
  140. #include "Money.h"
  141. #include <cstdio>
  142.  
  143. int main()
  144. {
  145.     Ruble r;
  146.     Dollar d;
  147.     Euro e;
  148.     lf rub = 0, dol = 0, ero = 0;
  149.     int choice = 0;
  150.     std::printf("The amount of rubles: ");
  151.     std::scanf("%lf", &rub);
  152.     r.set_money(rub);
  153.     std::printf("The amount of dollars: ");
  154.     std::scanf("%lf", &dol);
  155.     d.set_money(dol);
  156.     std::printf("The amount of euro: ");
  157.     std::scanf("%lf", &ero);
  158.     e.set_money(ero);
  159.     do
  160.     {
  161.         std::printf("Transfer to a single currency Select 1) RUBLE 2) DOLLAR 3) EURO: ");
  162.         std::scanf("%d", &choice);
  163.         if(choice > 3) std::printf("Incorrect input\n");
  164.     }
  165.     while(choice > 3);
  166.     switch (choice)
  167.     {
  168.     case 1:
  169.         r.add(&d);
  170.         r.add(&e);
  171.         std::printf("%lf rubles", r.get_money());
  172.         break;
  173.     case 2:
  174.         d.add(&r);
  175.         d.add(&e);
  176.         std::printf("%lf dollars", d.get_money());
  177.         break;
  178.     default:
  179.         e.add(&r);
  180.         e.add(&d);
  181.         std::printf("%lf euros", e.get_money());
  182.         break;
  183.     }
  184.     return 0;
  185. }
Add Comment
Please, Sign In to add comment