c Programación de ejercicios 1. Defina e implemente una clase de números complejos ClsComplex y complete los siguientes requisitos funcionales:
Pregunta 1.?#includelt;iostreamgt;
usando?namespace?std;
clase?ClsComplex{
privado:
doble?real;
doble?img;
público:
ClsComplex(){
real? =?0;
img?=?0;
}
ClsComplex(doble?r, ?doble?i){
real?=?r;
img?=?i;
}
void?show(){
coutlt ; lt;reallt;lt;'?'lt;lt;imglt;lt;endl;
}
}; Segunda pregunta: #includelt;iostreamgt;
usando?namespace?std;
clase?ClsComplex{
privado:
doble?real;
doble?img ;
público:
ClsComplex(){
real?=?0;
img?=?0;
}
ClsComplex(doble?r, ?doble?i){
real?=?r
img?=?i; p>
}
void?show(){
coutlt;lt;reallt;lt;'?'lt;lt;imglt;lt;endl;
}
amigo?doble?abs(ClsComplex?a,?ClsComplex?b);
};
doble?abs( ClsComplex? a?,?ClsComplex?b){
return?sqrt((a.real?-?b.real)*(a.real-b.real)? ?(a.img? -? b.img)?*(a.img?-?b.img));
}
void?main(){
ClsComplex ?c1 ,?c2(3,4);
coutlt;lt;abs(c1,?c2);
}
La tercera pregunta:
#includelt;iostreamgt;
usando?namespace?std;
clase?Shape{
público:
virtual ?float?peri()=0;?
};
clase?Rect: pública?Shape{
privada:
float?width;
float?length;
público:
float?peri(){
return?2* (ancho ?l
longitud);
}
Rect(float?w, ?float?l){
ancho?=?w; length?=?l;
}
};
clase?Círculo:?público?Forma{
privado:?
float?r;
público:
float?peri(){
return?2*(3.1415926?*?r) ;
}
};
void?main(){
Rect?r(1,?1); p>
p>
¿Forma?*p=amp;r;
coutlt;lt;?p-gt;peri();
}