Sa implemeteze clasa Punct3D ce deriva din clasa Punct2D.
1 #include <iostream> #include <conio.h> using namespace std; class Punct2D{ 5 protected: float x; float y; public: Punct2D(float x=0 , float y=0){ 10 this -> x = x; this -> y = y; cout<<"Constructor Punct2D"<<endl; } ~Punct2D(){ 15 cout<<"Destructor Punct2D"<<endl; } float getX(){ return x; } 20 void setX(float x){ this -> x = x; } float getY(){ return y; 25 } void setY(float y){ this -> y = y; } void print(){ 30 cout<<"("<<x<<","<<y<<")"; } }; class Punct3D: public Punct2D { 35 protected: float z; public: Punct3D(float x=0 , float y=0, float z=0):Punct2D(x,y){ this -> z = z; 40 cout<<"Constructor Punct3D"<<endl; } ~Punct3D(){ cout<<"Destructor Punct3D"<<endl; } 45 float getZ(){ return z; } void setZ(float z){ 50 this -> z = z; } void print(){ cout<<"("<<x<<","<<y<<","<<z<<")"; } 55 }; int main(){ Punct3D p(2,3,7); 60 cout<<"x="<<p.getX()<<endl; cout<<"y="<<p.getY()<<endl; cout<<"z="<<p.getZ()<<endl; p.print(); cout<<endl; 65 p.Punct2D::print(); cout<<endl; getch(); }