Starting Out with Python (4th Edition)
4th Edition
ISBN: 9780134444321
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 10.3, Problem 13CP
Program Plan Intro
Instance attribute:
- • An instance has its own set of data attributes of a class.
- • To create an attribute, the method uses the parameter “self”.
- • The “self” references the attribute that belongs to a specific object of the class.
- • In the same class, there is a possibility to create many instances. Here, each instance has its own set of attributes.
- • This is called as instance attribute.
- • In the given problem, there will be 10 attributes in memory while creating 10 instances of a class.
- • This is because each instance of a class calls the method for 10 times.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Java OOP
Write a complete address book maintenance application. The user of the program has four options: Add a new person, delete a person, modify the data of a person, and search for a person by giving the name. Use the AddressBook class, either the original one from the chapter or the modified one from the previous exercises. You have to decide how to allow the user to enter the values for a new person, display person information, and so forth.
Suppose that an application declares an array of class objects with the following statement: Employee[] employees = new Employee[9]; Write a loop that creates 10 instances of the class and assigns them to the elements of the array.
Background
Often, data are stored in a very compact but not human-friendly way. Think of how dishes in a menu can be stored in a restaurant database somewhere in the cloud. One way a dish object can be stored is this:
{ "name": "Margherita", "calories": 800, "price": 18.90, "is_vegetarian": "yes", "spicy_level": 2 }
Obviously, this format is not user-readable, so the restaurant's frontend team produced many lines of code to render and display this content in a way that's more understandable to us, the restaurant users.
We have a mini-version of the same task coming up. Given a list of similar complex objects (represented by Python dictionaries), display them in a user-friendly way that we'll define in these instructions.
What is a "dish"?
In this project, one dish item is a dictionary object that is guaranteed to have the following keys:
"name": a string that stores the dish's name.
"calories": an integer representing the calorie intake for one serving of the dish.
"price": a float to…
Chapter 10 Solutions
Starting Out with Python (4th Edition)
Ch. 10.1 - What is an object?Ch. 10.1 - Prob. 2CPCh. 10.1 - Why is an object's internal data usually hidden...Ch. 10.1 - What are public methods? What are private methods?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 - 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...
Knowledge Booster
Similar questions
- When an object is instantiated, the PVM must find space for the object on the ____. Question 16 options: unused memory activation record object heap call stackarrow_forwardObject oriented programming Intellijarrow_forwardComputer Science The goal of this assignment is to create an app that can capture, tag, save, and retrieve photos on your smartphone.Capture: When clicked, it takes a picture and shows a thumbnail image. Tag: A user can type multiple tags (separated by a “;”). Save: When clicked, it saves the photo in a database along with the tags. Load: A user can specify one or more tags. Your app will find and show the first photo that had any of those tags. When there are multiple photos matching the criteria, the App should have an UI element to show them one by one, e.g., when the user slides a slider.arrow_forward
- Language: C++ Subject: OOP Task:You have to write a program to store information of university students. There can be many students in university, so you can make a Student class and objects of class Student to store information. The university is interested in storing information about student’s name, enrollment, department, class, CGPA and gender. You can store this information as data member values for each object. But as you already know you cannot directly access data members of a class, so you need to make member functions to access data members. You can make as many member functions as you want. There are no restrictions. The University is interested in knowing the student’sname with highest CGPA in a specific class. For example if you entered information of 10 students from class BSIT 2 and information of 5 students from class BSIT 3, and it is asked to find name of student with highest CGPA in BSIT 2 then your program must be able to find details of highest CGPA student from…arrow_forwardTask 3: Constant data can also be declared as a Java interface. Any class that implements such an interface can use the constants declared in it without any qualifications. Redesign the example application with the ConstantDataManager as an interface. Use below class diagram for help. Address save () | > ✓ ConstantDataManager final ACCOUNT_DATA_FILE:String ="ACCOUNT.TXT" final VALID_MIN_LNAME_LEN: int =2 save () final ADDRESS_DATA_FILE:String = "ADDRESS.TXT" final VALID_ST_LEN: int =2 final VALID_ZIP_CHARS: String = "0123456789" final DEFAULT_COUNTRY: String ="USA" final CC_DATA_FILE:String = "CC.TXT" final VALID_CC_CHARS: String = "0123456789" final MASTER: String = "MASTER" final VISA: String ="VISA" final DISCOVER: String ="DISCOVER" | > Credit Card save () > Account save ()arrow_forwardWritten in Python It should have an init method that takes two values and uses them to initialize the data members. It should have a get_age method. Docstrings for modules, functions, classes, and methodsarrow_forward
- class Pt: def init_(self, x, y): self.x X P(3,4) self.y = y def _str__(self): x, y = self.x, self.y return f'P({x},{y})' True 18 # add coordinate-wise def add_(self, other): nx = 13 14 ny = 15 16 return 17 Pt(1, 1) b = Pt (2, 3) с %3D а + b d = b + Pt(5, 6) print (c) print ( isinstance (d, Pt)) print (d) %3Darrow_forwardComputer Science Help with C# programming in Microsoft Visual Studio: You will be creating a program that uses a GUI to allow the user to enter information about an employee. In addition to the main class you create, there will also be four additional classes named fileOutput, baseEmployee, superEmployee and advancedEmployee which you will have to create. For this problem, the baseEmployee class will need to accept user input for a name, email and address for a base employee. The advancedEmployee class should be able to extend the baseEmployee, by allowing an hourly rate and hours worked to be entered. Hours worked must be in the range of 0 to 80 and hourly rate is in the range of 10 to 42.50. The superEmployee class will then extend the advancedEmployee class and allow permission level of high, medium or low to be entered, along with their office number. The program should show a radio button that allows the user to choose whether or not the user is a base employee, advanced…arrow_forward7. Employee Management System This exercise assumes you have created the Employee class for Programming Exercise 4. Create a program that stores Employee objects in a dictionary. Use the employee ID number as the key. The program should present a menu that lets the user perform the following actions: Look up an employee in the dictionary Add a new employee to the dictionary Change an existing employee’s name, department, and job title in the dictionary Delete an employee from the dictionary Quit the program When the program ends, it should pickle the dictionary and save it to a file. Each time the program starts, it should try to load the pickled dictionary from the file. If the file does not exist, the program should start with an empty dictionary.arrow_forward
- LabProgram.java:8: error: class HorseDatabase is public, should be declared in a file named HorseDatabase.java public class HorseDatabase { ^ 1 error Complete the Java program to create a Horse table, insert one row, and display the row. The main program calls four methods: createConnection() creates a connection to the database.createTable() creates the Horse table.insertHorse() inserts one row into Horse.selectAllHorses() outputs all Horse rows.Complete all four methods. Method parameters are described in the template. Do not modify the main program. The Horse table should have five columns, with the following names, data types, constraints, and values: Name Data type Constraints ValueId integer primary key, not null 1Name text 'Babe'Breed text 'Quarter horse'Height double 15.3BirthDate text '2015-02-10'The program output should be: All horses:(1, 'Babe', 'Quarter Horse', 15.3, '2015-02-10')This lab uses the SQLite database…arrow_forwardWorkArea 1st object 2nd object 3rd object 1- Write the code that declares an array of Rectangle objects, called rectangles, and stores in it three objects with the following data: length width 20 25 30 10 15 30 Area of object 1: 200 Area of object 2: 375 Area of object 3: 900 Interactive Session ? 2- Write the code of a for loop that displays the areas of n objects from the rectangles array you declared in the previous task. The output of the for loop. when n = 3, should look like this: Note: Make sure to use the integer n in your for loop. Workbench Additional Notes: Regarding your code's standard output, CodeLab will ignore case errors and will ignore whitespace (tabs, spaces, newlines) altogether. Visible newlines 0 00 0? 0! 0x 1- Visible whitespace MacBook Air Display stdin ✔Display stdout Millarrow_forwardComputer Science JAVASCRIPT .xlsx parser I need to write a public class that reads an .xlsx file and returns an array of data in javascript. The array would be all of the data inside of the file. The file itself is going to be inside of a folder(downloadedFIles) inside of my project. So the public class will need to account for that.arrow_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
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