Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <iostream>
- #include <iomanip>
- using namespace std;
- class Tcomplex{
- public:
- float Re;
- float Im;
- Tcomplex();
- Tcomplex(float R);
- Tcomplex(float R, float I);
- friend Tcomplex operator +(Tcomplex R, Tcomplex I);
- friend ostream & operator<<(ostream& ekran, Tcomplex x);
- friend ostream & operator-(ostream& ekran, Tcomplex x);
- friend ostream & operator*(ostream& ekran, Tcomplex x);
- friend ostream & operator/(ostream& ekran, Tcomplex x);
- };
- Tcomplex::Tcomplex(){
- Re=0;
- Im=0;
- };
- Tcomplex::Tcomplex(float R){
- Re=R;
- Im=0;
- };
- Tcomplex::Tcomplex(float R,float I){
- Re=R;
- Im=I;
- };
- Tcomplex operator +(Tcomplex R, Tcomplex I)
- {
- Tcomplex c;
- c.Im=R.Im+I.Im;
- c.Re=R.Re+I.Re;
- return c;
- }
- Tcomplex operator -(Tcomplex R, Tcomplex I)
- {
- Tcomplex c;
- c.Im=R.Im-I.Im;
- c.Re=R.Re-I.Re;
- return c;
- }
- Tcomplex operator *(Tcomplex R, Tcomplex I)
- {
- Tcomplex c;
- c.Im=R.Im*I.Im;
- c.Re=R.Re*I.Re;
- return c;
- }
- Tcomplex operator /(Tcomplex R, Tcomplex I)
- {
- Tcomplex c;
- c.Im=R.Im/I.Im;
- c.Re=R.Re/I.Re;
- return c;
- }
- ostream&operator <<(ostream&ekran, Tcomplex x)
- {
- ekran<<x.Re<<""<<showpos<<x.Im<<"j"<<noshowpos<<endl;
- return ekran;
- }
- int main()
- {
- Tcomplex::Tcomplex L1(1,2);
- Tcomplex::Tcomplex L2(6,4);
- Tcomplex::Tcomplex L3;
- L3=L1/L2;
- cout<< L3;
- //cout<<L1.Re<<L1.Im;
- system("PAUSE");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement