I have a C++ exam on monday and I would appreciate some help. I'm currently going through some past papers and I need help on this question:
Design a C++ class to represent an object that consists of two members, a and b. Provide methods to overload the assignment (=), addition +, subtraction - , and division / operators, as given below. Provide a constructor that can initialise the object with specified values for a and b.
Operations on the object consisting of the members a and b with another object with members c and d.
I have no idea if this is right and I have no idea how to complete it. I'm unsure in the example I listed to include a b c d instead of actual numbers in the main function and if that would actually work.
Appreciate any help on how to start/complete this :)
- Don't bother with defining default constructor unless you plan on setting the X and y member variables to 0 on initialization (which you may want to do).
- When you do define a default constructor like in this case the compiler will no longer fill in the copy constructor or the destructor for you, this is commonly referred to as the "Rule of Three". The destructor isn't so important in your case since there aren't any dynamically allocated variables to clean up, but the copy constructor should be made.
- The braces around 'temp' when you return it are not necessary.
- You should avoid 'using' namespaces inside of header files, this is more about good practice then functionality. Also you don't use anything from the std namespace in this header file anyway.