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

University of Management and Technology Lahore

Subject: OOP T. Marks:20


Instructor: Nosheen Manzoor Ass=10+Viva=10

Assignment#3
Note:
 Submission deadline: 15/12/2023
 Bring your assignment along with you for Viva.
 Plagiarized assignments will be graded as zero.
Task 1:

Create a class Fraction containing two integer data members named num and den, used to
store the numerator and denominator of a fraction having the form num/den.
i. Implement all member functions required.

ii. Overload the + operator for adding two Fractions and returning the result. (a/b+c/d =
a*d+c*b/bd).

iii. Overload the - operator for subtracting two Fractions and returning the result. (a/b - c/d =
a*d - c*b/bd)

iv. Overload the * operator for multiplying two Fractions and returning the result. (a/b * c/d =
a*c/bd)

v. Overload the ++ operator Fractions that will add 1 in a fraction.

viii. Overload the -- operator Fractions that will subtract 1 from a fraction.
Write main function to demonstrate functionality of above class.

Task 2:
Recall that a complex number is of the form a + bi, in which a is the real part and b is the
imaginary part. Implement a class named ComplexNumber which stores and manipulates a
complex number e.g real part and imaginary part.

a. Implement the constructors. Default constructor should initialize both parts to 0.


Implement the getters and setters.

b. Implement the +, -, and * operators for ComplexNumber.


Adding two complex numbers ( a + bi ) and ( c + di ) yields ( (a+b) + (c+d)i ).
Subtracting two complex numbers ( a + bi ) and ( c + di ) yields ( (a-b) + (c-d)i ).
Multiplying two complex numbers ( a + bi ) and ( c + di ) yields ( (ac-bd) + (ad+bc)i ).
c. Implement the <, >, and == operators for ComplexNumber. > checks if the real part of
first complex number is bigger than second, if the real part is bigger, then the first complex
number is bigger, if it is less, then the first is smaller, if they’re same, then the decision goes
to imaginary part.

d. Implement the >=, <=, and != operators for ComplexNumber.

e: Implement the pre and post increment and decrement operators for ComplexNumber.
Increment and decrement operators should only add 1 or subtract 1 from real part.

You might also like