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

C++ Fraction 1 1. Imagine that the company you work for is going to create a lot

ID: 655184 • Letter: C

Question

C++

Fraction 1

1. Imagine that the company you work for is going to create a lot of tutorials on Fractions. You are to create a robust Fraction class that will have all of the following  (all examples are for a fraction half that has a numerator of 1 and a denominator of 2):

*Private integers numerator and denominator ;

*All public getter and setter functions for the numerator and denominator;

*Safeguard that the denominator will NEVER become 0!

*a default constructor with no arguments;

*a constructor that accepts both the numerator and denominator;

*a toDecimal method that returns the decimal value of the fraction, example: 1/2 will be 0.5;

*a toString method that will return the fraction as a string, , example: 1/2 will be "1/2";

*a reduce method that will change the numerator and denominator by finding a common *denominator and reducing the fraction.Example 3/12 becomes 1/4;

Show Sample output showing several different fractions and an example where the user tried to assign 0 to the denominator. Your output should show all of the methods listed above.

Fraction class 2

2. Expand your Fraction class to include all of the following  (all examples are for a fraction half that has a numerator of 1 and a denominator of 2):

*Overload ==, <, <=, >, >= operators (use the decimal values to compare);

*Overload = operator (assigns the numerator and denominator to the fraction);

*.Overload ++ so that 1/3 becomes 2/3 for example.

.*Overload -- so that 2/3 becomes 1/3 for eaxample.

.*It is OK if the numerator is negative.

include a representation of the class and

Sample output showing several different fractions and an example where the user tried to assign 0 to the denominator. Your output should show all of the methods listed above.

Explanation / Answer

#include<iostream.h>
#include<conio.h>
#include<string.h>

class a
{
private:
   int nu, de;
public:
   a()
   {
       nu=0;
       de=1;
   }
   a(int n, int d)
   {
       nu=n;
       de=d;
   }
   float toDecimal(int n, int d)
   {
       if (d>0)
       {
           return(n/d);
       }
       else
       {
           return 1.0;
       }
   }

   String toString(String aa)
   {
       return aa;
   }
};

void main()
{
   a o;
   a o(12,4);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote