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

  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