Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <iomanip>
- using namespace std;
- char inputData[100];
- //Zad5
- struct Osoba
- {
- Osoba(char* Imie, int Wiek, bool Plec)
- {
- this->Imie = new char[strlen(Imie)+1];
- strcpy(this->Imie, Imie);
- this->Wiek = Wiek;
- this->Plec = Plec;
- };
- char* Imie;
- int Wiek;
- bool Plec;
- //Zad6
- void Show()
- {
- cout << Imie << " " << Wiek << " " << Plec << endl;
- };
- };
- //Zad7
- int mul(int x, int y)
- {
- return x*y;
- }
- int dif(int x, int y)
- {
- if(y == 0)
- return 0;
- return x/y;
- }
- int sum(int x, int y)
- {
- return x+y;
- }
- int sub(int x, int y)
- {
- return x-y;
- }
- int funCall(int** NumTab, int NumTabSize, int (*FuncTab[])(int,int), int FuncTabSize)
- {
- for(int i=0; i<NumTabSize; i++)
- {
- for(int j=0; j<FuncTabSize; j++)
- {
- if(FuncTab[j] == &mul || FuncTab[j] == &dif)
- std::cout << FuncTab[j](NumTab[i][0], NumTab[i][1]) << ' ' << std::endl;
- }
- }
- }
- char** Add(char** Source, char** Destination, size_t &Size, int &Index)
- {
- if(Index == Size)
- {
- size_t NewSize = Size * 2;
- char** TempArray = new char*[NewSize];
- for(int i=0; i<Size; i++)
- {
- TempArray[i] = Destination[i];
- }
- Size = NewSize;
- delete [] Destination;
- Destination = TempArray;
- }
- Destination[Index] = *Source;
- Index++;
- return Destination;
- }
- int main()
- {
- /*
- //zad1
- char* Tab1 = new char[10];
- cin >> setw(9) >> Tab1;
- cin.ignore();
- //Zad2
- cin.getline(inputData, 99);
- char* Tab2 = new char[strlen(inputData)+1];
- strcpy(Tab2, inputData);
- //Zad3
- //ZZZZ
- //Zad4
- int Jump = 1024;
- for (int Size = Jump; ;Size += Jump)
- {
- try
- {
- char* buf = new char[Size];
- delete [] buf;
- }
- catch(bad_alloc)
- {
- cout << Size << endl;
- break;
- }
- }
- //Zad5
- char Imie[64];
- int Wiek;
- bool Plec;
- cin >> setw(63) >> Imie;
- cin >> Wiek;
- cin >> Plec;
- Osoba os(Imie, Wiek, Plec);
- cout << sizeof(os) << " " << &os << " " << os.Imie << " " << os.Wiek << " " << os.Plec << endl;
- //zad7
- int** TabLiczby = new int*[3];
- for(int i=0;i<3; i++)
- TabLiczby[i] = new int[2];
- TabLiczby[0][0] = 1;
- TabLiczby[0][1] = 2;
- TabLiczby[1][0] = 3;
- TabLiczby[1][1] = 4;
- TabLiczby[2][0] = 5;
- TabLiczby[2][1] = 6;
- int (*ptrFun1)(int, int) = &mul;
- int (*ptrFun2)(int, int) = &dif;
- int (*tabFunPtr[6])(int, int) ={
- &mul,
- &dif,
- &sum,
- &sub,
- ptrFun1,
- ptrFun2
- };
- funCall(TabLiczby, 3, tabFunPtr, 6);
- */
- //3
- int Index = 2;
- size_t Size = 2;
- char **Tab3 = new char*[Size];
- Tab3[0] = "Ala";
- Tab3[1] = "ma";
- char *Test = "Kota";
- char **Temp3 = Tab3;
- Tab3 = Add(&Test, Temp3, Size, Index);
- delete[] Temp3;
- cout << Tab3[0] << " " << Tab3[1] << " " << Tab3[2] << endl;
- getchar();
- cin.ignore();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement