C How to Program (8th Edition)
C How to Program (8th Edition)
8th Edition
ISBN: 9780133976892
Author: Paul J. Deitel, Harvey Deitel
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 17, Problem 17.6E

(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 4

would 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:

  1. Adding two Rational numbers. The result should be stored in reduced form.
  2. Subtracting two Rational numbers. The result should be stored in reduced form.
  3. Multiplying two Rational numbers. The result should be stored in reduced form.
  4. Dividing two Rational numbers. The result should be stored in reduced form.
  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–point format.

Blurred answer
Students have asked these similar questions
Please fill in the blanks for the following statements: To define a class use the keyword ________________ followed by the name of the class.
Problem 1: Java programComplete the Clothing class, the class should have the following instance variables, constructor(s) and instance methods:- An instance variable of type double named price.- An instance variable of type String named type.- An instance variable of type String named size.- A default “no-arg” constructor that sets the price to 29.9, the type to “TShirt” and the size to “Medium”. - An overloaded constructor that takes three parameters and set the instance variables accordingly. - A method named increasePrice that takes no parameters and returns no value, the method increases the instance variable price by 5.- An overloaded method increasePrice that takes a double parameter xand returns no value, the method increases the instance variable price by the value of parameter x.- A method named details which takes no parameters, returns no value, the method prints the Clothing item details in the format shown in the sample output.- Your output should look exactly the same…
Instructions-Java Assignment is to define a class named Address. The Address class will have three private instance variables: an int named street_number a String named street_name and a String named state. Write three constructors for the Address class: an empty constructor (no input parameters) that initializes the three instance variables with default values of your choice, a constructor that takes the street values as input but defaults the state to "Arizona", and a constructor that takes all three pieces of information as input Next create a driver class named Main.java. Put public static void main here and test out your class by creating three instances of Address, one using each of the constructors. You can choose the particular address values that are used. I recommend you make them up and do not use actual addresses. Run your code to make sure it works.  Next add the following public methods to the Address class and test them from main as you go: Write getters and…

Additional Engineering Textbook Solutions

Find more solutions based on key concepts
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY