answersLogoWhite

0


Best Answer

The C++ standard library provides a class complex in <complex>, including all the standard arithmetic operator overloads. It is highly unlikely that a user-defined implementation will improve upon any of the existing implementations, however the source code is worthy of study, particularly if you wish to extend the implementation in order to cater for a user-defined scalar; all the built-in scalars are already catered for.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you create a class complex in c plus plus and overload the following operators plus minus multiplication and division?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Why ostream operators not overloaded using member functions?

Consider the following line: cout&lt;&lt;obj; where obj is the object of Demo class. In this case we are overloading "&lt;&lt;" operator. But overloading the binary operator using member function, the left hand operand should be the object of relevant class. Here in this case left hand side operand is not the object of Demo class. It is object of ostream class. Hence we cant overload ostream operators using member function. But we can overload these type of operators using friend functions. Thanks, Prof. D. H. Ingole


Why should you have to use comparison operator overloading in pairs in c?

You cannot overload operators in C. This is a C++ thing only.


What of the following is a characteristic of an overload boat?

handles poorly


Which stream functions in c plus plus control the formatting of input and output values of a class?

None of them. To control the formatting of your classes, you must overload the stream insertion and extraction operators.


When was Overload - Overload album - created?

Overload - Overload album - was created in 2006.


Which of the following is not one of the ways to achieve overload or placement of greaterthannormal demands on muscles through exercise?

Increased rest periods


How to overload the new and delete operators to provide custom dynamic allocation of memory?

You don't. Remember that C++ is a superset of the C language. You can still use the old malloc/free functions to perform your own memory allocation/deletion.


What is meant when you say you overload an operator?

All operators are built-in but not all operators can operate upon data types they know absolutely nothing about. There are some exceptions such as the new operator and the sizeof operator -- both will work on any datatype. However, for those that cannot, operator overloads allow you to cater specifically for those types. An operator overload is implemented just as you would overload a function, but it is not a function per se because operators have different calling conventions to functions. It is also important to keep in mind that just because you can overload an operator, it does not mean that you should. Operators should only be overloaded when the overload would allow a user to interact with your data type in an intuitive manner; a manner that is consistent with the operator's intended purpose. So while it can be amusing to overload the plus (+) operator to perform a subtraction (-), it could hardly be called intuitive. The assignment operator is the most overloaded operator of them all. This is because it is extremely useful to be able to copy the members of one object and assign those values to another object of the same type. We can also overload the assignment operator to cater for objects of different types, but such assignments are rarely intuitive. Does it make sense to assign the properties of a banana object to a person object? Probably not. Even if you could find a practical reason for doing so, would it be an intuitive operation? Definitely not. Therefore there's no point in providing an operator to cater for this. To create an operator overload, the declaration will often be placed inside the class it pertains to. However there are exceptions. The output stream insertion operator is a good example of this. The following example demonstrates how we can overload an internal operator (the assignment operator) as well as an external operator (output stream insertion operator). #include&lt;iostream&gt; // required to make use of I/O streams class A { private: unsigned m_data; public: // constructors... A (const unsigned data = 0): m_data (data) {} A (const A&amp; copy): m_data (copy.m_data) {} // accessor function (interface) unsigned get_data() const { return m_data; } // operator overloads... A&amp; operator= (const A&amp; rhs) { m_data = rhs.m_data; } A&amp; operator= (const unsigned rhs) { m_data = rhs; } }; std::ostream&amp; operator&lt;&lt; (std::ostream&amp; os, const A&amp; a { os &lt;&lt; a.get_data(); return os; } int main() { A a, b; // invoke default constructors a = 42; // call assignment operator overload b = a; // call default assignment operator overload // call insertion operator overload std::cout &lt;&lt; a &lt;&lt; std::endl; std::cout &lt;&lt; b &lt;&lt; std::endl; } Output: 42 42


How does a cell avoid cell overload?

Flattened shapeFingerlike extensionsSpecialized organelles to improve efficiency (explains animal and plant cells being lager than bacterial cells)


When was Overload - magazine - created?

Overload - magazine - was created in 1993.


When was System Overload created?

System Overload was created in 2006.


When was Overload - novel - created?

Overload - novel - was created in 1979.