Design fraction class to represent numerator and denominator

Assignment Help Programming Languages
Reference no: EM1362632

Design a fraction class. The class should have 2 data members to represent the numerator and denominator. Both of these numbers should obviously be integers. It should be able to display a fraction and include an operator for performing multiplication of fractions.

Construct the fraction class with 3 constructors. The first is the default. The second constructor should allow us to create a fraction that represents a whole number. The third constructor should allow us to specify the numerator and denominator of a new fraction object. The public functions should include functions for respectively getting the numerator and denominator, setting the respective numerator and denominator, multiplying fractions, and displaying the fraction.

You should then use this class in a program that multiplies fractions. (Hint: you can create 3 fraction objects f1, f2, and f3. You can use the public function readFraction that reads 2 fractions f1 and f2. You can then use the statement f3 = f1.multiply(f2) to calculate f1 * f2 and assign the result to f3.)

The function's input prompts should be "Enter 1st fraction" and "Enter 2nd fraction" where the user enters the appropriate fractions. In addition, the program needs to display the result of the multiplication operation in the readable format:

3/4 * 5/6 = 15/24

This result should be displayed on one line.
Test the function with the fractions 3/4 and 5/6 and also with 1/2 and 1. (Note that your result will not provide the fraction in reduced form and you do not have to write code to reduce the fraction. Also note that we have not restricted a fraction with a denominator of 0, but this would be a nice addition to your program.)

Reference no: EM1362632

Questions Cloud

The market semi strong form efficient : Investors expect a corporation to announce a 10% increase in earnings, but instead the firm announces a 1% increase. If the market is semistrong-form efficient,
Find the speed of the ball just after collision : A small immersion heater is rated at 352 W. Estimate how long it will take to heat a cup of soup (suppose this is 250 mL of water) from 20°C to 50°C.
Healthcare consumer basics : How can you as a healthcare consumer continue to expand your knowledge base to better take care of yourself and your family? Consider all six dimensions of wellness.
Explain how much is the dollar overvalued/undervalued : Explain how much is the dollar overvalued/undervalued. What do you predict the U.S. real exchange rate with the United Kingdom will be in one year's time.
Design fraction class to represent numerator and denominator : Design a fraction class. The class should have 2 data members to represent the numerator and denominator. Both of these numbers should obviously be integers.
How many extra kilograms of gasoline are obtained : A projectile is launched from level ground. When it lands, its direction of motion has rotated clockwise by 60 degrees. What was the launch angle.
Discuss relevance of budgeting : Discuss the relevance of budgeting as it relates to the accounting profession in general. Relate lessons learned from a self-selected reading or from something you learned while working on your accounting profession in general.
Digestion and absorption of nutrients : The small intestine is the major site of digestion and absorption of nutrients. Where do the enzymes used in this process come from, and why are they available on demand?
Finding break-even point : Air Filter, Inc., sells its products for $6 per unit. It has the following expenses, Separate the expenses between fixed and variable expenses per unit. Using this information and the sales price per unit of $6, compute the break-even point.

Reviews

Write a Review

Programming Languages Questions & Answers

  Void function to display in nicely formated way

Write a void function display_exer() that display in a nicely formated way the eat members of an exerclass object. Pass the object to the function by reference.

  Design a flowchart displays item-s data

Design a flowchart or pseudocode for the following: displays the item's data only if it is a best-selling item. Best-selling items are those that sell more than 2000 pounds per month.

  Subdividing address block among four different customers

The ISP needs to subdivide the address block among four different customers, requiring 29, 28, 27, and 26 hosts respectively.

  Create a function that takes a one dimentional array

Create a function that takes a one dimentional array us a argument the function should return only these members from the array which are divisible by 4.

  Creating message box to display member name

Ddefine for your class is a method to design a message box to display member name, car year and model, and year member joined club.

  Write program for real estate agent

Write a program for a real estate agent. The program should perform the following tasks: ask users for the average house price for the each of past 5 years for a single family residence of 1500 square feet.

  Definition of function quadratic receives double parameters

Write down definition of function named quadratic which receives 3 double parameters a , b , c . If value of a is 0 then function prints the message "no solution for a=0"

  Write script to declare and sets variable equal to balance

Write a script that declares and sets a variable that's equal to the total outstanding balance due. If that balance is greater than $10,000.00, the script should return a result set consisting of VendorName.

  Hierarchy of processes

Write a program that creates a hierarchy of processes using the fork() system call.

  Explain about lexical analyzer

Explain about Lexical Analyzer

  Write program to calculate integer part of quotient

Write program segments that accomplish each of the following tasks:Calculate the integer part of the quotient when integer a is divided by integer. Calculate the integer remainder when integer a is divided by integer b.

  Creating printstream object using dos

Create a PrintStream object using dos and assign the resulting reference to ps, a PrintStream variable that has already been declared.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd