Develop a class Volume in Python that stores the volume for a stereo that has a value between 0 and 11. Usage of the class is listed below the problem descriptions.  Throughout the class you must guarantee that:

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 6PE
icon
Related questions
Question
  1. Develop a class Volume in Python that stores the volume for a stereo that has a value between 0 and 11. Usage of the class is listed below the problem descriptions.  Throughout the class you must guarantee that:

    • The numeric value of the Volume is set to a number between 0 and 11. Any attempt to set the value to greater than 11 will set it to 11 instead, any attempt to set a negative value will instead set it to 0.
    • This applies to the following methods below: __init__, set, up, down

You must write the following methods:

  • __init__ - constructor. Construct a Volume that is set to a given numeric value, or, if no number given, defaults the value to 0.   (Subject to 0 <= vol <=11 constraint above.)
  • __repr__ - converts Volume to a str for display, see runs below.
  • set – sets the volume to the specified argument (Subject to 0 <= vol <=11 constraint above.)
  • get – returns the numeric value of the Volume
  • up – given a numeric amount, increases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
  • down – given a numeric amount, decreases the Volume by that amount. (Subject to 0 <= vol <=11 constraint above.)
  • __eq__ - implements the operator ==.   Returns True if the two Volumes have the same value and False
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 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
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT