peterzig

[PO] Dziedziczenie

May 9th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.54 KB | None | 0 0
  1. /////////////////////////Cyfra.h/////////////////////////////////////////////////////////
  2. #pragma once
  3. class Cyfra
  4. {
  5.     int cyfra;
  6. public:
  7.     Cyfra(int );
  8.     int const getCyfra() const;
  9.     void Zmien(int);
  10.     void const Wyswietl() const;
  11.  
  12.     ~Cyfra();
  13. };
  14. //////////////////////////Cyfra.cpp///////////////////////////////////////////////////////
  15. #include "Cyfra.h"
  16. #include <iostream>
  17.  
  18. Cyfra::Cyfra(int c)
  19. {
  20.     if (c < 0)
  21.         cyfra = 0;
  22.     else if (c > 9)
  23.         cyfra = 9;
  24.     else
  25.         cyfra = c;
  26. }
  27.  
  28. int const Cyfra::getCyfra() const
  29. {
  30.     return cyfra;
  31. }
  32.  
  33. void Cyfra::Zmien(int c)
  34. {
  35.     if (c < 0)
  36.         cyfra = 0;
  37.     else if (c > 9)
  38.         cyfra = 9;
  39.     else
  40.         cyfra = c;
  41. }
  42.  
  43. void const Cyfra::Wyswietl() const
  44. {
  45.     std::cout << cyfra << " ";
  46. }
  47.  
  48. Cyfra::~Cyfra()
  49. {
  50. }
  51. ////////////////////////CyfraLCD.h////////////////////////////////////////////////////////////////////
  52. #pragma once
  53. #include "Cyfra.h"
  54. class CyfraLCD :public Cyfra
  55. {
  56. public:
  57.     CyfraLCD();
  58.     CyfraLCD(int cyfra);
  59.     void Wyswietl() const;
  60.     ~CyfraLCD();
  61. };
  62.  
  63.  
  64.  
  65.  
  66. //////////////////////////CyfraLCD.cpp////////////////////////////////////////////////////
  67. #include "CyfraLCD.h"
  68. #include <iostream>
  69. using namespace std;
  70.  
  71. CyfraLCD::CyfraLCD() : Cyfra(0)
  72. {  
  73. }
  74.  
  75. CyfraLCD::CyfraLCD(int cyfra) : Cyfra(cyfra)
  76. {  
  77. }
  78.  
  79. void CyfraLCD::Wyswietl() const
  80. {
  81.     switch(getCyfra())
  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. CyfraLCD::~CyfraLCD()
  158. {
  159. }
  160. //////////////////////////CyfraRzymska.h//////////////////////////////////////////////////
  161. #pragma once
  162. #include "Cyfra.h"
  163. class CyfraRzymska :public Cyfra
  164. {
  165.  
  166. public:
  167.     CyfraRzymska();
  168.     CyfraRzymska(int cyfra);
  169.     void Wyswietl();
  170.     ~CyfraRzymska();
  171. };
  172. //////////////////////////CyfraRzymska.cpp////////////////////////////////////////////////
  173. #include "CyfraRzymska.h"
  174. #include <iostream>
  175.  
  176.  
  177. CyfraRzymska::CyfraRzymska() : Cyfra(0)
  178. {  
  179. }
  180.  
  181. CyfraRzymska::CyfraRzymska(int cyfra) : Cyfra(cyfra)
  182. {  
  183. }
  184.  
  185. void CyfraRzymska::Wyswietl()
  186. {
  187.     switch(getCyfra())
  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. CyfraRzymska::~CyfraRzymska()
  213. {
  214. }
  215. ///////////////////////////[PO]Dziedziczenie.cpp///////////////////////////////////
  216.  
  217. #include "stdafx.h"
  218. #include <conio.h>
  219. #include "Cyfra.h"
  220. #include "CyfraRzymska.h"
  221. #include "CyfraLCD.h"
  222.  
  223.  
  224. int main()
  225. {
  226.     Cyfra zero(0);
  227.     Cyfra osiem(8);
  228.     Cyfra piec(5);
  229.     CyfraRzymska jeden(1);
  230.     CyfraRzymska dziewiec(35);
  231.     CyfraLCD trzy(3);
  232.     CyfraLCD zero1(-21);
  233.     CyfraLCD siedem(7);
  234.     zero.Wyswietl();
  235.     osiem.Wyswietl();
  236.     piec.Wyswietl();
  237.     jeden.Wyswietl();
  238.     dziewiec.Wyswietl();
  239.     trzy.Wyswietl();
  240.     zero1.Wyswietl();
  241.     siedem.Wyswietl();
  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