Starting Out with Python (3rd Edition)
3rd Edition
ISBN: 9780133582734
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 10, Problem 9MC
If a class has a method named _ _str_ _ , which of these is a way to call the method?
a. you call it like any other method: object._ _str_ _ ()
b. by passing an instance of the class to the built in str function
c. the method is automatically called when the object is created
d. by passing an instance of the class to the built-in state function
Expert Solution & Answer
Learn your wayIncludes step-by-step video
schedule04:03
Students have asked these similar questions
Summary
In this lab, you create a derived class from a base class, and then use the derived class in a Python program. The program should create two Motorcycle objects, and then set the Motorcycle’s speed, accelerate the Motorcycle object, and check its sidecar status.
Instructions
Open the file named Motorcycle.py.
Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class __init()__ method inside the Motorcycle class's __init()__ method.
In theMotorcycle class, create an attribute named sidecar.
Write a public set method to set the value for sidecar.
Write a public get method to retrieve the value of sidecar.
Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum speed: "This motorcycle cannot go that fast".
Open the file named MyMotorcycleClassProgram.py.
In the…
QUESTION 10
_____ is used to create an object.
A.
In-built functions
B.
constructor
C.
class
D.
User-defined functions
Write a C++ program that does the following:
Create a class called Student
This class has the following private attributes:
• Name
• Age
• GPA
This class has the following methods:
• Default constructor
• Non-default constructor that will initialize all the above attributes
• Set/Get method for each of the above attributes
• DisplayStudent that will print the information for the student all three values on the same line with proper spacing
• Destructor method that will print a message that the object has been deleted
Your main function should do the following
o Ask the user how many students to create
• Create an array of objects of type Student (studentArr)
o Call a function called acceptStudentinfo.This function will accept the array along with any needed parameters to allow the user to enter the
values for the different students
o Call a function called displayStudentlnfo. This function will accept the array along with any needed parameters to display the content of all
students
•…
Chapter 10 Solutions
Starting Out with Python (3rd Edition)
Ch. 10.2 - You hear someone make the following comment: "A...Ch. 10.2 - In this chapter, we use the metaphor of a cookie...Ch. 10.2 - What is the purpose of the _ _init_ _ method? When...Ch. 10.2 - Prob. 8CPCh. 10.2 - In a Python class, how do you hide an attribute...Ch. 10.2 - What is the purpose of the _ _str_ _ method?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 - What is an object?Ch. 10.4 - Prob. 2CPCh. 10.4 - Why is an object's internal data usually hidden...Ch. 10.4 - What are public methods? What are private methods?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 - 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
Write a program to print the value of EOF.
C Programming Language
_______ local variables retain their value between function calls.
Starting Out with C++ from Control Structures to Objects (8th Edition)
3.12 (Date Create a class called Date that includes three pieces Of information as data
members—a month (type ...
C++ How to Program (10th Edition)
Write a complete Java program that reads one line of text containing exactly three wordsseparated by any kind o...
Java: An Introduction to Problem Solving and Programming (8th Edition)
Write an SQL query to list each customer who bought at least one product that belongs to product line Basic in ...
Modern Database Management (12th Edition)
What is the total serial transfer time for the eight bits in Figure 1-62? What is the total parallel transfer t...
Digital Fundamentals (11th Edition)
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
- T/F: Instance variables are shared by all the instances of the class. T/F: The scope of instance and static variables is the entire class. They can be declared anywhere inside a class. T/F: To declare static variables, constants, and methods, use the static modifier.arrow_forwardThis function is used to check whether an object is an instance of a specific class or a subclass of that class. a. isinstance b. isobject c. isreference d. _ _str_ _arrow_forwardA. Car Class Create a Python Program where you write a class named Car that has the following data attributes: • _ _year_model (for the car's year model) • __make (for the make of the car) • _ _speed (for the car's current speed) The Car class should have an _init_ method that accepts the car's year model and make as arguments. These values should be assigned to the object's _year_model and make data attributes. It should also assign 0 to the __speed data attribute. The class should also have the following methods: accelerate() The accelerate method should add 5 to the speed data attribute each time it is called. brake() The brake method should subtract 5 from the speed data attribute each time it is called. • get_speed() The get_speed method should return the current speed. Next, design a program that creates a Car object then calls the accelerate method five times. After each call to the accelerate method, get the current speed of the car and display it. Then call the brake method…arrow_forward
- 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…arrow_forwardPython program for this project: Patient Charges Write a class named Patient that has attributes for the following data: First name, middle name, and last name Address, city, state, and ZIP code Phone number Name and phone number of emergency contact The Patient class’s _ _init_ _ method should accept an argument for each attribute. The Patient class should also have accessor and mutator methods for each attribute. Next, write a class named Procedure that represents a medical procedure that has been performed on a patient. The Procedure class should have attributes for the following data: Name of the procedure Date of the procedure Name of the practitioner who performed the procedure Charges for the procedure The Procedure class’s _ _init_ _ method should accept an argument for each attribute. The Procedure class should also have accessor and mutator methods for each attribute. Next, write a program that creates an instance of the Patient class, initialized with sample data. Then,…arrow_forwardclassname.py -> using "sys.argv" ● Create a program called classname.py. The program should define a class called person that has one method called hello, and one attribute called name, which represents the name of the person. ● The hello method should print the following string to the screen: ‘My name is ____ and I am a _____’ where: ○ The first blank should be the name attribute ○ The second blank should be the name of the class ○ The above blanks should NOT be manually printed (ex. print(‘My name is Greg and I am a person’)) ● After defining the class, there are three things you must do: 1. Instantiate an object of the class 2. Run the hello method of the instantiated object a. (e.g., Greg.hello()) 3. For grading purposes, you must also print the name of the class so I can be sure you’ve created a class a. (The expected output is )arrow_forward
- Which of the following applies to destructors? Choose all that apply. A.) A destructor is a function that automatically gets called when an object of its class falls out of scope. B.) If you create a copy constructor, you must also create a copy destructor. C.) A destructor cannot take any parameters. D.) A destructor cannot return a value.arrow_forwardThe __________ declares that a derived class is allowed to override a method. a. void keyword b. protected keyword c. base keyword d. virtual keywordarrow_forwardWrite a class called Game that contains a video game’s name, genre, and difficulty Level. 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 difficulty Level between 1-10 (inclusive). Seed this random number generator with 100. Next, dynamically create a Game object (remember that this requires the use of the “new”…arrow_forward
- Write a C++ program that does the following: Create a class called Automobile This class has the following private attributes: model year mileage This class has the following methods: Default constructor Non-default constructor that will initialize all the above attributes Set/Get method for each of the above attributes displayAuto that will print the information for the Automobile all three attributes on the same line with proper spacing Destructor method that will print a message that the object has been deleted Create a class called Inventory This class has the following private attributes: count: This represents how many current automobiles in the inventory maxCount: This represents the maximum number of automobiles that can be stored autoPtr: A pointer to Automobile objects. This class has the following methods: Default constructor (count is 0, maxCount will be 10, autoPtr is NULL) Non-default constructor that will have one integer parameter count will be initialized…arrow_forwardT/F A method defined in a class can access the class' instance data without needing to pass them as parameters or declare them as local variables.arrow_forwardAn object is an instance of a * program class method data Which of the following statements are true? * A default constructor is provided automatically if no constructors are explicitly declared in the class. At least one constructor must always be defined explicitly. Every class has a default constructor. The default constructor always return True/False O All of the abovearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENTEBK JAVA PROGRAMMINGComputer ScienceISBN:9781305480537Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrProgramming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:CengageC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
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