Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by Benc ( 14 years ago )
#include <iostream>

using namespace std;

//Prosta klasa wektora 3d razem z metodami
class vector3d
{
public:
 void Ustaw(float x, float y, float z);
 void Wypisz();

private:
 float x, y, z;
};

void vector3d::Ustaw(float x, float y, float z)
{
 this->x = x;
 this->y = y;
 this->z = z;
}

void vector3d::Wypisz()
{
 cout << "X: " << x << " Y: " << y << " Z: " << z << endl;
}

//Tworzymy wskaźniki które (tak jak w C) przetrzymają adres zaalokowanej pamięci
vector3d* Wektor = 0;
vector3d* TablicaWektorow = 0;

int main()
{
 cout << "Czy chcesz utworzyc wektor?" << endl;

 //Zmienna bool - przyjmuje wartości 0 (false) lub 1 (true)
 bool utworzWektor;

 cin >> utworzWektor;

 if(utworzWektor)
 {
  //ZAJĘCIE MIEJSCA NA OBIEKT "Wektor".
  Wektor = new vector3d;
  Wektor->Ustaw(1.0f, 20.0f, 3.0f);
  Wektor->Wypisz();
  
  //ZAJĘCIE MIEJSCA NA TABLICĘ OBIEKTÓW Z KLASY vector2d
  TablicaWektorow = new vector3d[3];
  TablicaWektorow[0].Ustaw(1.0f, 2.0f, 2.0f);
  TablicaWektorow[1].Ustaw(3.0f, 2.0f, 1.0f);
  TablicaWektorow[2].Ustaw(9.0f, 2.0f, 25.0f);

  for(int i=0; i<3; i++)
  {
   TablicaWektorow[i].Wypisz();
  }
 }

 //PO WYKORZYSTANIU PAMIĘCI - USUWAMY ŚMIECI BO KOMPILATOR ZA NAS TEGO NIE ZROBI
 delete Wektor;
 delete[] TablicaWektorow;

 system&#40;"PAUSE"&#41;;

 return 0;
}

 

Revise this Paste

Your Name: Code Language: