Language is C Youll be creating your own class called Fracti

Language is C++

You\'ll be creating your own class called Fraction which stores a fractional value. Your Fraction class will have the following integer member variables: num: representing the numerator den: representing the denominator (must be non-zero) Your Fraction class should have the following member functions: Constructors: one general and one default constructor- don\'t forget to do input validation on denominator. Accessors: one get function for each member variable Mutators: one set function for each member variable - don\'t forget to do input validation on denominator Print (): a function to display the fraction in standard format, e.g. 1/2. double getDecimal(): calculates the decimal equivalent of the fraction and returns it. Your main function should: Create a Fraction object and use the general constructor to initialize it to 6/10. Call print on the object. Create an array of 3 Fraction objects. Prompt the user for the values of the numerator and denominator of the 3 Fractions and use the mutators-to set their values. Find the item with: The largest numerator The largest denominator The largest decimal equivalent. If you want, you can use the following values for your 3 fractions to test whether your code from part 5 -works correctly: 1/100, 5/40, 3/4.

Solution

class Fraction
{
int num,den;

Fraction()
{System.out.println(\"In Fraction class\");
}
Fraction(int num, int den)
{this.num = num;
if(den!=0)
{this.den= den;}}

int getNum()
{return num;}

int getDen()
{return den;}

void setNum(int num)
{this.num = num;}

void setDen(int den)
{if(den!=0)
{this.num= num;}}
}

float print()
{
float fraction;
fraction = num/den;
System.out.println(\"Fraction value is\"+fraction);
return fraction; }
}

public static void main(String arg[])
{float fraction;
Fraction f = new Fraction(6,10);
fraction = f.print();
}
}

Language is C++ You\'ll be creating your own class called Fraction which stores a fractional value. Your Fraction class will have the following integer member v

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site