0% found this document useful (0 votes)
28 views2 pages

Oop in C++ Questions

The document describes an assignment for an OOP class with two tasks. Task 1 involves creating a Fraction class with data members for the numerator and denominator. It requires overloading operators like +, -, *, ++, and -- for fractions. Task 2 involves creating a ComplexNumber class to represent complex numbers with real and imaginary parts. It requires implementing constructors, getters/setters, and overloading operators like +, -, and * for complex arithmetic. Comparision operators and increment/decrement operators must also be overloaded.

Uploaded by

Naseem Ullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views2 pages

Oop in C++ Questions

The document describes an assignment for an OOP class with two tasks. Task 1 involves creating a Fraction class with data members for the numerator and denominator. It requires overloading operators like +, -, *, ++, and -- for fractions. Task 2 involves creating a ComplexNumber class to represent complex numbers with real and imaginary parts. It requires implementing constructors, getters/setters, and overloading operators like +, -, and * for complex arithmetic. Comparision operators and increment/decrement operators must also be overloaded.

Uploaded by

Naseem Ullah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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