Design a fraction class

Assignment Help C/C++ Programming
Reference no: EM13314288

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: EM13314288

Questions Cloud

Determine corresponding increase in the diameter of vessel : a spherical pressure vessel has an outer diameter of 10 ft and a wall thickness of 0.5 in. knowing that for the steel used ?all= 12 ski, E= 29 x 10^6 psi, and v= 0.29, determine (a) the allowable gage pressure,
State all of the statements that are true for so2 : Check all of the statements that are true for SO2. The domain geometry is trigonal planar. The molecular geometry is bent. The bond angle is 90 degrees
Determine the maximum force p that can be applied : The coefficient of static friction between each crate and the ground is 0.25 The crates are next to each other connected by a rope and then from the other end one has a P force going up at an angle of 30 degrees
Draw at a context diagram and a level-0 diagram : Draw at a context diagram and a level-0 diagram. In drawing these diagrams, if you discover that the narrative is incomplete, make up reasonable explanations to complete the story. Provide these extra explanations along with the diagrams.
Design a fraction class : 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 multiplica..
Define assumptions are reasonable ksp is the as solubility : The molar solubility of AgCl in 6.5 x 10^-3 M AgNO3 is 2.5 x 10^-8 M. In deriving Ksp from these data, which of the following assumptions are reasonable? A) Ksp is the same as solubility.
How much quantity does each individual firm produce : How much quantity does each individual firm produce? Using your answers from a) and b), determine if an individual firm is making a profit or loss and calculate this amount.
Find the magnitude of the acceleration of the jogger : A jogger accelerates from rest to 2.12 m/s in 3.34 s. A car accelerates from 24.1 to 38.6 m/s also in 3.34 s.  Find the magnitude of the acceleration of the jogger
Explain the balanced equation for the hydration of cuso4 : Write the balanced equation for the hydration of CuSO4. Indicate the physical states using the abbreviations (s), (l), or (g) for solid, liquid, or gas, respectively

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program that stores a series of numbers in a binary tree

Write a program that stores a series of numbers in a binary tree

  Supposed to swap numbers

The program is supposed to swap numbers, but I am stuck something is wrong! It does not swap them it repeats the second number, please help to fix! Thanks, this is in C++.

  Program to output value of tenth component of array

Write a C++ statements to perform the following: Set value of fourth component of array alpha to three times  value of eight component minus 57.

  Change this code to read in strings from a text file

code takes in a string from a user, checks if the paranthesis are ballanced (as defined by my class) and also returns the variable from my line (also from my class). All like to change this code to read in strings from a text file (each line is a str..

  Develop the implementation file student.cpp

The data fields have self explanatory identifiers, and their meaning should be clear from the Introduction.

  Create a program that displays the number of days in a month

Create a program that displays the number of days in a month. Use a 12-element one-dimensional array to store the number of days in each month (use 28 for the number of days in February).

  Longest increasing subsequence problem

Write a computer program to solve the Longest Increasing Subsequence problem.Your program should read input from a text file (one value per line

  Write a program to find out all 3-digit

Write a program to find out all 3-digit Narcissistic number. A number n is a 3-digit Narcissistic number if: (a) 100   n   999, (b) The sum of its own digits each raised to the power of 3 equals to itself. For example: 153 is a Narcissistic number ..

  Takes 100 number in an array

Write a program in c++ that takes 100 number in an array and add them and print the sum

  Define the class bankaccount

Define the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder's name (string), account number (int), account type (string, checking/saving), balance (double),..

  This program will simulate the game of hearts

This program will simulate the game of Hearts, which is a four-player trick-taking game using any ordinary deck of playing cards. Each player is dealt thirteen cards. Whoever is dealt the Two of Clubs must lead it to the first trick. Each person p..

  Calculate the trajectory of a soccer ball

Write a program to calculate the trajectory (flight path) of a soccer ball

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