Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use C++ Given Main program; /* * CS 145 Assignment 4 * Primary File for use with the FractionalComplex class * * This file

Please use C++

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Given Main program;

/* * CS 145 Assignment 4 * Primary File for use with the FractionalComplex class * * This file is the primary file for use with the student created * class FractionalComplex class. It is designed to test * all of the possible operators needed for that class. * * it is divded into pieces so that it can be done in sections. * each "section" contains different parts of the requirement. * * Students may only alter this file by removing commented sections * as they implement more and more parts of their code. * The primary code should be untouched */

#include #include "FractionalComplex.h"

using namespace std;

void intro(); void section1(); void section2(); void section3(); void section4(); void section5(); void section6(); void section7(); void section8();

int main() { intro(); //Uncomment these as you complete various sections. //section1(); //section2(); //section3(); //section4(); //section5(); //section6(); //section7(); //section8(); }

void intro() {

cout

void section1() { cout

void section2() {

cout

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();

}

void section3() {

cout

FractionalComplex a, b, c;

cout

c = a + b; cout

cout

c = a + b; cout

void section4() {

cout

FractionalComplex a, b, c;

cout

c = a - b; cout

cout

c = a - b; cout

void section5() {

cout

FractionalComplex a, b, c, d; a = FractionalComplex(2, 5, 3, 7); b = FractionalComplex(2, 5, 3, 7); c = FractionalComplex(10, 25, 15, 35); d = FractionalComplex(10, 25, 35, 36);

a.printme(); b.printme(); cout

cout

a.printme(); c.printme(); cout

cout

c.printme(); d.printme(); cout

cout

a.printme(); d.printme();

cout

cout

a.printme(); d.printme();

cout d) {cout a) {cout

}

void section6() {

cout

FractionalComplex a, b; a = FractionalComplex(6,4,12,9); b = FractionalComplex(1,5,5,6);

cout

void section7() { cout

FractionalComplex a, b; a = FractionalComplex(1,2,3,5); b = FractionalComplex(1,3,2,5);

cout

a = FractionalComplex(-1,1,2,9); b = FractionalComplex(3,5,1,5);

cout

cout

}

void section8() { cout

FractionalComplex a,b; a = FractionalComplex(1,2,1,4);

cout

b = FractionalComplex(1,3,1,5); cout

CS132 - PROGRAMMING ASSIGNMENT FRACTIONS OVERVIEW This activity is designed to have you work with a class and practice adding field methods and operator overloading. INSTRUCTIONS In this program you will write a class that is designed to combine the concepts of integer fractions and complex numbers. Remember from math class that a fraction is number written in the form 7 where a and b are not reducible. is acceptable whereas is not because it can be reduced by a power of two. However we are also going to augment that with the idea of a complex number. Remember that the complex numbers are a joint number consisting of a real part (a) and an imaginary part (6 * i) where i is the imaginary number -1. Your class will implement the FractionalComplex number class, and allow for the class to implement the necessary overloaded functions and operators. You will be provided a main program that is designed to test your class, and make sure that each part is working as indicated. Note that if you need help with the math involved, tips will be provided at the end, but feel free to get help from a math instructor or from your computer science instructor. THE MAIN PROGRAM. Your main program will be provided for you. It will be broken into pieces that allow you to get parts of your program up and running in small sections without having to get the entire thing working at once. You are not to modify the main program code as a norm, but sections of it are commented out. It will be important for you to uncomment these sections as you get parts of your code working. THE FRACTIONALCOMPLEX CLASS The primary work that you will be doing is creating the Fractional Complex 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 {+i is acceptable, but + i is not because is not reduced. If at any time one of the numbers is zero, represent it by the number. So + i 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 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. and= are ok. are not ok. PHASE ONE FRACTIONALCOMPLEX () You will want a default constructor that creates the number i + i. FRACTIONALCOMPLEX (INT X, INT Y) You will want a two variable constructor that creates the number *+}i. FRACTIONALCOMPLEX (INTA, INT B, INT C, INT D) You will want a four variable constructor that creates the number 6 +i. 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 positiveegative of each fraction. PUBLIC PRINTME() Eventually we will be overloading the Create an operator that allows you to check to see if one Fractional Complex is larger than another. To compare two fractional numbers, you check to see if one is longer than the other using the private length() method; PHASE 4 OPERATOR Create an operator that allows you to check to see if one Fractional Complex is larger than another. To compare two fractional numbers, you check to see if one is longer than the other using the private length() method; PHASE 4 OPERATOR

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Discuss the evidence for environmental influences on intelligence.

Answered: 1 week ago

Question

it can be used for for storing lots of information

Answered: 1 week ago

Question

5. If yes, then why?

Answered: 1 week ago

Question

6. How would you design your ideal position?

Answered: 1 week ago