fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4.  
  5. class Sparschwein{
  6.  
  7. int inhalt = 0;
  8. int muenzen[3] {0, 0, 0};
  9.  
  10. public:
  11. Sparschwein();
  12. Sparschwein(int coin);
  13. Sparschwein(int firstCoin, int secondCoin, int thirdCoin);
  14. void print();
  15. void einwerfen(int firstCoin, int secondCoind, int thirdCoin);
  16. void leeren();
  17.  
  18. private:
  19. void einwerfen(int coin);
  20.  
  21. };
  22.  
  23. Sparschwein::Sparschwein()
  24. {
  25. this->inhalt = 0;
  26. }
  27.  
  28. Sparschwein::Sparschwein(int coin)
  29. {
  30. this->einwerfen(coin, 0, 0);
  31. }
  32.  
  33. Sparschwein::Sparschwein(int firstCoin, int secondCoin, int thirdCoin)
  34. {
  35. this->einwerfen(firstCoin, secondCoin, thirdCoin);
  36. }
  37.  
  38. void Sparschwein::print()
  39. {
  40. cout << this->muenzen[0] << "x1cent + " << this->muenzen[1] << "x5 cent + " << this->muenzen[2] << "x10cent = " << this->inhalt << " cent" << endl;
  41. }
  42.  
  43. void Sparschwein::einwerfen(int firstCoin, int secondCoin, int thirdCoin) {
  44. this->muenzen[0] += firstCoin;
  45. this->muenzen[1] += secondCoin;
  46. this->muenzen[2] += thirdCoin;
  47.  
  48. this->inhalt += (firstCoin) + (secondCoin * 5) + (thirdCoin * 10);
  49. }
  50.  
  51. void Sparschwein::leeren() {
  52. this->inhalt = 0;
  53. this->muenzen[0] = 0;
  54. this->muenzen[1] = 0;
  55. this->muenzen[2] = 0;
  56. }
  57.  
  58.  
  59. int main () {
  60.  
  61. Sparschwein a;
  62. a.print();
  63.  
  64. Sparschwein b = 10;
  65. b.print();
  66.  
  67. Sparschwein c(47, 11, 42);
  68. c.print();
  69.  
  70. Sparschwein d;
  71. d.einwerfen(0, 8, 15);
  72. d.print();
  73.  
  74. d.leeren();
  75. d.print();
  76.  
  77.  
  78. return 0;
  79. }
  80.  
  81.  
Success #stdin #stdout 0s 3456KB
stdin
Standard input is empty
stdout
0x1cent + 0x5 cent + 0x10cent = 0 cent
10x1cent + 0x5 cent + 0x10cent = 10 cent
47x1cent + 11x5 cent + 42x10cent = 522 cent
0x1cent + 8x5 cent + 15x10cent = 190 cent
0x1cent + 0x5 cent + 0x10cent = 0 cent