Class Assignment Number: Two
DEPARTMENT OF APPLIED SCIENCES AND GRADUATE STUDIES
OBJECT ORIENTED PROGRAMMING
OBJECT ORIENTED PROGRAMMING
Submission Format: Print out on A4 size blank paper
Problem One:
Write a class description for complex numbers. A complex number in mathematics is
defined as x + y, where x defines the real part and y defines the imaginary part. Provide
the getData and displayData functionalities to input and display a complex number.
Overload the addition operator (+) that adds two complex numbers, subtraction
operator (–) that finds the difference of two complex numbers, multiplication operator
(*) that finds the product of two complex numbers and Equals to operator (==) that
compares two complex numbers for equality.
Test the class by creating three complex numbers, all initialized to zero. Provide the
following menu to perform various functions.
Pressing ‘I’: To input the values for two complex numbers.
Pressing ‘A’: To add the two complex numbers and display the result.
Pressing ‘S’: To subtract the first complex number from second and display the result.
Pressing ‘M’: To find the product of two complex numbers and display the result.
Pressing ‘C’: To check if the two complex numbers are equal or not.
Pressing ‘E’: To Exit
Formula:
Add: x3 = x1 + x2, y3 = y1 + y2
Subtract: x3 = x1 – x2, y3 = y1 – y2
Multiply: x3 = x1 * x2 – y1 * y2,
y3 = x1 * y2 + y1 * x2
Post A Comment
No comments :