Advertisement
Koelion

c++

Apr 24th, 2015
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 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.  
  65. int main()
  66. {
  67. //zad1
  68. char* Tab1 = new char[10];
  69. cin >> setw(9) >> Tab1;
  70. cin.ignore();
  71.  
  72. //Zad2
  73. cin.getline(inputData, 99);
  74. char* Tab2 = new char[strlen(inputData)+1];
  75. strcpy(Tab2, inputData);
  76.  
  77. //Zad3
  78. //ZZZZ
  79.  
  80. //Zad4
  81. int Jump = 1024;
  82. for (int Size = Jump; ;Size += Jump)
  83. {
  84. try
  85. {
  86. char* buf = new char[Size];
  87. delete [] buf;
  88. }
  89. catch(bad_alloc)
  90. {
  91. cout << Size << endl;
  92. break;
  93. }
  94. }
  95. //Zad5
  96. char Imie[64];
  97. int Wiek;
  98. bool Plec;
  99. cin >> setw(63) >> Imie;
  100. cin >> Wiek;
  101. cin >> Plec;
  102. Osoba os(Imie, Wiek, Plec);
  103. cout << sizeof(os) << " " << &os << " " << os.Imie << " " << os.Wiek << " " << os.Plec << endl;
  104.  
  105. //zad7
  106. int** TabLiczby = new int*[3];
  107. for(int i=0;i<3; i++)
  108. TabLiczby[i] = new int[2];
  109.  
  110. TabLiczby[0][0] = 1;
  111. TabLiczby[0][1] = 2;
  112. TabLiczby[1][0] = 3;
  113. TabLiczby[1][1] = 4;
  114. TabLiczby[2][0] = 5;
  115. TabLiczby[2][1] = 6;
  116.  
  117. int (*ptrFun1)(int, int) = &mul;
  118. int (*ptrFun2)(int, int) = &dif;
  119.  
  120. int (*tabFunPtr[6])(int, int) ={
  121. &mul,
  122. &dif,
  123. &sum,
  124. &sub,
  125. ptrFun1,
  126. ptrFun2
  127. };
  128.  
  129. funCall(TabLiczby, 3, tabFunPtr, 6);
  130.  
  131.  
  132.  
  133. getchar();
  134. cin.ignore();
  135.  
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement