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

  Write a hexadecimal integer literal

Write a hexadecimal integer literal representing the value fifteen.

  To deal with deadlocks we can either use prevention or

to deal with deadlocks we can either use prevention or avoidance or detection followed by recovery. but which is a

  The two-dimensional array

1. Given the two-dimensional array declared by the following statement int myArray[4][3] = {{2,4,6},{1,8,10},{3,5,7},[9,11,13}}; what is the value of myArray[1][2]

  calculates the average rainfall

Write a program that calculates the average rainfall for three months. The program should ask the user to enter the name of each month, such as June or July, and the amount of rain (in millimeters) that fell each month.

  Digital signal processing - employ state-space models

you will program, document, and test a zero-crossing detector, with hysteresis for robustness, that also counts the number of samples between zero crossings.

  Write a program that will represent an axis-aligned

Write a program that will represent an axis-aligned right triangle in the x-y plane as a Class. A right triangle has a right angle (90-degree angle) and two sides adjacent to the right angle, called legs. See http://en.wikipedia.org/wiki/Right_tri..

  Write a program that reads in an integer

Write a program that prompts the user for a measurement in meters, and then converts it in to miles, feet, and inches.

  Where s is any string

Write a function detab(s, stop), where s is any string, and stop is a positive integer called tabstop size. This function should return a string which is like s.

  Allocate array of n doubles and assign the resulting pointer

The variable dp is to refer to an array of double. Assuming the integer variable n has been assigned a value, declare dp appropriately, allocate an array of n doubles and assign the resulting pointer to dp.

  Accept positive and negative numbers in its input sequence

the program must accept positive and negative numbers in its input sequence, and ?nd the largest and smallestof the numbers entered whether they are all positive, all negative, or a combination of both positive and negative.

  Use a switch statement

Use a switch statement to write a program that prompts user to enter an character.

  Prepare a program for a bank that allows the user

Prepare a program for a bank that allows the user to enter an amount of money in cents. Show the number of whole dollars the bank will give the customer in exchange.

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