Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

CSCP 1024 Object Oriented Paradigm

Lab Manual

Session: Fall 2014

Faculty of Information Technology


UCP Lahore, Pakistan

Lab 6: Constructors Destructors


Instructions:
Draw Class diagram before you start coding

Indent your code

Comment your code

Use meaningful variable names

Plan your code carefully on a piece of paper before you implement it.

You must follow all best programming practices discussed in class.

Lab Tasks:
Create a class called ComplexNumber for performing arithmetic with complex numbers.
Write a driver program to test your class. Use integer variables to real and imaginary to
represent the data of the class. Also declare another data member named sign to represent +
and sign between real and imaginary part. For details on complex number you may review
the manual on complex number provided to you.
Provide a constructor function that enables an object of this class to be initialized when it is
declared. You have to enforce the rule that your class object cannot be instantiated without
providing real and imaginary values. Sign parameter can be set to a default + sign. (Hint:
assign default parameter value in constructor if sign is not provided for initialization)
Also declare an overloaded constructor that initializes the object with another complex
number object.
Also think logically if the getter and setter functions are required or not.
Provide public member functions for each of the following:
1. Addition of two complex numbers.
2. Subtraction of two complex numbers.
3. Multiplication of two complex numbers.
4. Division of two complex numbers.
5. Conjugate of a real number.
6. Printing complex numbers in the form a+bi where a is the real part and b is the
imaginary part.

You might also like