Advertisement
Koelion

Untitled

Apr 24th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <iomanip>
  4.  
  5. using namespace std;
  6.  
  7. char inputData[100];
  8.  
  9. //Zad5
  10. struct Osoba
  11. {
  12. Osoba(char* Imie, int Wiek, bool Plec)
  13. {
  14. this->Imie = new char[strlen(Imie)+1];
  15. strcpy(this->Imie, Imie);
  16. this->Wiek = Wiek;
  17. this->Plec = Plec;
  18. };
  19. char* Imie;
  20. int Wiek;
  21. bool Plec;
  22.  
  23. //Zad6
  24. void Show()
  25. {
  26. cout << Imie << " " << Wiek << " " << Plec << endl;
  27. };
  28. };
  29.  
  30.  
  31. //Zad7
  32. int mul(int x, int y)
  33. {
  34. return x*y;
  35. }
  36. int dif(int x, int y)
  37. {
  38. if(y == 0)
  39. return 0;
  40. return x/y;
  41. }
  42. int sum(int x, int y)
  43. {
  44. return x+y;
  45. }
  46. int sub(int x, int y)
  47. {
  48. return x-y;
  49. }
  50.  
  51. int funCall(int** NumTab, int NumTabSize, int (*FuncTab[])(int,int), int FuncTabSize)
  52. {
  53. for(int i=0; i<NumTabSize; i++)
  54. {
  55. for(int j=0; j<FuncTabSize; j++)
  56. {
  57. if(FuncTab[j] == &mul || FuncTab[j] == &dif)
  58. std::cout << FuncTab[j](NumTab[i][0], NumTab[i][1]) << ' ' << std::endl;
  59. }
  60. }
  61. }
  62.  
  63.  
  64. char** Add(char** Source, char** Destination, size_t &Size, int &Index)
  65. {
  66. if(Index == Size)
  67. {
  68. size_t NewSize = Size * 2;
  69. char** TempArray = new char*[NewSize];
  70.  
  71. for(int i=0; i<Size; i++)
  72. {
  73. TempArray[i] = Destination[i];
  74. }
  75.  
  76. Size = NewSize;
  77. delete [] Destination;
  78. Destination = TempArray;
  79. }
  80. Destination[Index] = *Source;
  81. Index++;
  82.  
  83. return Destination;
  84. }
  85.  
  86.  
  87. int main()
  88. {
  89. /*
  90. //zad1
  91. char* Tab1 = new char[10];
  92. cin >> setw(9) >> Tab1;
  93. cin.ignore();
  94.  
  95. //Zad2
  96. cin.getline(inputData, 99);
  97. char* Tab2 = new char[strlen(inputData)+1];
  98. strcpy(Tab2, inputData);
  99.  
  100. //Zad3
  101. //ZZZZ
  102.  
  103. //Zad4
  104. int Jump = 1024;
  105. for (int Size = Jump; ;Size += Jump)
  106. {
  107. try
  108. {
  109. char* buf = new char[Size];
  110. delete [] buf;
  111. }
  112. catch(bad_alloc)
  113. {
  114. cout << Size << endl;
  115. break;
  116. }
  117. }
  118. //Zad5
  119. char Imie[64];
  120. int Wiek;
  121. bool Plec;
  122. cin >> setw(63) >> Imie;
  123. cin >> Wiek;
  124. cin >> Plec;
  125. Osoba os(Imie, Wiek, Plec);
  126. cout << sizeof(os) << " " << &os << " " << os.Imie << " " << os.Wiek << " " << os.Plec << endl;
  127.  
  128. //zad7
  129. int** TabLiczby = new int*[3];
  130. for(int i=0;i<3; i++)
  131. TabLiczby[i] = new int[2];
  132.  
  133. TabLiczby[0][0] = 1;
  134. TabLiczby[0][1] = 2;
  135. TabLiczby[1][0] = 3;
  136. TabLiczby[1][1] = 4;
  137. TabLiczby[2][0] = 5;
  138. TabLiczby[2][1] = 6;
  139.  
  140. int (*ptrFun1)(int, int) = &mul;
  141. int (*ptrFun2)(int, int) = &dif;
  142.  
  143. int (*tabFunPtr[6])(int, int) ={
  144. &mul,
  145. &dif,
  146. &sum,
  147. &sub,
  148. ptrFun1,
  149. ptrFun2
  150. };
  151.  
  152. funCall(TabLiczby, 3, tabFunPtr, 6);
  153.  
  154.  
  155. */
  156.  
  157.  
  158.  
  159. //3
  160. int Index = 2;
  161. size_t Size = 2;
  162. char **Tab3 = new char*[Size];
  163. Tab3[0] = "Ala";
  164. Tab3[1] = "ma";
  165. char *Test = "Kota";
  166.  
  167. char **Temp3 = Tab3;
  168. Tab3 = Add(&Test, Temp3, Size, Index);
  169. delete[] Temp3;
  170.  
  171.  
  172. cout << Tab3[0] << " " << Tab3[1] << " " << Tab3[2] << endl;
  173.  
  174.  
  175.  
  176. getchar();
  177. cin.ignore();
  178.  
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement