# CSCI 1730 – Programming Assignment 3 solved

\$40.00

## Description

5/5 - (1 vote)

1. Create a class, called Complex, for modeling complex numbers, a + bi, and some complex number arithmetic/comparison operations.

Here is what should be included within this class:
• Include a no-argument constructor (to initialize a complex number to 0+0i).
• Include public member functions to perform these complex number tasks:
o Addition of complex numbers
o Subtraction of complex numbers
o Multiplication of complex numbers
o Division of complex numbers
o User input of a complex number
o Display of a complex number
o Conversion of a real number, r, to a complex number, r + 0i
o Check for equality of two complex numbers

Then, write a C++ program that will use the Complex class to repeatedly do one of the following tasks:
a) Perform a complex number arithmetic operation. For this option, the program will ask the user to enter a complex number, an arithmetic operation (+, –, *, /), and a second complex number, and will then calculate and display the result of performing the arithmetic operation on the two input complex numbers.
b) Determine if a complex number is a solution of a quadratic equation. For this option, the program will prompt for and read in the real number coefficients, a, b, and c, of a quadratic equation, ax2+bx+c=0. Next, it will prompt for and read in a complex number, z. Then, it will determine if z is a solution of the quadratic equation.

• Note: When checking for equality of two complex numbers, do not use the “is equal to” operator on the float values – instead, determine if the absolute value of the float values are smaller than a threshold value (something small, like 0.000001).
• To extract input of a complex number a + bi from keyboard, do the following:
double a, b;
char i;
cin >>a >> b >> i;

Complex Number Review:
A complex number is a number of the form a + bi where a and b are real numbers and i is the imaginary unit, .

• Multiplication:
• Division:

Here is output from a sample run of the program (user input in bold):

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
1
Enter a complex number a+bi: 2+3i
Enter an operation (+, -, *, /): +
Enter a complex number a+bi: 4-8i
2+3i + 4-8i = 6-5i

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
1
Enter a complex number a+bi: 2+9i
Enter an operation (+, -, *, /): –
Enter a complex number a+bi: 4+5i
2+9i – 4+5i = -2+4i

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
1
Enter a complex number a+bi: 4+2i
Enter an operation (+, -, *, /): *
Enter a complex number a+bi: 4-2i
4+2i * 4-2i = 20+0i

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
1
Enter a complex number a+bi: 4+8i
Enter an operation (+, -, *, /): /
Enter a complex number a+bi: 1-1i
4+8i / 1-1i = -2+6i

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
2
Enter the coefficients of a quadratic equation: 1 -2 5
Enter a complex number a+bi: 1+2i
The complex number: 1+2i is a solution of the quadratic equation

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
2
Enter the coefficients of a quadratic equation: 1 -2 5
Enter a complex number a+bi: 2+3i
The complex number: 2+3i is not a solution of the quadratic equation

Select an option – (1) perform complex number arithmetic
(2) check for quadratic equation solution
(3) exit
3

2. Modify the Complex class from problem #1 and replace all arithmetic and relational operator member functions with appropriate overloaded operators (+, -, *, /, ==). In addition, add friend functions to overload the insertion and extraction operators (<< and >>) for use with the Complex class. Then modify the main function and any other stand-alone functions that make use of Complex objects to make use of the new overloaded operators.

3. Write a class IntSet for modeling sets of integers in the range 0 through 99. A set should be represented internally as an array of type bool: The ith array element will be true whenever integer i is in the set and will be false whenever integer i is not in the set. Include a no-argument constructor that initializes a set to the so-called “empty set,” i.e., a set whose array representation contains all false values. The class should include the following overloaded operators:
+ to perform the union of two set (the union of sets A and B is the set that contains all
elements of set A or set B, or both).
* to perform the intersection of two sets (the intersection of sets A and B is the set that
contains all elements in both set A and set B.)
– to form the difference of two sets (the difference of sets A and B is the set containing those elements that are in A but not in B)
+= to add an integer into a set.
-= to delete an integer from a set.
== to determine if two sets are equal.
! to form the complement of a set (the complement of set A, denoted , is the set containing all the elements in the universal set that are not in A – the universal set for this problem is the set containing all integers between 0 and 99)