Create a class called rational for performing arithmetic

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

Rational Class Create a class called Rational for performing arithmetic with fractions. Write a program to test your class.

Use integer variables to represent the private data of the class-the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it's declared. The constructor should contain default values in case no initializers are provided and should store the fraction in reduced form. For example, the fraction 2/4would be stored in the object as 1 in the numerator and 2 in the denominator. Provide public member functions that perform each of the following tasks:

a. Adding two Rational numbers. The result should be stored in reduced form.

b. Subtracting two Rational numbers. The result should be stored in reduced form.

c. Multiplying two Rational numbers. The result should be stored in reduced form.

d. Dividing two Rational numbers. The result should be stored in reduced form.

e. Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator.

f. Printing Rational numbers in floating-point format.

//Rational.h
#ifndef RATIONAL_H
#define RATIONAL_H
Class Rational
{
public:
Rational(int=0,int=1);//default constructor
Rational addition (const Rational&);//function addition
Rational subtraction (const Rational&);//function subtraction
Rational multiplication(const Rational&);//function multi.
Rational division (const Rational&);//function division
Void printRational ();//print rational format
Void printRationalAsDouble ();//print rational as double format
private:
int numerator;//integer numerator
int denominator;//integer denominator
void reduction();//utility function
}; //end class Rational
#endif

Reference no: EM13757882

Questions Cloud

Choose google technologies would you like to research on : Find and choose 5 Google technologies would you like to research on. Share one interesting finding about each technology that you have chosen
Achieve through the use of its antitrust policy : What are the differences among horizontal, vertical, and conglomerate mergers? What does the U.S. government hope to achieve through the use of its antitrust policy?
How do delay jitter and packet loss affect voip calls : What is the difference between the SIP and RTP protocols used with VoIP? How do delay, jitter, and packet loss affect VoIP calls
Investors relations section of the website : Based on your review of the annual report and the Investors Relations section of the website for the company you selected for this week's discussion response in addition to Yahoo Finance, does the company pay cash dividends regularly?
Create a class called rational for performing arithmetic : Rational Class Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private data of the class-the numerator and the denominator. Provide a constructor th..
How environmental and visual supports needed in the school : analyze and discuss how environmental and visual supports may be needed in the home, school, and community and give an example of a support that may be utilized in each of these settings.
User documentation and system documentation : Explain the difference between user documentation and system documentation. What are the reasons underlying the popularity of online documentation? Are there any limitations to online documentation? Explain
What are the impacts of innovation and technology : What are the impacts of innovation and technology on the cost of production? How does technology affect market structure and real-world competition?
What are some ways to offer children literature choices : What are some ways to offer children literature choices? Also explain why teachers should help young children make responsible choices regarding literature and how you can do this.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Evaluate the expression

How many times will "jump" be displayed in the following program segment? If the loop doesn't terminate, write "infinite" Evaluate the expression.

  How would you put a empty space between output

How would you put a empty space between output, right now it prints 6 rows but how do i add a space or a "\n" for example row1 row2 row3

  Make a class constructor that initializes a customer

Make a class constructor that initializes a customer with a name, number, and order size.Make class member functions to print each of: name, number, and order size.

  Write a program that displays the size of a population

Write a function that calculates the size of the population after a year. To calculate the new population after one year.

  Explain one 1 scenario not mentioned in the textbook in

q1. describe one 1 scenario not mentioned in the textbook in which it would be advantageous for you to use a definite

  Write a program which has a base process which communicates

write a program which has a base process which communicates with child processes acting as bombers that it

  Once the user enters a 0

Once the user enters a 0 you will exit the loop, close the file and execute the code as previously designed until you have displayed all of the scores and the average handicap.

  Prepare the weighted scoring model for three exams

Prepare the weighted scoring model. Final grades are based on three exams worth 15%, 20%, and 25%, respectively; homework is worth 20%.

  What is wrong with this function

What is wrong with this function? Can you find problem in this code?

  Ruby implement primitive types

How does Ruby implement primitive types, such as those for integer and floating-point data?  3-What is the single most important practical difference between Smalltalk and C++?

  Inserts a node with info value x

Complete the code for a function that inserts a node with info      value x before, and a node with info value zafter,each node with      info value y in a linked list with first node pointer p.

  Find the pairs in any given matrix

write a c program which will find the pairs in any given matrix, whose sum of pairs are 10.

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