Extras din laborator
/*Implementati o clasa pentru realizarea de operatii cu numere complexe, o
functie friend care calculeaza distanta dintre 2 numere complexe si inca o
functie friend pentru a calcula inmultirea unui numar complex cu un
parametru*/
#include <iostream.h>
#include <math.h>
#include <conio.h>
class complex {
private:
float x,y;
public:
complex();
complex(float a,float b);
void citire();
void afis();
friend float dist(complex& nr1,complex& nr2);
friend complex ori(complex& nr, float param);
};
complex::complex() {
x=0;y=0;
}
complex::complex(float a,float b) {
x=a;y=b;
}
void complex::afis() {
cout<<x<<" "<<y<<endl;
}
void complex::citire() {
cout<<"Dati partea reala:";
cin>>x;
cout<<"Dati partea imaginara";
cin>>y;
}
float dist(complex& nr1,complex& nr2) {
float aux;
aux=sqrt((nr1.x-nr2.x)*(nr1.x-nr2.x)+(nr1.y-nr2.y)*(nr1.y-nr2.y));
return aux;
}
complex ori(complex& nr, float param) {
complex aux;
aux.x=nr.x*param;
aux.y=nr.y*param;
return aux;
}
void main() {
clrscr();
complex a,b(3,3),c;
c=ori(b,5);
c.afis();
c.citire();
c.afis();
getch();
}
Conținut arhivă zip
- Probleme POO
- 1.CPP
- 10.CPP
- 11.CPP
- 12.CPP
- 13.CPP
- 14.CPP
- 15.CPP
- 16.CPP
- 17.CPP
- 18.CPP
- 19.CPP
- 2.CPP
- 20.CPP
- 21.CPP
- 22.CPP
- 23.CPP
- 24.CPP
- 25.CPP
- 26.CPP
- 27.CPP
- 28.CPP
- 29.CPP
- 3.CPP
- 30.CPP
- 4.CPP
- 5.CPP
- 6.CPP
- 7.CPP
- 8.CPP
- 9.CPP