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

  Describe the purpose of the hierarchical nature of

q1. explain the purpose of the hierarchical nature of traditional structured design.q2. describe what kinds of systems

  Maze program

Maze program. In this assignment you will represent a maze with a binary tree. . The starting point is node N and the ending point is node Z.

  Find the retail price for each product

Your program should use a switch statement to find the retail price for each product - Use a sentinel-controlled loop to decide when the program should stop looping and show the final output.

  Determine the largest of these ten values

Write a small loop that will determine the largest of these ten values. When the loop completes, the largest number will be in accumulator

  Implement a graphics system that has classes

Implement a graphics System that has classes for various figures: rectangles, squares, triangles and circles. A rectangle has data members height, width, color , and center point. A square has center point and an edge and color

  Assume that a text file named text1txt contains text

Assume that a text file named text1.txt already contains some text written into it, write a function named vowelwords(), that reads the file text1.txt and create a new file named text2.txt,

  Create a detailed ipo chart

Create a detailed IPO chart that also includes the algorithm from the attached c++ source code.

  Written a code that parses through a file reading

written a code that parses through a file reading it line by line and splitting it into tokens by white space. But I want a pair of single quotes to be one token, not how many words are in it

  Generate mathematical problems based on the difficulty level

Generate mathematical problems based on the difficulty level selected. You must implement the following five levels of difficulty

  Create a graphical calculator with buttons that can add

create a graphical calculator with buttons that can add subtract multiply divide - sin cos tan clear and modulus.write

  The minimal spanning tree algorithm

discuss the minimal spanning tree algorithm. Describe the advantages and disadvantages of this algorithm. List the circumstances best suited for the minimal spanning tree algorithm.

  Using visual c++ and your opengl configured environment

Using Visual C++ and your OpenGL configured environment, write an application that uses OpenGL Raster transformations to draw a triangle of your choice of size, location and color, and then rotate that triangle by 90 degrees and scale it by a fact..

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