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
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…
For this assignment, you need to build a class that contains basic information about students and courses that have those students on the roster. You also need to build a menu that supports basic CRUD functionality for those courses. The requirements are as follows:
The student class should contain the following data about a student:
Name (dynamic char array)
Classification (char)
Major (dynamic char array)
StudentId (can be an int or a dynamic char array)
The course class should contain the following data about a course:
Course Name (dynamic char array)
Course Code (char array of size 7)
Location (char array of size 10)
Roster (dynamic student array)
The menu program should act as a driver program that manages a dynamically allocated array of courses and allows the user to:
Add a course to the list
Add students to a course
Update a course to change any of the data above including edits to students or adding/removing students from the roster
List courses including students in the…
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
- INSTRUCTIONS: All problems should be written using JustBASIC. The code should be typed into the JustBASIC editor and executed. At the end of each solution, you should state whether the code executed and whether it produced correct results. Failure to follow directions will result in a zero for the assignment. 1. 2. 3. Write the beginning of the program that will create five arrays of the type and name listed below. Get the number of movies to be entered into the database from the user. Be sure to initialize the arrays. STRING actorLastName STRING actorFirstName STRING nameOf Movie NUM year OfDebut NUM grossearnings Add to the previously written code the part that will allow the user to populate the arrays. Using the previously written code, add pseudocode that will search for the actor's last name. You will ask the user for the last name to be searched for. You can assume all last names are unique (no repeats). If the name is present, your program will return the string "Target found"…arrow_forwardWhen 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_forwardLanguage: 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_forward
- Project in Java programming language : Choose an enterprise and do a business description of it. 1-2 pages. Create all classes for entities. All classes must have at least a constructor, get and set methods for all private variables and a toString method. Create classes also for connection entities (e.g. orders, reservations, etc.) All information should be saved in files. When opening the program, all information from files must be loaded in array lists. Use an array list for every class. The program must have at least one menu where the user can choose the operations to work. You should at least have one class that inherits from another class. You should have at least one interface that is extended by at least 2 classes. You must use the interface methods in your program. You are allowed to use the GUI for this project. If not use JOptionPane You are allowed to use databases, instead of files.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_forwardException handling allows for the programmer to account for incidences that can go wrong at run time and not crash the program. True False The Val function converts a string argument to a numeric value. True False Objects must be self contained and communicate with the host application only through its interface. True False To insure that previously assigned values are not lost when an array is re-dimensioned, you should use the Preserve keyword. True False Message boxes are the most common way for an object to return information to the developer. True False It is not possible to have more than one array in any given form. True False A loop counter can be decremented by starting at the highest value and using a negative Step value True False Tables within datasets hold returned data from SQL. True False Code execution begins at the top of the loop clause and then repeats the body of the loop until a predetermined condition is met. True False A module contains code and variable…arrow_forward
- Python: Total Damages Example skill_book = { 'mage': {'punch':10, 'spellcast':50}, 'shielder': {'punch': 5 }, 'vanguard': {'quickpunch':10, 'punch':20, 'kick':30} } assert total_damage(skill_book, [('mage','punch'), ('mage','punch')]) == 20 # each mage's punch deal 10 damage assert total_damage(skill_book, [('mage','punch'), ('vanguard','punch')]) == 30 # each vanguard's punch deal 20 damage, so the total is 10+20 = 30 assert total_damage(skill_book, [('mage','spellcast'), ('vanguard','punch'), ('vanguard','punch')]) == 90 assert total_damage(skill_book, [('vanguard','punch'), ('vanguard','kick'), ('shielder','punch')]) == 55arrow_forwardInstructions: In the code editor, you are provided with a treasureChestMagic() function which has the following description: Return type - void Name - treasureChestMagic Parameters - an address of an integer Description - updates the value of a certain integer randomly You do not have to worry about how the treasureChestMagic() function works. All you have to do is ask the user for an integer and then call the treasureChestMagic() function, passing the address of that integer you just asked. Finally, print the updated value of the integer inputted by the user. Please create a main code for my function that works with this. This is my code: #include<stdio.h>#include<math.h> void treasureChestMagic(int*); int main(void) { // TODO: Write your code here return 0;} void treasureChestMagic(int *n) { int temp = *n; int temp2 = temp; *n = *n + 5 - 5 * 5 / 5; temp2 = (int) pow(2, 3); if(temp % 3 == 0) { *n = temp * 10; } else if(temp %…arrow_forwardTask 2: Create a class that includes a data member that holds a “serial number” for each object created from the class. That is, the first object created will be numbered 1, the second 2, and so on. To do this, you’ll need another data member that records a count of how many objects have been created so far. (This member should apply to the class as a whole; not to individual objects. What keyword specifies this?) Then, as each object is created, its constructor can examine this count member variable to determine the appropriate serial number for the new object. Add a member function that permits an object to report its own serial number. Then write a main() program that creates three objects and queries each one about its serial number. They should respond I am object number 2, and so on. Paste only class definition here Paste function definitions of member functions one by one in different rows Member function 1() here Member function 2() here…arrow_forward
- Rectangle Object Monitoring Create a Rectangle class that can compute the total area of all the created rectangle objects using static fields (variables). Remember that a Rectangle has two attributes: Length and Width. Implement the class by creating a computer program that will ask the user about three rectangle dimensions. The program should be able to display the total area of the three rectangle objects. For this exercise, you are required to apply all OOP concepts that you learned in class. Sample output: Enter Length R1: 1 Enter Width R1: 1 Enter Length R2: 2 Enter Width R2: 2 Enter Length R3: 3 Enter Width R3: 3 The total area of the rectangles is 14.00 Note: All characters in boldface are user inputs.arrow_forwardclass 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_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
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT