Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
bartleby

Concept explainers

bartleby

Videos

Textbook Question
Book Icon
Chapter 10, Problem 8PE

Cash Register

This exercise assumes you have created the RetailItem class for Programming Exercise 5. Create a CashRegister class that can be used with the RetailItem class. The Cash Register class should be able to internally keep a list of RetailItem objects. The class should have the following methods:

■ A method named purchase_item that accepts a RetailItem object as an argument. Each time the purchase_item method is called, the RetailItem object that is passed as an argument should be added to the list.

■ A method named get_total: that returns the total price of all the RetailItem objects stored in the CashRegister object’s internal list.

■ A method named show_items that displays data about the RetailItem objects stored in the CashRegister object’s internal list.

■ A method named clear that should clear the CashRegister object’s internal list.

Demonstrate the CashRegister class in a program that allows the user to select several items for purchase. When the user is ready to check out, the program should display a list of all the items he or she has selected for purchase, as well as the total price.

Blurred answer
Students have asked these similar questions
Dynamic Games Instructions: Write a class called Game that contains a video game’s name, genre, and difficultyLevel.  Include a default constructor and destructor for the class.  The constructor should print out the following message:  “Creating a new game”.  The destructor should print out the following message:  “In the Game destructor.”  Include appropriate get/set functions for the class. In main(), prompt the user to enter the number of games he or she has played in the past year.  Dynamically create a built-in array based on this number (not a vector or object of the array class) to hold pointers to Game objects. Construct a loop in main() that executes once for each of the number of games that the user indicated.  Within this loop, ask the user to enter the name and genre of each game.  Using a random number generator, generate a difficultyLevel between 1-10 (inclusive). Seed this random number generator with 100.  Next, dynamically create a Game object (remember that this…
Pet ClassDesign a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird". age: The age field holds the pet’s age. The Pet class should also have the following methods: setName: The setName method stores a value in the name setType: The setType method stores a value in the type setAge: The setAge method stores a value in the age getName: The getName method returns the value of the name getType: The getType method returns the value of the type getAge: The getAge method returns the value of the age Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen.  *** I need help…
Pet ClassDesign a class named Pet, which should have the following fields: name: The name field holds the name of a pet. type: The type field holds the type of animal that a pet is. Example values are "Dog", "Cat", and "Bird". age: The age field holds the pet’s age. The Pet class should also have the following methods: setName: The setName method stores a value in the name setType: The setType method stores a value in the type setAge: The setAge method stores a value in the age getName: The getName method returns the value of the name getType: The getType method returns the value of the type getAge: The getAge method returns the value of the age Once you have designed the class, design a program that creates an object of the class and prompts the user to enter the name, type, and age of his or her pet. This data should be stored in the object. Use the object’s accessor methods to retrieve the pet’s name, type, and age and display this data on the screen. The output Should be…

Chapter 10 Solutions

Starting Out with Python (4th Edition)

Ch. 10.2 - Prob. 11CPCh. 10.3 - What is an instance attribute?Ch. 10.3 - Prob. 13CPCh. 10.3 - What is an accessor method? What is a mutator...Ch. 10.4 - Prob. 15CPCh. 10.4 - Prob. 16CPCh. 10.4 - When designing an object-oriented application, who...Ch. 10.4 - How do you identify the potential classes in a...Ch. 10.4 - What are a classs responsibilities?Ch. 10.4 - What two question should you ask to determine a...Ch. 10.4 - Will all of a class's action always be directly...Ch. 10 - The _______ programming practice is centered on...Ch. 10 - The ___________ programming practice is centered...Ch. 10 - A(n) _____ is a component of a class that...Ch. 10 - Prob. 4MCCh. 10 - By doing this, you can hide a classs attribute...Ch. 10 - Prob. 6MCCh. 10 - A(n) ________ method stores a value in a data...Ch. 10 - Prob. 8MCCh. 10 - If a class has a method named _ _str_ _ , which of...Ch. 10 - A set of standard diagrams for graphically...Ch. 10 - In one approach to identifying the classes in a...Ch. 10 - Prob. 12MCCh. 10 - The practice of procedural programming is centered...Ch. 10 - Object reusability has been a factor in the...Ch. 10 - It is a common practice in object-oriented...Ch. 10 - Prob. 4TFCh. 10 - Starting an attribute name with two underscores...Ch. 10 - You cannot directly call the _ _ str _ _ method.Ch. 10 - One way to find the classes needed for an...Ch. 10 - Prob. 1SACh. 10 - Why should an object's data attributes be hidden...Ch. 10 - What is the difference between a class and an...Ch. 10 - The following statement calls an object's method....Ch. 10 - Prob. 5SACh. 10 - In a Python class, how do you hide an attribute...Ch. 10 - Prob. 7SACh. 10 - Suppose my_car is the name of a variable that...Ch. 10 - Prob. 2AWCh. 10 - Look at the following description of a problem...Ch. 10 - Pet Class The Pet class Write a class named Pet,...Ch. 10 - Car Class Write a class named Car that has the...Ch. 10 - Personal Information Class Design a class that...Ch. 10 - Employee Class Write a class named Employee that...Ch. 10 - RetailItem Class Write a class named RetailItem...Ch. 10 - Patient Charges Write a class named Patient that...Ch. 10 - Employee Management System This exercise assumes...Ch. 10 - Cash Register This exercise assumes you have...Ch. 10 - Trivia Game In this programming exercise, you will...

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
    Microsoft Visual C#
    Computer Science
    ISBN:9781337102100
    Author:Joyce, Farrell.
    Publisher:Cengage Learning,
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
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