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. Provide public member functions that perform each of the following tasks: Adding two Rational numbers. The result should be stored in reduced Subtracting two Rational numbers. The result should be stored in reduced Multiplying two Rational numbers. The result should be stored in reduced Dividing two Rational numbers. The result should be stored in reduced Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator. Printing Rational numbers in floating-pointformat

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter11: Inheritance And Composition
Section: Chapter Questions
Problem 5PE: Using classes, design an online address book to keep track of the names, addresses, phone numbers,...
icon
Related questions
Question
100%

 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.

Provide public member functions that perform each of the following tasks:

  1. Adding two Rational numbers. The result should be stored in reduced
  2. Subtracting two Rational numbers. The result should be stored in reduced
  3. Multiplying two Rational numbers. The result should be stored in reduced
  4. Dividing two Rational numbers. The result should be stored in reduced
  5. Printing Rational numbers in the form a/b, where a is the numerator and b is the denominator.
  6. Printing Rational numbers in floating-pointformat

 

 

 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Data members
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,