Programacion Orientada a Objetos

Saturday, December 03, 2005

Perímetro y área de un Rectángulo con Clases

#include
#include

class Rectangulo{
private:
float longitud,ancho,per,ar;
public:
Rectangulo(float =1,float=1,float =1,float=1);
void perimetro(void);
void area(void);
void establecer();
};

Rectangulo::Rectangulo(float ll,float aa,float pp,float arr){
longitud=ll;
ancho=aa;
per=pp;
ar=arr;
}

void Rectangulo::establecer(void){
float xl,xan;
cout<<"\n\nValor de altura: "; cin>>xl;
if(xl<=0 xl>=20)
cout<<"El valor esta fuera del rango"< else
longitud=xl;

cout<<"Valor de base: "; cin>>xan;
if(xan<=0 xan>=20)
cout<<"El valor esta fuera del rango"< else
ancho=xan;
}

void Rectangulo::perimetro(void){
per = longitud*2+ancho*2;
}

void Rectangulo::area(void){
ar = longitud*ancho;
cout<<"\nEl perimetro: "< cout<<"El area: "< }

main(){
Rectangulo a,b,c;
a.establecer();
a.perimetro();
a.area();
b.establecer();
b.perimetro();
b.area();
c.establecer();
c.perimetro();
c.area();
getch();
}

0 Comments:

Post a Comment

<< Home