Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using std::string;
- class complex{
- public:
- void complex();
- void complex(double, double, string);
- complex add(complex, complex);
- complex subtract(complex, complex);
- complex multiply(complex, complex);
- void output();
- double getReal(){return real;}
- double getImaginary(){return imaginary;}
- void setReal(double r){real = r;}
- void setImaginary(double im){imaginary = im;}
- private:
- double imaginary;
- double real;
- string i;
- };
- void complex::complex(){
- imaginary = 1;
- real = 2;
- i = "(SQRT(-1))";
- }
- void complex::complex(double a, double b){
- real = a;
- imaginary = b;
- i = "(SQRT(-1))";
- }
- void complex::setComplexumber(double a, double b){
- real = a;
- imaginary = b;
- }
- complex complex::add(complex lhs, complex rhs){
- lhs.setReal(lhs.getReal()+rhs.getReal());
- lhs.setImaginary(lhs.getImaginary()+rhs.getImaginary());
- return complex(lhs.getReal(), lhs.getImaginary());
- }
- complex complex::subtract(complex lhs, complex rhs){
- lhs.setReal(lhs.getReal()-rhs.getReal());
- lhs.setImaginary(lhs.getImaginary()-rhs.getImaginary());
- return complex(lhs.getReal(), lhs.getImaginary());
- }
- complex complex::multiply(complex lhs, complex rhs){
- lhs.setReal(lhs.getReal()*rhs.getReal());
- lhs.setImaginary(lhs.getImaginary()*rhs.getImaginary());
- return complex(lhs.getReal(), lhs.getImaginary());
- }
- void complex::output(){
- std::cout << std::stod(real) << " + " << std::stod(imaginary)<<" * " << i << "\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement