Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. //============================================================================
  2. // Name : Kolos_2.cpp
  3. // Author :
  4. // Version :
  5. // Copyright : Your copyright notice
  6. // Description : Hello World in C++, Ansi-style
  7. //============================================================================
  8.  
  9. #include <iostream>
  10. using namespace std;
  11. class Zad2 {
  12. int x, *tab;
  13. public:
  14. Zad2(int a = 5) :
  15. x(a) {
  16. tab = new int[a];
  17. }
  18. Zad2(char a) :
  19. Zad2() {
  20. cout << "delegacja" << endl;
  21. }
  22. void pobierz_wstaw() {
  23. int y, liczb;
  24. char znak;
  25. do {
  26. cout << "wybierz indeks" << endl;
  27. cin >> y;
  28. cout << "w - wstaw p - pobierz a - zakoncz" << endl;
  29. cin >> znak;
  30. if ((y < 0) || ((x - 1) < y)) {
  31. cout << "przekroczyles wielkosc tablicy" << endl;
  32. } else {
  33.  
  34. switch (znak) {
  35. case ('w'):
  36. cout << "wybierz inta do wstawienia" << endl;
  37. cin >> liczb;
  38. tab[y] = liczb;
  39. cout << tab[y] << endl;
  40. break;
  41. case ('p'):
  42. cout << tab[y] << endl;
  43. break;
  44. default:
  45. break;
  46. }
  47. }
  48. } while (znak != 'a');
  49. }
  50. ~Zad2() {
  51. delete[] tab;
  52. }
  53.  
  54. }
  55. ;
  56. class Zwierze {
  57. public:
  58. virtual void polowanie(int a)=0;
  59. virtual ~Zwierze() {
  60. }
  61. };
  62. class Lew: public Zwierze {
  63. int sila;
  64. public:
  65. virtual void polowanie(int a) {
  66. cout << "uderza lapa" << endl;
  67. }
  68. void uderzLapa() {
  69. polowanie(sila);
  70. }
  71. };
  72. class Lis: public Zwierze {
  73. int spryt;
  74. public:
  75. virtual void polowanie(int a) {
  76. cout << "drapie pazurem" << endl;
  77. }
  78. void Zadraplapa() {
  79. polowanie(spryt);
  80. }
  81. };
  82. class Wilk: public Zwierze {
  83. int szybkosc;
  84. public:
  85. virtual void polowanie(int a) {
  86. cout << "gryzie" << endl;
  87. }
  88. void ugryz() {
  89. polowanie(szybkosc);
  90. }
  91. };
  92. void zad1(int *a) {
  93. cout << "wartosc:";
  94. cout << *a << endl;
  95. cout << "adres:";
  96. cout << a << endl;
  97. cout << "adres wskaznika:";
  98. cout << &a << endl;
  99. *a += 5;
  100. }
  101. int main() {
  102. /*Lew *uderz = new Lew();
  103. uderz->uderzLapa();
  104. Wilk *gryz = new Wilk();
  105. gryz->ugryz();*/
  106. Zad2 *wsk = new Zad2();
  107. wsk->pobierz_wstaw();
  108. delete wsk;
  109. /*int a = 5;
  110. int *wsk = &a;
  111. cout << a << endl;
  112. cout << &a << endl;
  113. cout << &wsk << endl;
  114. zad1(wsk);
  115. cout << a << endl;
  116. return 0;*/
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement