Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

please clean out the solution #include <iostream> #include<math.h> using namespa

ID: 3740780 • Letter: P

Question

please clean out the solution

#include <iostream>

#include<math.h>

using namespace std;

class fraction {

int numerator;

int denominator;

double wholenumber;

public:

fraction();

fraction(double wholenumber, int numerator = 0, int denominator = 1);

  

void reducefraction();

int gcd(int a, int b);

  

};

fraction::fraction() {

numerator = 0;

denominator = 1;

reducefraction();

}

fraction::fraction(double wholenumber, int numerator, int denominator) {

numerator = numerator;

denominator = denominator;

wholenumber = wholenumber;

reducefraction();

}

void fraction::reducefraction() {

if (wholenumber == 0) {

for (int index = 0;index = denominator * numerator; index--) {

if ((denominator % index == 0) && (numerator % index == 0)) {

  

int complete = gcd(numerator, denominator);

numerator = numerator / complete;

denominator = denominator / complete;

}

}

}

else {

int number = denominator * wholenumber + numerator;

for (int index = denominator * number; index > 1; index--) {

if ((denominator % index == 0) && (number% index == 0)) {

int complete = gcd(numerator, denominator);

numerator = numerator / complete;

denominator = denominator / complete;

}

}int fraction::gcd(int a, int b) {

if (a == 0 || b == 0)

return 0;

else if (a == b)

return a;

if (a > b)

return gcd(a - b, b);

return gcd(a, b - a);

}

wholenumber = number / denominator;

numerator = number % denominator;

}

cout << " The reduced fraction is" << " "

<< wholenumber << " " << numerator << "/" << denominator << endl;

}

int main() {

double wholenumber;

int numerator;

int denominator;

cout << " Enter a whole number:";

cin >> wholenumber;

cout << " Enter numerator:";

cin >> numerator;

cout << " Enter denominator:";

cin >> denominator;

if ((wholenumber == 0 && denominator == 0)) {

cout << " Denominator value set to 1";

fraction (wholenumber, numerator, 1);

}

else if (denominator == 0) {

cout << " Denominator value set to 1";

fraction(wholenumber, numerator);

}

else

fraction(wholenumber, numerator, denominator);

system("pause");

return 0;

}

a. You have been developing a Fraction class for Teacher’s Pet Software that contains

several fields and functions.

Add two constructors to the class. The first accepts two integer values representing the

numerator and denominator. If a single integer is passed to the constructor, use it as the

numerator, and use a default value of 1 for the denominator. If no values are passed to

the constructor, use a default value of 0 for the numerator and 1 for the denominator.

When any Fraction is constructed with a 0 argument for the denominator, force the

denominator value to 1.

The second constructor requires three arguments: a whole number portion for a Fraction,

a numerator, and a denominator. This constructor executes when any Fraction object

is instantiated using three integer arguments. As with the other constructor, when any

Fraction is constructed with a 0 argument for the denominator, force the denominator

value to 1.

Whenever a Fraction object is constructed, automatically reduce the Fraction to the

proper format. For example, a Fraction created using 0, 2, and 4 as arguments should

be reduced to 1/2, and a Fraction created as 3 10/2 should be reduced to 8 0/1.

Write a main()function that declares several Fraction objects, and confirm that the

class works correctly.

Save the file as Fraction.cpp.

Explanation / Answer

Please find my code:

a) Frction Program

Program

//HeaderFiles
#include<iostream>
#include<math.h>
//For input output(cin,cout)
using namespace std;
//Fraction class
class fraction {
   //member variables
   int numerator;
    int denominator;
    double wholenumber;
   //You have to declare member functions as public
public:
   //Default constructor
   fraction();
   //Construction with parameters
   fraction(double wholenumber, int numerator = 0, int denominator = 1);
   //method
   void reduceFraction();
};//end of the class
//method definitions
fraction::fraction() {
   //put default values to numerator and denominator
    numerator = 0;
    denominator = 1;
   reduceFraction();
}
fraction::fraction(double wholenumber, int numerator, int denominator) {
   //set values to numerator,denominator and wholenumber with user given
   numerator = numerator;
    denominator = denominator;
    wholenumber = wholenumber;
    reduceFraction();
}
//fraction calculation expansion
void fraction::reduceFraction() {
   if (wholenumber == 0) {

       for (int index = 0; index = denominator * numerator; index--) {

           if ((denominator % index == 0) && (numerator % index == 0)) {

               denominator /= index;

               numerator /= index;

           }

       }

   }

   else {

       int number = denominator * wholenumber + numerator;

       for (int index = denominator * number; index > 1; index--) {

           if ((denominator % index == 0) && (number% index == 0)) {

               denominator /= index;

               number /= index;

           }

       }

       wholenumber = number / denominator;

       numerator = number % denominator;

   }

   cout << wholenumber << "" << numerator << "/" << denominator;

}
//main function
int main() {
   //variable declaration
   int numerator;
    int denominator;
    double wholenumber;
   //user prompt
    cout << " Program to reduce fraction" << " Enter 0 when you don't want to enter value";
    cout << "Enter a whole number";
    cin >> wholenumber;
    cout << "Enter numerator";
    cin >> numerator;
    cout << "Enter denominator";
    cin >> denominator;
  
   //check denominator
   if (wholenumber == 0 && denominator == 0) {

       cout << "Denominator has been set to defult value 1";

       fraction f(wholenumber, numerator, 1);

   }
   else if (denominator == 0) {

       cout << " Denominator has been set to defult value 1";

       fraction(wholenumber, numerator);

   }
   else
       fraction(wholenumber, numerator, denominator);
return 0;
}

-----------------------------------------------------------------------------------------------------------------