Conan
Moderator
 Inregistrat: acum 17 ani
Postari: 198
|
|
/* sa se implementeze clasa dreptunghi cu lungime, latime, constructor implicit, constr cu param. def fct friend pe calcul ari si perimetru*/
#include <iostream.h> #include <conio.h>
class drept { private: int l,L; public: drept(); drept(int nr1, int nr2); int getl(); int getL(); friend int perimetru(drept& d); friend int arie(drept& d); };
drept::drept() { l=0;L=0; }
drept::drept(int nr1,int nr2) { l=nr1;L=nr2; }
int drept::getl() { return l; }
int drept::getL() { return L; }
int perimetru(drept& d) { return 2*(d.getl()+d.getL()); }
int arie(drept& d) { return d.getl()*d.getL(); }
void main() { clrscr(); drept d(5,10); cout<<"Arie "<<arie(d)<<" perimetru "<<perimetru(d); getch(); }
|
|