Question
You are not to modify the main program code THE FRACTIONALCOMPLEX CLASS The primary work that you will be doing is creating the FractionalComplex class
You are not to modify the main program code
THE FRACTIONALCOMPLEX CLASS The primary work that you will be doing is creating the FractionalComplex class and its associated methods. You will be expected to implement all of the methods below, but as always, you are welcome to add additional methods if you want / need them to help you out. Your class should only use int values, as the point of the class is to do things with fractions. A Fractional Complex number will be represented by 4 integer values, a, b, c, and d. The format of the number will be ( / ) + ( / ) Note that you should not have to keep track of the (i) as that will be in the code. At all times should be kept in reduced form as should . (1 / 2) + (4 / 5) is acceptable, but (5 / 10) + (4 / 5) is not because / is not reduced. If at any time one of the numbers is zero, represent it by the number 0 / 1 . So (0 / 1) + (0 / 1) is acceptable. Make sure that the denominators (b,d) are never zero. If they become zero in the constructor or by work, then make the value 0 / 1 by default. Note that these are fractions. Make sure you add/subtract/multiply/divide according the rules for fractions. If a fraction is negative, then the negative number should be in the numerator. If they are both negative then make it positive. 1 / 2 and 1 / 2 are ok. 1 / 2 , 1 / 2 are not ok.
PHASE ONE FRACTIONALCOMPLEX () You will want a default constructor that creates the number (0 / 1) + (0 / 1) . FRACTIONALCOMPLEX (INT X, INT Y) You will want a two variable constructor that creates the number ( / 1) + ( / 1) . FRACTIONALCOMPLEX (INT A, INT B, INT C, INT D) You will want a four variable constructor that creates the number ( / ) + ( / ) . Make sure to watch for invalid numbers and reduce after entry. PRIVATE REDUCE() You will want to add a private method that double checks both a/b and c/d to make sure that they are reduced. You will be using this a lot, so make sure that it is a method. This is also where you should check the positive/negative of each fraction. PUBLIC PRINTME() Eventually we will be overloading the << method, but for initial testing, create a printme() method that outputs the FractionalComplex in the form. [(a/b) + (c/d)i] So if a = 2, b = 5, c = 10, d = 11. Then the output of printme() should look like: [(2/5) + (10/11)i]
PHASE 2 OPERATOR+ Create an operator that allows you to add two FractionalComplex together to create a third one. Adding complex numbers requires you to add the real parts together and the imaginary parts together. So if = (1 / 2) + (3 / 4) and = (1 / 3) + (5 / 4) then the code z = x + y Should make = (5 / 6) + (2 / 1) . Note that he numbers were added then simplified. (1 / 2) + (1 / 3) = (5 / 6) and (3 / 4) + (5 / 4) = (8 / 4) = (2 / 1) OPERATOR Create an operator that allows you to subtract two FractionalComplex together to create a third one. Subtracting complex numbers requires you to subtract the real parts together and the imaginary parts together. [ (1 / 2) + (4 / 5) ] [ (1 / 3) + (2 / 3) ] = [ (1 / 6) + (2 / 15) ]
#include
using namespace std;
void intro(); void section1(); void section2();
int main() { void intro() {
void section1() { cout << "** Section 1" << endl; cout << "Basic creation and printing" << endl << endl; FractionalComplex a; FractionalComplex b(5, 10); FractionalComplex c(1,2,3,4); a.printme(); b.printme(); c.printme(); }
void section2() {
cout << endl << endl; cout << "** Section 2" << endl; cout << "Reductions " << endl << endl;
FractionalComplex a;
a = FractionalComplex(20, 6, 10, 8); a.printme(); a = FractionalComplex(-45, 105, 60, 54); a.printme(); a = FractionalComplex(-2, -4, -12, -8); a.printme(); a = FractionalComplex(1, -4, 2, -10); a.printme();
}
} }
Prints Out;
Section 1: Basic creation and printing
[(0/1)+(0/1)i]
[(5/1)+(10/1)i]
[(1/2)+(3/4)i]
Section 2: Reductions
[(10/3)+(5/4)i]
[(-3/7)+(10/9)i]
[(1/2)+(3/2)i]
[(-1/4)+(-1/5)i]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started