Advertisement
sdee3

OBP1 - p02

Mar 13th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. //PovecajCharIliInt.h
  2.  
  3. #pragma once
  4. class PovecajCharIliInt {
  5. public:
  6.     void Povecaj(void *pvoid, int velicina);
  7. };
  8.  
  9. //PovecajCharIliInt.cpp
  10.  
  11. #include <iostream>
  12. #include "PovecajCharIliInt.h"
  13.  
  14. using namespace std;
  15.  
  16. void PovecajCharIliInt::Povecaj(void *pvoid, int velicina) {
  17.     if (velicina == sizeof(char)) {
  18.         char *pchar = (char *)pvoid;
  19.         ++(*pchar);
  20.     }
  21.     else if (velicina == sizeof(int)) {
  22.         int *pint = (int *)pvoid;
  23.         ++(*pint);
  24.     }
  25. }
  26.  
  27. //MainProg.cpp
  28.  
  29. #include <iostream>
  30. #include "PovecajCharIliInt.h"
  31.  
  32. using namespace std;
  33.  
  34. int main() {
  35.     PovecajCharIliInt pov;
  36.     char a = 'C'; int b = 1999;
  37.  
  38.     cout << "Pre: a = " << a << "\t" << "b = " << b << endl;
  39.     pov.Povecaj(&a, sizeof(a));
  40.     pov.Povecaj(&b, sizeof(b));
  41.     cout << "Posle: a = " << a << "\t" << "b = " << b << endl;
  42.  
  43.     system("pause");
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement