peterzig

[C++] Multiple Inheritance for Chi Jack

Oct 13th, 2020
2,043
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.61 KB | None | 0 0
  1. /////////////////////////Numeral.h/////////////////////////////////////////////////////////
  2. #pragma once
  3. class Numeral
  4. {
  5.     int Numeral;
  6. public:
  7.     Numeral(int );
  8.     int const getNumeral() const;
  9.     void Swap(int);
  10.     void const Print() const;
  11.  
  12.     ~Numeral();
  13. };
  14. //////////////////////////Numeral.cpp///////////////////////////////////////////////////////
  15. #include "Numeral.h"
  16. #include <iostream>
  17.  
  18. Numeral::Numeral(int c)
  19. {
  20.     if (c < 0)
  21.         Numeral = 0;
  22.     else if (c > 9)
  23.         Numeral = 9;
  24.     else
  25.         Numeral = c;
  26. }
  27.  
  28. int const Numeral::getNumeral() const
  29. {
  30.     return Numeral;
  31. }
  32.  
  33. void Numeral::Swap(int c)
  34. {
  35.     if (c < 0)
  36.         Numeral = 0;
  37.     else if (c > 9)
  38.         Numeral = 9;
  39.     else
  40.         Numeral = c;
  41. }
  42.  
  43. void const Numeral::Print() const
  44. {
  45.     std::cout << Numeral << " ";
  46. }
  47.  
  48. Numeral::~Numeral()
  49. {
  50. }
  51. ////////////////////////NumeralLCD.h////////////////////////////////////////////////////////////////////
  52. #pragma once
  53. #include "Numeral.h"
  54. class NumeralLCD :public Numeral
  55. {
  56. public:
  57.     NumeralLCD();
  58.     NumeralLCD(int Numeral);
  59.     void Print() const;
  60.     ~NumeralLCD();
  61. };
  62.  
  63.  
  64.  
  65.  
  66. //////////////////////////NumeralLCD.cpp////////////////////////////////////////////////////
  67. #include "NumeralLCD.h"
  68. #include <iostream>
  69. using namespace std;
  70.  
  71. NumeralLCD::NumeralLCD() : Numeral(0)
  72. {  
  73. }
  74.  
  75. NumeralLCD::NumeralLCD(int Numeral) : Numeral(Numeral)
  76. {  
  77. }
  78.  
  79. void NumeralLCD::Print() const
  80. {
  81.     switch(getNumeral())
  82.     {
  83.     case 0: std::cout << endl
  84.         << "   ##   " << std::endl
  85.         << "  #  #  " << endl
  86.         << "  #  #  " << endl
  87.         << "  #  #  " << endl
  88.         << "   ##   ";
  89.         break;
  90.     case 1: std::cout << endl
  91.         << "    ##   " << std::endl
  92.         << "   # #  " << endl
  93.         << "  #  #  " << endl
  94.         << "     #   " << endl
  95.         << "     #   ";
  96.         break;
  97.     case 2: std::cout << endl
  98.         << "   ##   " << std::endl
  99.         << "  #  #  " << endl
  100.         << "    #   " << endl
  101.         << "   #    " << endl
  102.         << "  ####  ";
  103.         break;
  104.     case 3: std::cout << endl
  105.         << "   ##   " << std::endl
  106.         << "  #  #  " << endl
  107.         << "   ###  " << endl
  108.         << "  #  #  " << endl
  109.         << "   ##   ";
  110.         break;
  111.     case 4: std::cout << endl
  112.         << "  #  #  " << std::endl
  113.         << "  #  #  " << endl
  114.         << "  ####  " << endl
  115.         << "     #  " << endl
  116.         << "     #  ";
  117.         break;
  118.     case 5: std::cout << endl
  119.         << "  ####  " << std::endl
  120.         << "  #     " << endl
  121.         << "   ###  " << endl
  122.         << "  #  #  " << endl
  123.         << "   ##   ";
  124.         break;
  125.     case 6: std::cout << endl
  126.         << "   ##   " << std::endl
  127.         << "  #    " << endl
  128.         << "  ###   " << endl
  129.         << "  #  #  " << endl
  130.         << "   ##   ";
  131.         break;                  1
  132. case 7: std::cout << endl
  133.         << "  ##### " << std::endl
  134.         << "     #  " << endl
  135.         << "   ###  " << endl
  136.         << "   #    " << endl
  137.         << "  #     ";
  138.         break;
  139.     case 8: std::cout << endl
  140.         << "   ###  " << std::endl
  141.         << "  #   # " << endl
  142.         << "   ###  " << endl
  143.         << "  #   # " << endl
  144.         << "   ###  ";
  145.         break;
  146.     case 9: std::cout << endl
  147.         << "   ##   " << std::endl
  148.         << "  #  #  " << endl
  149.         << "  ####  " << endl
  150.         << "     #  " << endl
  151.         << "   ##   ";
  152.         break;
  153.     }
  154. }
  155.  
  156.  
  157. NumeralLCD::~NumeralLCD()
  158. {
  159. }
  160. //////////////////////////NumeralRoman.h//////////////////////////////////////////////////
  161. #pragma once
  162. #include "Numeral.h"
  163. class NumeralRoman :public Numeral
  164. {
  165.  
  166. public:
  167.     NumeralRoman();
  168.     NumeralRoman(int Numeral);
  169.     void Print();
  170.     ~NumeralRoman();
  171. };
  172. //////////////////////////NumeralRoman.cpp////////////////////////////////////////////////
  173. #include "NumeralRoman.h"
  174. #include <iostream>
  175.  
  176.  
  177. NumeralRoman::NumeralRoman() : Numeral(0)
  178. {  
  179. }
  180.  
  181. NumeralRoman::NumeralRoman(int Numeral) : Numeral(Numeral)
  182. {  
  183. }
  184.  
  185. void NumeralRoman::Print()
  186. {
  187.     switch(getNumeral())
  188.     {
  189.     case 0: std::cout << " ";
  190.         break;
  191.     case 1: std::cout << "I ";
  192.         break;
  193.     case 2: std::cout << "II ";
  194.         break;
  195.     case 3: std::cout << "III";
  196.         break;
  197.     case 4: std::cout << "IV ";
  198.         break;
  199.     case 5: std::cout << "V ";
  200.         break;
  201.     case 6: std::cout << "VI ";
  202.         break;
  203.     case 7: std::cout << "VII ";
  204.         break;
  205.     case 8: std::cout << "VIII ";
  206.         break;
  207.     case 9: std::cout << "IX ";
  208.         break;
  209.     }
  210. }
  211.  
  212. NumeralRoman::~NumeralRoman()
  213. {
  214. }
  215. ///////////////////////////Multiple_Inheritance.cpp///////////////////////////////////
  216.  
  217. #include "stdafx.h"
  218. #include <conio.h>
  219. #include "Numeral.h"
  220. #include "NumeralRoman.h"
  221. #include "NumeralLCD.h"
  222.  
  223.  
  224. int main()
  225. {
  226.     Numeral zero(0);
  227.     Numeral eight(8);
  228.     Numeral five(5);
  229.     NumeralRoman one(1);
  230.     NumeralRoman nine(35);
  231.     NumeralLCD three(3);
  232.     NumeralLCD zero1(-21);
  233.     NumeralLCD seven(7);
  234.     zero.Print();
  235.     eight.Print();
  236.     five.Print();
  237.     one.Print();
  238.     nine.Print();
  239.     three.Print();
  240.     zero1.Print();
  241.     seven.Print();
  242.  
  243.     _getch();
  244.  
  245.     return 0;
  246. }
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.                                     2
Advertisement
Add Comment
Please, Sign In to add comment