Starting Out With C++: Early Objects (10th Edition)
10th Edition
ISBN: 9780135235003
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7, Problem 47RQE
Assume a class named Inventory keeps track of products in stock for a company. It has member variables prodID, prodDescription, and qtyInStock. Write a constructor that initializes a new Inventory object with the values passed as arguments, but that also includes a reasonable default value for each parameter.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
5. class definition for GameEnemy
Next, we want to start making enemies for our upcoming video game, so we will define a class called GameEnemy.
Every GameEnemy will have a name, an x location, a y location, and a number of hit points (which must be a non-
negative integer ). The_init__ method for GameEnemy will take all of these parameters (in that order) and store them
on the object. GameEnemy also needs a method called healthbar, which will allow us to show that enemy's health bar in
the game. It returns the enemy's name followed by a number of asterisks to show how many hit points it has left. The
exact format is shown below.
Sample runs should look like:
>>> enemy = GameEnemy ("TODD", 100, 200, 5)
>>> enemy.healthbar()
TODD: ******
>>> enemy-%
ence
100
>>> enemy-y
200
If vou havo qu octiona
Create a class called Rational to be able to perform arithmetic operations with fractions. testing your class and
Write a program that presents a menu to the user to perform the desired action. User enters -1 value
You can trade as much as you want.
Use integer variables to represent the private data members (numerator and denominator) of the class. to this class
Write a constructor function that initializes an object of the property as soon as it is declared. Constructive
the function must contain default values for cases where no initial values are given and use the fractional number
should store it in reduced form (i.e. the fraction 2/4 should be reduced to 1 for the numerator and 2 for the denominator).
Provide public member functions for each of the following:
‐ The sum of two fractions
- Subtraction of two fractions
‐ Multiplication of two fractions
‐ The division of two fractions
In all of the above functions, results must be stored in a reduced form.
Also, write the…
2019 AP® COMPUTER SCIENCE A FREE-RESPONSE QUESTIONS
2. This question involves the implementation of a fitness tracking system that is represented by the
StepTracker class. A StepTracker object is created with a parameter that defines the minimum
number of steps that must be taken for a day to be considered active.
The StepTracker class provides a constructor and the following methods.
addDailySteps, which accumulates information about steps, in readings taken once per day
activeDays, which returns the number of active days
averageSteps, which returns the average number of steps per day, calculated by dividing the
total number of steps taken by the number of days tracked
The following table contains a sample code execution sequence and the corresponding results.
Statements and Expressions
Value Returned
Comment
(blank if no
value)
StepTracker tr
StepTracker(10000);
Days with at least 10,000 steps are considered
active. Assume that the parameter is positive.
new
tr.activeDays () ;
No…
Chapter 7 Solutions
Starting Out With C++: Early Objects (10th Edition)
Ch. 7.5 - Which of the following shows the correct use of...Ch. 7.5 - An objects private member variables can be...Ch. 7.5 - Assuming that soap is an instance of the Inventory...Ch. 7.5 - Complete the following code skeleton to declare a...Ch. 7.7 - Briefly describe the purpose of a constructor.Ch. 7.7 - Constructor functions have the same name as the A)...Ch. 7.7 - A constructor that requires no arguments is called...Ch. 7.7 - Assume the following is a constructor: ClassAct: :...Ch. 7.7 - Prob. 7.9CPCh. 7.7 - True or false: A class may have a constructor with...
Ch. 7.7 - A destructor function name always starts with A) a...Ch. 7.7 - True or false: Just as a class can have multiple...Ch. 7.7 - What will the following program code display on...Ch. 7.7 - What will the following program code display on...Ch. 7.9 - 7.15 private class member function can be called...Ch. 7.9 - When an object is passed to a function, a copy of...Ch. 7.9 - If a function receives an object as an argument...Ch. 7.9 - Prob. 7.18CPCh. 7.9 - Prob. 7.19CPCh. 7.10 - Prob. 7.20CPCh. 7.10 - Write a class declaration for a class named...Ch. 7.10 - Write a class declaration for a class named Pizza...Ch. 7.10 - Write four lines of code that might appear in a...Ch. 7.11 - Assume the following class components exist in a...Ch. 7.11 - What header files should be included in the client...Ch. 7.12 - Write a structure declaration for a structure...Ch. 7.12 - Prob. 7.27CPCh. 7.12 - Prob. 7.28CPCh. 7.12 - Write a declaration for a structure named...Ch. 7.12 - Write a declaration for a structure named City,...Ch. 7.12 - Write assignment statements that store the...Ch. 7.12 - Prob. 7.32CPCh. 7.12 - Write a function that uses a Rectangle structure...Ch. 7.12 - Prob. 7.34CPCh. 7.15 - Prob. 7.35CPCh. 7.15 - When designing an object -oriented application,...Ch. 7.15 - How do you identify the potential classes in a...Ch. 7.15 - What two questions should you ask to determine a...Ch. 7.15 - Look at the following description of a problem...Ch. 7 - Prob. 1RQECh. 7 - Which of the following must a programmer know...Ch. 7 - Prob. 3RQECh. 7 - ______programming is centered around functions, or...Ch. 7 - An object is a software entity that combines both...Ch. 7 - An object is a(n) ______ of a class.Ch. 7 - Prob. 7RQECh. 7 - Once a class is declared, how many objects can be...Ch. 7 - An objects data items are stored in its...Ch. 7 - The procedures, or functions, an object performs...Ch. 7 - Bundling together an objects data and procedures...Ch. 7 - An objects members can be declared public or...Ch. 7 - Normally a classs _________ are declared to be...Ch. 7 - A class member function that uses, but does not...Ch. 7 - A class member function that changes the value of...Ch. 7 - When a member functions body is written inside a...Ch. 7 - A class constructor is a member function with the...Ch. 7 - A constructor is automatically called when an...Ch. 7 - Constructors cannot have a(n) ______ type.Ch. 7 - A(n) ______ constructor is one that requires no...Ch. 7 - A destructor is a member function that is...Ch. 7 - A destructor has the same name as the class but is...Ch. 7 - A constructor whose parameters all have default...Ch. 7 - A class may have more than one constructor, as...Ch. 7 - Prob. 25RQECh. 7 - In general, it is considered good practice to have...Ch. 7 - When a member (unction forms part of the interface...Ch. 7 - When a member function performs a task internal to...Ch. 7 - True or false: A class object can be passed to a...Ch. 7 - Prob. 30RQECh. 7 - It is considered good programming practice to...Ch. 7 - If you were writing a class declaration for a...Ch. 7 - If you were writing the definitions for the Canine...Ch. 7 - A structure is like a class but normally only...Ch. 7 - By default, are the members of a structure public...Ch. 7 - Prob. 36RQECh. 7 - When a structure variable is created its members...Ch. 7 - Prob. 38RQECh. 7 - Prob. 39RQECh. 7 - Prob. 40RQECh. 7 - Prob. 41RQECh. 7 - Write a function called showReading. It should...Ch. 7 - Write a function called input Reading that has a...Ch. 7 - Write a function called getReading, which returns...Ch. 7 - Indicate whether each of the following enumerated...Ch. 7 - Prob. 46RQECh. 7 - Assume a class named Inventory keeps track of...Ch. 7 - Write a remove member function that accepts an...Ch. 7 - Prob. 49RQECh. 7 - A) struct TwoVals { int a, b; } ; int main() { }...Ch. 7 - A) struct Names { string first; string last; } ;...Ch. 7 - A) class Circle: { private double centerX; double...Ch. 7 - A) class DumbBell; { int weight; public: void set...Ch. 7 - If the items on the following list appeared in a...Ch. 7 - Look at the following description of a problem...Ch. 7 - Soft Skills Working in a team can often help...Ch. 7 - Date Design a class called Date that has integer...Ch. 7 - Report Heading Design a class called Heading that...Ch. 7 - Widget Factory Design a class for a widget...Ch. 7 - Car Class Write a class named Car that has the...Ch. 7 - Population In a population, the birth rate and...Ch. 7 - Gratuity Calculator Design a Tips class that...Ch. 7 - Inventory Class Design an Inventory class that can...Ch. 7 - Movie Data Write a program that uses a structure...Ch. 7 - Movie Profit Modify the Movie Data program written...Ch. 7 - Prob. 10PCCh. 7 - Prob. 11PCCh. 7 - Ups and Downs Write a program that displays the...Ch. 7 - Wrapping Ups and Downs Modify the program you...Ch. 7 - Left and Right Modify the program you wrote for...Ch. 7 - Moving Inchworm Write a program that displays an...Ch. 7 - Coin Toss Simulator Write a class named Coin. The...Ch. 7 - Tossing Coins for a Dollar Create a game program...Ch. 7 - Fishing Came Simulation Write a program that...Ch. 7 - Group Project 19. Patient Fees This program should...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
// This code contains ERRORS! // It adds two numbers entered by the user. int1 num1, num2; String input; char a...
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
What do the Ada and COBOL languages have in common?
Concepts Of Programming Languages
File Letter Counter Write a program that asks the user to enter the name of a file, and then asks the user to e...
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
(Bar-Chart Printing Program) One interesting application of computers is to display graphs and bar charts. Writ...
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
A(n)is a software application that simulates a computer, but hides the underlying operating system and hardware...
Java How To Program (Early Objects)
Write a loop equivalent to the for loop above without using .
C Programming Language
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
- Create a class named Employee. The class must contain private member variables: name and salary. It should contain getter methods for returning the name and salary. It should also contain setter methods for setting the name and salary. The class must include a constructor, the constructor must be designed to set both the name and the salary. In addition, the Employee class must contain a toString() method that prints both name and salary. Create a class named Test. The class must contain the mainmethod. In the main method, you should create three objects fromclass Employee and store them in an array of type Employee (youmust prompt the user to enter name and salary for each object).Then, you should print the name and salary of each object (usingeither the getters or the toStrong() method). DO NOT COPY CHEGGarrow_forwardObject Oriented Programming in JAVA Define and use a class for the student record. The class should have instance variables for the quizzes, midterm, final, overall numeric score for the course, and final letter grade. The overall numeric score is a number in the range 0 to 100, which represents the weighted average of the student’s work. The class should have methods to compute the overall numeric grade and the final letter grade. These last methods should be void methods that set the appropriate instance variables. Your class should have a reasonable set of accessor and mutator methods, an equals method, and a toString method.arrow_forwardT/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_forward
- Design a Ship class that has the following members:a. A field for the name of the ship (a string).b. A field for the year that the ship was built (a string).c. A constructor and appropriate accessors and mutators.d. A toString method that displays the ship's name and the year it was built.Design a CruiseShip class that extends the Ship class. The CruiseShip class should have the following members:a. A field for the maximum number of passengers (an int).b. A constructor and appropriate accessors and mutators.c. A toString method that overrides the toString method in the base class. The CruiseShip class's toString method should display only the ship's name and the maximumnumber of passengers.Design a CargoShip class that extends the Ship class. The CargoShip class should have the following members:a. A field for the cargo capacity in tonnage (an int).b. A constructor and appropriate accessors and mutators.c. A toString method that overrides the toString method in the base class. The…arrow_forwardAssignment:The BankAccount class models an account of a customer. A BankAccount has the followinginstance variables: A unique account id sequentially assigned when the Bank Account is created. A balance which represents the amount of money in the account A date created which is the date on which the account is created.The following methods are defined in the BankAccount class: Withdraw – subtract money from the balance Deposit – add money to the balance Inquiry on:o Balanceo Account ido Date createdarrow_forwardWrite a class named Car that has the following member variables: yearModel: An int that holds the car’s year model. name: A string that holds the name of the car. company: A string that holds the company of the car. speed: An int that holds the car’s current speed. In addition, the class should have the following member functions. Mutator: Appropriate accessor functions to set the values of object’s yearModel, name, company, and speed member variables. Accessor: Appropriate accessor functions to get the values stored in an object’s yearModel, company, and speed member variables. Accelerate: The accelerate function should add 5 to the speed member variable each time it is called. Brake: The brake function should subtract 5 from the speed member variable each time it is called. Demonstrate the class in a program that creates a Car object, call the setter functions to set the values and then call the accelerate function five times. After each call to the accelerate function, get…arrow_forward
- 1. Write a class named Coin. The Coin class should have the following field: • A String named sideUp. The sideUp field will hold either "heads" or "tails" indicating the side of the coin that is facing up. The Coin class should have the following methods: • A no-arg constructor that randomly determines the side of the coin that is facing up ("heads" or "tails") and initializes the sideUp field accordingly. • A void method named toss that simulates the tossing of the coin. When the toss method is called, it randomly determines the side of the coin that is facing up ("heads" or "tails") and sets the sideUp field accordingly. • A method named getSide Up that returns the value of the side Up field. Write a program that demonstrates the Coin class. The program should create an instance of the class and display the side that is initially facing up. Then, use a loop to toss the coin 20 times. Each time the coin is tossed, display the side that is facing up. The program should keep count of…arrow_forwardCreate an Account class that a bank might use to represent customers’ bank accounts. Include a data member to represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. The constructor should validate the initial balance to ensure that it is greater than or equal to 0. If not, set the balance to 0. Provide three member functions:- credit($amount) should add amount to the current balance- debit($amount) should ensure that amount does not exceed the current balance and then reduce the current balance by amount. The balance should not change if amount exceeds the balance.- getBalance() should return the current balanceNote: Create a set of test data and then write a program to test the class.arrow_forwardconstructor that sets all instance variable to a given values. instanc variables: Full name( service(int), monthly salary (double) Method to print information of the employee. B: Create a class called Employee that includes five pieces of information as: yearly salary for them.arrow_forward
- Question 6 Create a set of classes and interface for the following scenario: Define an interface called Classical Music, which contains a get Year method that returns the year the classical album released. Create an abstract class Called CD. This class contains the title as String, and playingTime as integer (e.g. 60 minutes). Include a constructor to initialize all the data fields. Create an abstract method called printPlayingTime to show the CD playing details. Make sure all the data fields can be accessed directly from the child classes. Create a class called Album that inherits from the CD and Classical Music. Include a data field called year as integer type. Create a constructor to initialize all the data members. Override the getYear method to return the released year. Override the printPlayingTime method. If the CD title is more than 10 characters, this method will print the first 10 characters, followed by the three ellipse dots and the playing time. For example: Thriller 60…arrow_forwardTrue or false: A class may have a constructor with no parameter list, and an overloaded constructor whose parameters all take default arguments.arrow_forwardThis is the question - Create a class named Rock that acts as a superclass for rock samples collected and catalogued by a natural history museum. The Rock class contains the following fields: sampleNumber - of type int description - A description of the type of rock (of type String) weight - The weight of the rock in grams (of type double) Include a constructor that accepts parameters for the sample number and weight. The Rock constructor sets the description value to "Unclassified". Include get methods for each field. Create three child classes named IgneousRock, SedimentaryRock, and MetamorphicRock. The constructors for these classes require parameters for the sample number and weight. Search the Internet for a brief description of each rock type and assign it to the description field using a method named setDescription inside of the constructor. This is the code I have, the program does not like at all what I have - import java.util.*; public class DemoRock { public static…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningMicrosoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,Programming Logic & Design ComprehensiveComputer ScienceISBN:9781337669405Author:FARRELLPublisher:Cengage
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
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