Guest User

Untitled

a guest
Dec 10th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. #include "stdafx.h"
  2. #include <memory.h>
  3.  
  4. int apole1[10]={2,4,6,8,10,12,14,16,25,37};
  5. int apole2[9]={2,4,6,8,10,12,14,16,25};
  6. int apole3[4]={2,4,6,8};
  7. //1. Vytvořte třídu Cisla, která konstruktorem jakékoliv integer pole
  8. //různého počtu prvků a poskytne sumu prvků
  9. //2. Vytvořte funkci která poskytne prvek daný indexem
  10. //3. Vytvořte funkci srovnává dvě pole
  11.  
  12. class Cisla{
  13. public:
  14. Cisla(const int* pPole,int iVelikost)
  15. { //vysvetlit obsah zavorky--> neco zjistovani velikost pole
  16. //podle poctu prvku a dat.typu
  17. m_pPole=new int [iVelikost/sizeof(int)];//kde je new tak musi nekde
  18. //byt destruktor
  19. //kopirovani zdrovojeho pole do atributu
  20. m_iVelikostPole = iVelikost;
  21. memset(m_pPole,0,iVelikost);
  22. memcpy(m_pPole,pPole,iVelikost);
  23.  
  24. }
  25.  
  26. //destruktor
  27. ~Cisla(){
  28. if(m_pPole)
  29. delete[] m_pPole;
  30. }
  31.  
  32.  
  33.  
  34.  
  35. int Sum() const //nezmeni se hodnota zadneho atribtu tridy
  36. {
  37. if(m_pPole==0)
  38. return 0;
  39. //vypocet sumy
  40. }
  41.  
  42. int Get(int index) const{
  43. return *(m_pPole+index);
  44. }
  45.  
  46. bool GetReference(int index,int &ref) const{
  47. if((index >= 0 )&& (index < (m_iVelikostPole/sizeof(int))))
  48. {
  49. ref = *(m_pPole+index);
  50. return true;
  51. }
  52. return false;
  53. }
  54. int * GetPointer(int index)
  55. {
  56. if((index >= 0 )&& (index < (m_iVelikostPole/sizeof(int))))
  57. {
  58. return (m_pPole+index);
  59.  
  60. }
  61. return 0;
  62. }
  63. protected:
  64. int* m_pPole;
  65. int m_iVelikostPole;
  66. };
  67.  
  68.  
  69.  
  70.  
  71. int _tmain(int argc, _TCHAR* argv[])
  72. {
  73. Cisla inst1(apole1, 16);
  74. Cisla inst2(apole2, 36);
  75. int cislo = 0;
  76. if(inst1.GetReference(1,cislo) == false)
  77. {
  78. cislo = 100;
  79. }
  80. int * uk_cislo = inst1.GetPointer(2);
  81. if(uk_cislo==0){
  82. return 0;
  83. }
  84. int iv = inst1.Get(1);
  85. return 0;
  86. }
Add Comment
Please, Sign In to add comment