Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- class complexNum
- {
- private:
- double w, i;
- public:
- complexNum ();
- complexNum (double, double);
- void add (complexNum o)
- {
- w += o.getWholePart();
- i += o.getImagiPart();
- }
- void subtract (complexNum o)
- {
- w -= o.getWholePart();
- i -= o.getImagiPart();
- }
- void multiply (complexNum o)
- {
- double tmp = w;
- w = w*o.getWholePart() - i*o.getImagiPart();
- i = tmp*i + i*o.getWholePart();
- }
- double getWholePart ()
- {
- return w;
- }
- double getImagiPart ()
- {
- return i;
- }
- void print()
- {
- std :: cout << "(" << w << " + " << i<<"i)";
- }
- };
- complexNum::complexNum ()
- {
- w = 16;
- i = 12;
- }
- complexNum::complexNum (double wPart, double iPart)
- {
- w = wPart;
- i = iPart;
- }
- int main()
- {
- double x1, y1, x2, y2;
- std::cout << "Enter an x1 and y1 value in the form \"x1 y1\"\n";
- std::cin >> x1 >> y1;
- std::cout << "Enter an x2 and y2 value in the form \"x2 y2\"\n";
- std::cin >> x2 >> y2;
- complexNum a = complexNum(x1, y1), b = complexNum(x2, y2);
- a.add(b);
- a.print();
- a = complexNum(x1, y1), b = complexNum(x2, y2);
- a.subtract(b);
- a.print();
- a = complexNum(x1, y1), b = complexNum(x2, y2);
- a.multiply(b);
- a.print();
- system("PAUSE");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement