Design a c++ program containing a class fraction.

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

Design a C++ program containing a class Fraction. The class data should have two variables numerator and denominator, both of type integer, to represent the fraction numerator/denominator. The fraction representation within the object must allow no simplification. That is, the numerator and denominator have to have no common divisor different from 1. For example, the fraction 4/6 must be represented as 2/3.

Be sure to implement the following features:

1. The class constructor must take two integers numbers (numerator and denominator).

2. For negative fractions, the numerator must be negative and denominator must be positive.

3. Include the method simplify that takes two numbers and returns a fraction object (representing a fraction that cannot be simplified).

4. Include a method add that takes two fraction objects and returns their sum (as a fraction object).

5. Include a method diff that takes two fraction objects and returns their difference (as a fraction object).

6. Implement overloaded operators + and - for addition and subtraction of fractions.

7. Implement overloaded comparison operators == and != for comparing two fraction objects.

Test your class in the main() method by creating several fractions, adding them, subtracting them, and printing the result by using the / sign (e.g., 2/3), not as decimal fractions. Also demonstrate usage of the overloaded operators.

Reference no: EM13937643

Questions Cloud

Write a c++ code for sum of two large integers : Write a C++ code for sum of two large integers. User have to enter two integers one by one.
Require an increase in net working capital : McGilla Golf has decided to sell a new line of golf clubs. The length of this project is seven years. The company has spent $1796356 on research and development for the new clubs. The plant and equipment required will cost $28141541 and will be depre..
Prepare shareholders equity section of marbles balance sheet : On October 1, 2006, Marble Company had 400,000 shares of $2 par common stock issued and outstanding. Prepare the shareholders' equity section of Marble's balance sheet at September 30, 2007.
What is the companys expected growth rate : Kahn Inc. has a target capital structure of 50% common equity and 50% debt to fund its $10 billion in operating assets. Furthermore, Kahn Inc. has a WACC of 14%, a before-tax cost of debt of 11%, and a tax rate of 40%. What is the company's expected ..
Design a c++ program containing a class fraction. : Test your class in the main() method by creating several fractions, adding them, subtracting them, and printing the result by using the / sign (e.g., 2/3), not as decimal fractions. Also demonstrate usage of the overloaded operators.
Why is sustained inflation a purely monetary phenomenon : Why is sustained inflation a purely monetary phenomenon? Why is an increase in foreign exchange reserves recorded as a debit (-) item in the balance of payments?
What is initial cost of project including flotation costs : Western Wear is considering a project that requires an initial investment of $260,000. The firm maintains a debt-equity ratio of .40 and has a flotation cost of debt of 8 percent and a flotation cost of equity of 10.5 percent. The firm has sufficient..
What was the average issue price of the stock issued : What was the average issue price of the stock issued during 2007? What was the amount of dividends declared during 2007? Did the company have any treasury shares at the end of 2007?
What is the payback period for this project : McGilla Golf has decided to sell a new line of golf clubs. The length of this project is seven years. The company has spent $1915230 on research and development for the new clubs. The plant and equipment required will cost $28720691 and will be depre..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

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