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

c++ Imagine that the company you work for is going to create a lot of tutorials

ID: 650750 • Letter: C

Question

c++

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;

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