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 a class called vehicle

Create a class called Vehicle that has the manufacturer's name (type String), number of cylinders in the engine (type int), and owner (type Person given below).

  What is the output of the loop as it is written

Correct the syntax of the loop so that the logic of the corrected loop corresponds to the formatting of the original loop. What is the output of the corrected loop?

  Waiting time is the diff b/w the arrival time and simulation

The Server removes a customer from the queue then generates a random number between 1 and 5 to simulate a transaction type i.e. Open a checking account etc.

  Implementation of classes

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

  Mark the following statements as true or false

Mark the following statements as true or false.

  Write cpp program that processes the data of retail company

Write a C++ program that processes the data of a retail company with following requirements: Define a new data type (struct) ofCustomer, with following members

  Execute the next line which is enter your last name

C++ in VS and I'm trying to run the following program. As soon as I put in my name after the 2nd cout statement, the program ends.

  How many times is the copy constructor called

In the subsequent code how many times is the copy constructor called in the given code?

  Write a c program that copies the contents of one file

write a c program that copiest the contents of one file to a destination file. This program works by first prompting the user for the name of the source file and destination file.

  Collection of course components and weighting schemes

Define the data type that represents the collection of course components and weighting schemes and break down the required functionality into modular, reusable functions

  Write unique, simple function in c++

Write unique, simple function in C++. Be sure you provide code that calls the function also. Visual Studio

  Formulate an linear programming model

1. Formulate an Linear Programming model for this problem 2. Create a spreadsheet model for this problem and solve it using Solver 3. What is the optimal solution?

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