Question: Write a C++ program that will include a .h file named complexNumber.h. In this .h file is a class named complexNum. This class has two
Write a C++ program that will include a .h file named complexNumber.h. In this .h file is a class named complexNum. This class has two private variables named real and imaginary both of type float. It has a default constructor that sets both real and imaginary to zero. It has non-default constructor that allows user to initialize real and imaginary to any float number. It has one member function named "setReal" that takes in a float type as an input parameter then set variable real to the input parameter. It has another member function named "getReal" that simply returns a float value that is equal to the variable real. Now extend "getReal" and "setReal" specifications out to write also member functions "setImaginary" and "getImaginary";
Also class complexNum will have a member function named "increment" that has no input parameter. The function returns a complexNum that has real and imaginary data that are equal to the instance's data plus 1. Namely, if instance calling increment is a complex number 5 + 6i, the return value of the function is 6 + 7i. Make sure main tests out the member function "increment". Example:
complexNum a(6, 7);
a=a.increment(); //This will result in real of a = 7 because 6 + 1 = 7 and imaginary of a = 8 because 7 + 1 = 8
Writed the .h file.
Write a complexNumber.cpp file that satisfies the following specifications:
-Has a default constructor that sets both real and imaginary to zero.
-Has a constructor that allows user to initialize real and imaginary to any float number.
-Has member functions "setReal", "getReal", "setImaginary", "getImaginary", and "increment".
Write a main function in a file main.cpp that tests the .h and .cpp files.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
