Practice with Classes
Separate declaration and definition
In class, for illustration, we put the class definition and the member function definitions together in the header file.
This assignment requires you to separate the class definition and the member function definitions into two files, the header file and the implementation file.
Separate the rectangle.cpp into Rectangle.h, Rectangle.cpp and main.cpp. Write a CMakeLists.txt to compile the project.
Complex number class
Define a class called Complex for performing arithmetic with complex numbers. Write a program to test your class.
- Use two member variables to represent the private data of the class.
- Provide a constructor that enables an object of this class to be initialized when it’s declared.
- Create a
main.cppto test the class.
Provide public member functions that perform the following tasks:
add: Add two complex numbers. The result is returned as aComplexobject.subtract: Subtract two complex numbers. The result is returned as aComplexobject.print: Print a complex number.
Submit Complex.h, Complex.cpp and main.cpp. Write a CMakeLists.txt to compile the project.
Submission
Create two folders and name them assignment1 and assignment2.
- For assignment 1, submit
rectangle.h,rectangle.cpp,main.cppandCMakeLists.txtinsideassignment1. - For assignment 2, submit
complex.h,complex.cpp,main.cppandCMakeLists.txtinsideassignment2. - Finally zip two folders and submit the zip file.