Absolute C++
6th Edition
ISBN: 9780133970784
Author: Walter Savitch, Kenrick Mock
Publisher: Addison-Wesley
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 6, Problem 5PP
Define a class for a type called Fraction. This class is used to represent a ratio of two integers. Include mutator functions that allow the user to set the numerator and the denominator. Also include a member function that returns the value of the numerator divided by the denominator as a double. Include an additional member function that outputs the value of the fraction reduced to lowest terms. For example, instead of outputting 20/60 the function should output 1/3. This will require finding the greatest common divisor for the numerator and denominator, and then dividing both by that number. Embed your class in a test program.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Quick java class question
Program SpecificationUsing python, design a class named PersonData with the following member variables:
lastName
firstName
address
city
state
zip
phone
Write the appropriate accessor and mutator functions for these member variables. Next, design a class named CustomerData , which is derived from the PersonData class. The CustomerData class should have the following member variables:
customerNumber
mailingList
The customerNumber variable will be used to hold a unique integer for each customer. The mailingList variable should be a bool . It will be set to true if the customer wishes to be on a mailing list, or false if the customer does not wish to be on a mail-ing list. Write appropriate accessor and mutator functions for these member variables.
Next write a program which demonstrates an object of the CustomerData class in a program. Your program MUST use exception handling. You can choose how to implement the exception handling.
Start your program with a welcome message
Make sure…
When you derive a class from an existing class, you
Group of answer choices
can add both new data and new functions.
can add new data, but cannot add new functions.
can add new functions, but cannot add new data.
must add both new data and new functions.
Chapter 6 Solutions
Absolute C++
Ch. 6 - Write a grading program for a class with the...Ch. 6 - Define a class for a type called CounterType. An...Ch. 6 - Write the definition for a class named Gaspump to...Ch. 6 - Define a class for a type called Fraction. This...Ch. 6 - Create a Temperature class that internally stores...Ch. 6 - Do Programming Project 5.18 except use only one...
Knowledge Booster
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
- Mark the following statements as true or false. The member variables of a class must be of the same type. (1) The member functions of a class must be public. (2) A class can have more than one constructor. (5) A class can have more than one destructor. (5) Both constructors and destructors can have parameters. (5)arrow_forward13. Term 1 that is used. by CodeChum Admin Construct a class called Term. It is going to represent a term in polynomial expression. It has an piece of codeinteger coefficient and an exponent. In this case, there is only 1 independent variable that is 'x'..arrow_forwardIn C++arrow_forward
- PS: see image for question.arrow_forwardWrite a class Box having three private data members (width, depth, height) The class has three constructors which are having no parameter – for setting values to zero or null. having three parameters for assigning values to height, width, depth respectively. Overload the above constructor and use this keyword to set the values of width, height & depth. Provide getters/setters for data members. Write a function calculateVolume() which calculates the volume of the box. Write test Application that demonstrates the Box class by calling all the three constructors and method, creating a Create Box object, and then displaying the Box’swidth , height, length and volume .arrow_forwardDefine a Pet class that stores the pet’s name, age, and weight. Add appropriateconstructors, accessor functions, and mutator functions. Also define a functionnamed getLifespan that returns a string with the value “unknown lifespan.” Next, define a Dog class that is derived from Pet. The Dog class should have aprivate member variable named breed that stores the breed of the dog. Add mutator and accessor functions for the breed variable and appropriate constructors.Redefine the getLifespan function to return “Approximately 7 years” if the dog’sweight is over 100 pounds and “Approximately 13 years” if the dog’s weight isunder 100 pounds. Next, define a Rock class that is derived from Pet. Redefine the getLifespanfunction to return “Thousands of years.” Finally, write a test program that creates instances of pet rocks and pet dogs thatexercise the inherited and redefined functions. use c++arrow_forward
- quick and fast plzarrow_forwardWrite a Rectangle class that has the following fields: Length (L): a double - Width (W): a double The class should have the following functions: Constructor: accepts the length (L) and the width (W) of a rectangle as arguments. Constructor: does not take any parameters and initializes the length(L) and width(W) to zero. - A function called getArea which returns the area of the rectangle. A function called getPerimeter which returns the perimeter of the rectangle. {note: The area of a rectangle =L*W, and its perimeter = 2*(L+W) } Then, write a program to ask the user to enter the length and width of a rectangle, and then use the above class to calculate and print the area and perimeter of the rectangle.arrow_forwardDefine a class named StudentGrader that has the following attributes defined within the initialization function: homeworkAvg as float midtermScore as integer finalScore as integer attendance as floata. Define a function named getOverallPctScore(). This function calculates and returns the overall grade score using the following weights for each category:arrow_forward
- Rewrite the calculator program using a class called calculator. Your program will keep asking the user if they want to perform more calculations or quit and will have a function displayMenu to display the different functions e.g .(1 - addition, 2- subtraction, 3- multiplication, 4- division) Your program must have appropriate constructors and member functions to initialize, access, and manipulate the data members as well as : A member function to perform the addition and return the result A member function to perform the subtraction and return the result A member function to perform the multiplication and return the result A member function to perform the division and return the resultarrow_forwardT F Classes are allowed to contain both functions and variables.arrow_forwardC++ Friend function concepts Do not use operator overloading Create a class User with private member variables "id". In the class define a function increment_user_id() which will increment the id and return it as well. Create another method "void show_Id()" to show the id for a particular object. Create a constructor of User class where increment the Id by calling the increment_user_id() method for every new object . Finally create two objects of the class and print their corresponding id's on console.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningC++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Introduction to Classes and Objects - Part 1 (Data Structures & Algorithms #3); Author: CS Dojo;https://www.youtube.com/watch?v=8yjkWGRlUmY;License: Standard YouTube License, CC-BY