STARTING OUT WITH C++ MPL
9th Edition
ISBN: 9780136673989
Author: GADDIS
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 7, Problem 53RQE
A) class DumbBell;
{
int weight;
public:
void set Weight(int);
) ;
void setWeight(int w)
{ weight = w; }
int main()
{
DumB1e 1 bar ;
DumbBell .setWeight(200);
cout << "The weight is"<< bar .weight << endl;
return O;
}
B) class Change
{
private:
int pennies;
int nickels;
int dimes;
int quarters;
Change()
{pennies= nickels= dimes= quarters= 0; }
Change(int p = 100, int n = 50, d = 50 , q = 25);
} ;
void Change: :Change( int p, int n , d, q)
{
pennies= p;
nickels= n;
dimes= d;
quarters= q;
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Public Class SavingsAccount
{
float interest;
float FixedDeposit;
SeniorAccount(float interest, float FixedDeposit)
{
this. interest = interest;
this.fixedDeposit= FixedDeposit;
}
float calculateInterest();
{
System.out.println(“Calculating Savings Account Interest”);
return(FixedDeposit*interest/100);
}
}
Public Class SeniorAccount extends SavingAccount
{
float seniorInterest;
SeniorAccount(float interest, float FixedDeposit)
{
this.seniorInterest=interest;
super(interest, FixedDeposit)
}
float calculateInterest()
{
System.out.println(“Calculating Savings Account Interest”);
return(FixedDeposit*seniorinterest/10);
}
}
Public static void main(String args[])
{
SavingsAccount saving = new SavingsAccount(6,100000);
System.out.println(saving.calculateinterest());
SeniorAccount senior=new seniorAccount(10,100000);
System.out.println(Senior.calculateInterest());
}
Rubric:
Correct the syntax and logical errors
Proper working code
class Lease{ private String name; private int aptNumber; private double rent; private int term; private static final int FEE = 10; public Lease(){ name = "XXX"; aptNumber = 0; rent = 1000; term = 12; } public void setName(String tenant) { name = tenant; } public void setAptNumber(int apt){ aptNumber = apt; } public void setRent(double monthRent) { rent = monthRent; } public void setTerm(int t){ term = t; } public String getName(){ return name; } public int getAptNumber(){ return aptNumber; } public double getRent(){ return rent; } public int getTerm(){ return term; } public void addPetFee(){ rent = rent + FEE; } }
Create a class named TestLease as instructed below:
Instantiate four Lease objects in the main()method.
Change the aptNumber value for the first object to 20
Change the rent value…
package myq2;
class Sale {
int sellerID, milksale, buttersale;
Sale(int sid, int ms, int bs) {
sellerID = sid;
milksale- ms;
buttersale - bs;
}
elling dairy
ifferent days
using OOP
ers, based on
YQ2
int totalsaving(){
return milksale + buttersale;
}
}
ale
public class Myq2 {
public static void main(String[] args) {
Sale s = new Sale(111, 10, 20);
System.out.println("Seller ID" + s.sellerID );
System.out.println("Total Saving "+s.totalsaving());
}
}
4) Use the parameterized constructor to initialize the member
variables of the class.
5) Display the following details of seller using object of Sale
class.
seller ID, totalsaving
Solution to program
Chapter 7 Solutions
STARTING OUT WITH C++ MPL
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
How would the following strings be converted by the CDec function? a. 48.5000 b. 34.95 c. 2,300 d. Twelve
Starting Out With Visual Basic (8th Edition)
What is the output produced by the following? intnumber=10;while(number0)number=number2;if(number==4)break;Syst...
Absolute Java (6th Edition)
Describe the three types of anomalies that can arise in a table and the negative consequences of each.
Modern Database Management (12th Edition)
Explain the problems that denormalized tables may have for insert, update, and delete actions.
Database Concepts (7th Edition)
Calories from Fat and Carbohydrates A nutritionist who works for a fitness club helps members by evaluating the...
Starting out with Visual C# (4th Edition)
A_________-controlled loop uses a true/false condition to control the number of times that it repeats. a. Boole...
Starting Out with Python (4th 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
- class Player { protected: string name; double weight; double height; public: Player(string n, double w, double h) { name = n; weight = w; height = h; } string getName() const { return name; } virtual void printStats() const = 0; }; class BasketballPlayer : public Player { private: int fieldgoals; int attempts; public: BasketballPlayer(string n, double w, double h, int fg, int a) : Player(n, w, h) { fieldgoals = fg; attempts = a; } void printStats() const { cout << name << endl; cout << "Weight: " << weight; cout << " Height: " << height << endl; cout << "FG: " << fieldgoals; cout << " attempts: " << attempts; cout << " Pct: " << (double) fieldgoals / attempts << endl; } }; a. What does = 0 after function printStats() do? b. Would the following line in main() compile: Player p; -- why or why not? c. Could…arrow_forwardEach of the following class declarations or programs contain errors. Find as many as possible. 73. class Circle: { private double centerX; double centerY; double radius; public setCenter(double, double); setRadius(double); } 74. #include using namespace std; Class Moon; { Private; double earthWeight; double moonWeight; Public; moonWeight(double ew); { earthWeight = ew; moonWeight = earthWeight / 6; } double getMoonWeight(); { return moonWeight; } }arrow_forwardC# problem when printing Weigh no value shows up code public class HealthProfile{private String _FirstName;private String _LastName;private int _BirthYear;private double _Height;private double _Weigth;private int _CurrentYear;public HealthProfile(string firstName, string lastName, int birthYear, double height, double weigth, int currentYear){_FirstName = firstName;_LastName = lastName;_BirthYear = birthYear;_Height = height;_Weigth = weight;_CurrentYear = currentYear;}public string firstName { get; set; }public string lastName { get; set; }public int birthYear { get; set; }public int height { get; set; }public double weight { get; set; }public int currentYear { get; set; }public int Person_Age{get { return _CurrentYear - _BirthYear; }}public double Height{get { return _Height; }}public double Weight{get { return Weight; }}public int Max_Heart_Rate{get { return 220 - Person_Age; }}public double Min_Target_Heart_Rate{get { return Max_Heart_Rate * 0.65; }}public double…arrow_forward
- Timer Class Concepts tested: Classes 1) Write a class called Timer that models a stopwatch with start, stop, and reset buttons. It has the following members: a) -int startTime; // variable tracking when the timer was started (unused when timer is not running). In number of seconds since 1970 b) -int timeOnClock; // variable tracking the time on the clock since last reset in seconds c) -bool isRunning; //variable tracking wether the clock is running or stopped d) +Timer(); //constructor, initializes all to zero/false e) +Timer(bool startNow); // constructur that starts clock automatically if startNow is true f) +int getTime(); // returns time on clock in seconds. If clock is running, this must also include the time since it was last started g) +void addTimeToClock(int seconds); // allows manually adding time to the clock h) +void reset(); // resets time on clock to zero i) +void start(); // starts clock j) +void stop(); // stops clock k)…arrow_forwardIn C++ class film { public: void setFilmDirector(string s); //sets the filmTitle to s void setFilmYear(string year); //sets the private member filmYear to year void setFilmProdCost(double cost); //sets the private member filmProdCost to cost void setFilmGenre (string type); //sets the private member filmGenre to type void printAllFilmInfo() const; //prints the filmDirector, filmYear, the filmProdCost and the filmGenre string geFilmGenre() const; //returns the filmGenre string getFilmYear() const; //returns the filmYear double getFilmProdCost() const; //returns the filmProdCost void updateFilmProdCost(double cost); //adds cost to the filmProdCost, so that the filmProdCost now has it original value plus the //parameter sent to this function private: string filmDirector; string filmYear; double filmProdCost; string filmGenre; }; Assume the following in your main program (the…arrow_forwardclass Course { private String courseNumber; private String courseName; private int creditHrs; public Course (String number, String name, int creditHrs){ this.courseNumber = number; this.courseName = name; this.creditHrs = creditHrs; } public String getNumber() { return courseNumber; } public String getName() { return courseName; } public int getCreditHrs() { return creditHrs; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseName(String courseName) { this.courseName = courseName; } public void setCreditHrs(int creditHrs) { this.creditHrs = creditHrs; }} class Student { private String firstName; private String lastName; private String gender; private String phoneNumber; private String email; private String jNumber; protected ArrayList<MyCourse> courseList; public String…arrow_forward
- class Course { private String courseNumber; private String courseName; private int creditHrs; public Course (String number, String name, int creditHrs){ this.courseNumber = number; this.courseName = name; this.creditHrs = creditHrs; } public String getNumber() { return courseNumber; } public String getName() { return courseName; } public int getCreditHrs() { return creditHrs; } public void setCourseNumber(String courseNumber) { this.courseNumber = courseNumber; } public void setCourseName(String courseName) { this.courseName = courseName; } public void setCreditHrs(int creditHrs) { this.creditHrs = creditHrs; }}class Student { private String firstName; private String lastName; private String gender; private String phoneNumber; private String email; private String jNumber; protected ArrayList courseList; public String getFullName() {…arrow_forwardClass member methods (choose the best answer) A.) defines what the class can do B.) must return a value or void C.) are set to private by default D.) Is also called a function E.) all of the abovearrow_forwardclass Vehicle { private: int wheels; protected : int passenger: public : void inputdata(int, int); void outputdata(); }; class Heavyvehicle : protected Vehicle { int diesel_petrol; protected : int load; public: void readdata(int, int); void writedata(); }; class Bus : private Heavyvehicle char make[20]; public : void fetchdata(char); void displaydata(); (1) Name the base class and derived class of the class Heavyvehicle. (ii) Name the data member(s) that can be accessed from function displaydata(). (iii) Name the data member's that can be accessed by an object of Bus class. (iv) Is the member function outputdata() accessible to the objects of Heavyvehicle class.arrow_forward
- Account Class) Create an Account class that a bank might use to represent customers’ bank accounts. Include a data member of type intto represent the account balance. Provide a constructor that receives an initial balance and uses it to initialize the data member. Theconstructor should validate the initial balance to ensure that it’s greater than or equal to 0. If not, set the balance to 0 and display anerror message indicating that the initial balance was invalid. Provide three member functions. Member function credit should add anamount to the current balance. Member function debit should withdraw money from the Account and ensure that the debit amountdoes not exceed the Account’s balance. If it does, the balance should be left unchanged and the function should print a messageindicating "Debit amount exceeded account balance." Member function getBalance should return the current balance. Create a programthat creates two Account objects and tests the member functions…arrow_forwardQ-2) Given the following code: class Calculation { int z, public void addition(int x, int y) { z = x + y; System.out.println("The sum of the given numbers:"+z); } public void Subtraction(int x, int y) { z = x-y; System.out.println("The difference between the given numbers:"+z); public class My_Calculation extends Calculation { public void multiplication(int x, int y) { z = x*y; System.out.println("The product of the given c) Give the output when this program is run: numbers:"+z); } public static void main(String args[]) { int a = 20, b = 10; } My Calculation demo = new My_Calculation(); demo.addition(a, b); demo.Subtraction(a, b); demo.multiplication(a, b); Complete the missing lines in a and b a) Name the superclass the subclass b) Suppose we wish to save the program in a text file My_Calculation. The extension should be d) Which objects (variables and methods) are inherited from the superclass? e) If you instantiate demo as Calculation demo = new My_Calculation(); in the main…arrow_forwardData Structure Add this two methods for the following classarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
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