Starting Out with C++ from Control Structures to Objects (9th Edition)
9th Edition
ISBN: 9780134498379
Author: Tony Gaddis
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Textbook Question
Chapter 13, Problem 76RQE
class Change
{
public:
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
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…
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<MyCourse> courseList;
public String…
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() {…
Chapter 13 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Ch. 13.3 - True or False: You must declare all private...Ch. 13.3 - Assume RetailItem is the name of a class, and the...Ch. 13.3 - An objects private member variables are accessed...Ch. 13.3 - Assume RetailItem is the name of a class, and the...Ch. 13.3 - Complete the following code skeleton to declare a...Ch. 13.6 - Why would you declare a classs member variables...Ch. 13.6 - When a classs member variables are declared...Ch. 13.6 - What is a class specification file? What is a...Ch. 13.6 - Prob. 13.9CPCh. 13.6 - Assume the following class components exist in a...
Ch. 13.6 - What is an inline member function?Ch. 13.9 - Briefly describe the purpose of a constructor.Ch. 13.9 - Prob. 13.13CPCh. 13.9 - A member function that is never declared with a...Ch. 13.9 - A member function that is never declared with a...Ch. 13.9 - Prob. 13.16CPCh. 13.9 - A constructor that requires no arguments is called...Ch. 13.9 - True or False: Constructors are never declared...Ch. 13.9 - True or False: Destructors are never declared with...Ch. 13.9 - Prob. 13.20CPCh. 13.12 - What will the following program display on the...Ch. 13.12 - What will the following program display on the...Ch. 13.12 - In your answer for Checkpoint 13.22, indicate for...Ch. 13.12 - Why would a member function be declared private?Ch. 13.12 - Define an array of three InventoryItem objects.Ch. 13.12 - Complete the following program so it defines an...Ch. 13.16 - Prob. 13.27CPCh. 13.16 - When designing an object-oriented application, who...Ch. 13.16 - How do you identify the potential classes in a...Ch. 13.16 - What are a classs responsibilities?Ch. 13.16 - What two questions should you ask to determine a...Ch. 13.16 - Will all of a classs actions always be directly...Ch. 13.16 - Look at the following description of a problem...Ch. 13 - What is the difference between a class and an...Ch. 13 - What is the difference between the following...Ch. 13 - What is the default access specification of class...Ch. 13 - Look at the following function header for a member...Ch. 13 - A contractor uses a blueprint to build a set of...Ch. 13 - What is a mutator function? What is an accessor...Ch. 13 - Is it a good idea to make member variables...Ch. 13 - Can you think of a good reason to avoid writing...Ch. 13 - Under what circumstances should a member function...Ch. 13 - What is a constructor? What is a destructor?Ch. 13 - What is a default constructor? Is it possible to...Ch. 13 - Is it possible to have more than one constructor?...Ch. 13 - If a class object is dynamically allocated in...Ch. 13 - When defining an array of class objects, how do...Ch. 13 - What are a classs responsibilities?Ch. 13 - How do you identify the classes in a problem...Ch. 13 - Programming: In programming, there are two most...Ch. 13 - ____________ programming is centered around...Ch. 13 - _________ programming is centered around objects.Ch. 13 - _____________ is an objects ability to contain and...Ch. 13 - In C++, the _________ is the construct primarily...Ch. 13 - A class is very similar to a(n) _____________.Ch. 13 - A(n) _________ is a key word inside a class...Ch. 13 - The default access specification of class members...Ch. 13 - The default access specification of a struct in...Ch. 13 - Defining a class object is often called the...Ch. 13 - Members of a class object may be accessed through...Ch. 13 - If you were writing the declaration of a class...Ch. 13 - If you were writing the external definitions of...Ch. 13 - When a member functions body is written inside a...Ch. 13 - A(n) __________ is automatically called when an...Ch. 13 - A(n) __________ is a member function with the same...Ch. 13 - __________ are useful for performing...Ch. 13 - Constructors cannot have a(n) _________ type.Ch. 13 - A(n) ___________ constructor is one that requires...Ch. 13 - A(n) ___________ is a member function that is...Ch. 13 - A destructor has the same name as the class, but...Ch. 13 - Like constructors, destructors cannot have a(n)...Ch. 13 - A constructor whose arguments all have default...Ch. 13 - A class may have more than one constructor, as...Ch. 13 - Prob. 41RQECh. 13 - A(n) __________ may be used to pass arguments to...Ch. 13 - Write a class declaration named Circle with a...Ch. 13 - Add a default: constructor to the Circle class in...Ch. 13 - Add an overloaded constructor to the Circle class...Ch. 13 - Write a statement that defines an array of five...Ch. 13 - Write a statement that defines an array of five...Ch. 13 - Prob. 48RQECh. 13 - If the items on the following list appeared in a...Ch. 13 - Look at the following description of a problem...Ch. 13 - T F Private members must be declared before public...Ch. 13 - T F Class members are private by default.Ch. 13 - T F Members of a struct are private by default.Ch. 13 - T F Classes and structures in C++ are very...Ch. 13 - T F All private members of a class must be...Ch. 13 - T F All public members of a class must be declared...Ch. 13 - T F It is legal to define a pointer to a class...Ch. 13 - T F You can use the new operator to dynamically...Ch. 13 - T F A private member function may be called from a...Ch. 13 - T F Constructors do not have to have the same name...Ch. 13 - T F Constructors may not have a return type.Ch. 13 - T F Constructors cannot take arguments.Ch. 13 - T F Destructors cannot take arguments.Ch. 13 - T F Destructors may return a value.Ch. 13 - T F Constructors may have default arguments.Ch. 13 - T F Member functions may be overloaded.Ch. 13 - T F Constructors may not be overloaded.Ch. 13 - T FA class may not have a constructor with no...Ch. 13 - T F A class may only have one destructor.Ch. 13 - T F When an array of objects is defined, the...Ch. 13 - T F To find the classes needed for an...Ch. 13 - T F A classs responsibilities are the things the...Ch. 13 - class Circle: { private double centerX; double...Ch. 13 - #include iostream using namespace std; Class Moon;...Ch. 13 - #inc1ude iostream using namespace std; class...Ch. 13 - class Change { public: int pennies; int nickels;...Ch. 13 - Date Design a class called Date. The class should...Ch. 13 - Employee Class Write a class named Employee that...Ch. 13 - Car Class Write a class named Car that has the...Ch. 13 - Patient Charges Write a class named Patient that...Ch. 13 - Retail Item Class Write a class named RetailItem...Ch. 13 - Inventor Class Design an Inventory class that can...Ch. 13 - TestScores Class Design a TestScores class that...Ch. 13 - Circle Class Write a Circle class that has the...Ch. 13 - Population In a population, the birth rate and...Ch. 13 - Number Array Class Design a class that has an...Ch. 13 - Payroll Class Design a PayRoll class that has data...Ch. 13 - Coin Toss Simulator Write a class named Coin. The...Ch. 13 - Tossing Coins for a Dollar For this assignment,...Ch. 13 - Fishing Game Simulation For this assignment, you...Ch. 13 - Mortgage Payment Design a class that will...Ch. 13 - Freezing and Boiling Points The following table...Ch. 13 - Cash Register Design a CashRegister class that can...Ch. 13 - A Game of 21 For this assignment, you will write a...Ch. 13 - Trivia Game In this programming challenge, you...Ch. 13 - Patient Fees 1. This program should be designed...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Write a procedure is_little_endian that will return 1 when compiled and run on a little-endian machine, and wil...
Computer Systems: A Programmer's Perspective (3rd Edition)
Leap Year Detector Design a program that asks the user to enter a year, and then displays a message indicating ...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
T F: The multiplication operator has higher precedence than the addition operator.
Starting Out With Visual Basic (7th Edition)
Car Loan If A dollars are borrowed at r interest compounded monthly to purchase a car with monthly payments for...
Introduction To Programming Using Visual Basic (11th Edition)
Repeat Programming Project 8 in Chapter 1, but add yes-or-no dialogs to allow the user to make the following co...
Java: An Introduction to Problem Solving and Programming (7th 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 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_forwardpublic Account (double initialBalance){balance = initialBalance;}public Account () {balance = 0;}public void deposit (double amount){balance += amount; // Balance = balance + amount}public void withdraw (double amount){balance -= amount; // balance = balance - amount}public void close (){balance = 0;}public String toString(){return "balance: " + balance;}} Modify the Account class by adding two instance variables containing the customer's name and the account number. Both will be String objects. Modify the primary constructor for the Account class so that it takes three parameters: the balance, the customer's name, and the account number. Add instance methods named getCustomerName and getAccountNumber that return the customer name and account number.arrow_forwardpackage 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 programarrow_forward
- package application; public class Employee { private int eid; private String name; private String department; private float salary; private String mobileNo; public Employee() { super(); } public Employee(int eid, String name, String department, float salary, String mobileNo) { super(); this.eid = eid; this.name = name; this.department = department; this.salary = salary; this.mobileNo = mobileNo; } public int getEid() { return eid; } public void setEid(int eid) { this.eid = eid; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getDepartment() { return department; } public void setDepartment(String department) { this.department = department; } public float getSalary() { return salary; } public void setSalary(float salary) { this.salary = salary; } public String getMobileNo() { return mobileNo; } public void setMobileNo(String mobileNo) { this.mobileNo = mobileNo; } } Is…arrow_forwardpublic class Author2 {3 private String name;4 private int numberOfAwards;5 private boolean guildMember;6 private String[] bestsellers;78 public String Author()9 {10 name = "Grace Random";11 numberOfAwards = 0;12 guildMember = false;13 bestsellers = {"Minority Report", "Ubik", "The Man in the HighCastle"};14 }1516 public void setName(String n)17 {18 name = n;19 }20 public String getName()21 {22 return name;23 }2425 public void winsAPulitzer()26 {27 System.out.println(name + " gave a wonderful speech!");28 }29 } 1. This class includes a constructor that begins on line 8; however, it contains an error. Describe the error. 2. Rewrite the constructor header on line 8 with the error identied in part c of this question corrected. 3. Demonstrate how you might overload the constructor for this class. Write only the header. 4. Write a line of Java code to create an instance (object) of this class. Name it someAuthor. 5. Write a line of code to demonstrate how you would use the someAuthor object…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
- Student Name: 8) Consider the following ciass definitions. public class LibraryID{ private String name; // Person's name private int ID; // Person's library ID # private ArrayList Books; // Loaned books public LibraryID (String n, int num) { name = n; ID = num; Books = new ArrayList(); } public int getID () { return ID; } public String getName() { return name; } /* CheckOut () and ReturnBook () methods not shown */ Complete the following override method, contained in the LibraryID class. Two LibraryID's are considered the same if their ID numbers are the same. public boolean equals (Object other) { if (other == null){ return false;} LibraryID o = (LibraryID) other; 9) Assuming the code written in 8 is correct, write the call to compare LibraryID one and two inside the if statement. LibraryID one = new LibraryID("Mankind", 106); LibraryID two = new LibraryID ("Mick Foley", 106); if System.out.println("ID's belong to the same person"); else System.out.println("ID's belong to the…arrow_forwardthis is my retail item code: //Import statements public class RetailItem { private String description; private int units; private double price; public RetailItem() { } public RetailItem(String x, int y, double z) { description = x; units = y; price = z; } public RetailItem(RetailItem i) { } public void setDescription(String x) { description = x; } public void setPrice(double z) { price = z; } void setUnits(int y) { units = y; } public int getUnits() { return units; } public String getDescription() { return description; } public double getPrice() { return price; } // Main class public static void main(String[] args) { String str = "Shirt"; RetailItem r1 = new RetailItem("Jacket", 12,…arrow_forwardInstrument.java public class Instrument { protectedStringinstrumentName; protectedStringinstrumentManufacturer; protectedintyearBuilt, cost; publicvoidsetName(StringuserName) { instrumentName = userName; } publicStringgetName() { return instrumentName; } publicvoidsetManufacturer(StringuserManufacturer) { instrumentManufacturer = userManufacturer; } publicStringgetManufacturer(){ return instrumentManufacturer; } publicvoidsetYearBuilt(intuserYearBuilt) { yearBuilt = userYearBuilt; } publicintgetYearBuilt() { return yearBuilt; } publicvoidsetCost(intuserCost) { cost = userCost; } publicintgetCost() { return cost; } publicvoidprintInfo() { System.out.println("Instrument Information: "); System.out.println(" Name: " + instrumentName); System.out.println(" Manufacturer: " + instrumentManufacturer); System.out.println(" Year built: " + yearBuilt); System.out.println(" Cost: " + cost); } } StringInstrument.java // TODO: Define a class: StringInstrument that is derived from…arrow_forward
- Take the following code: class Song { private: string name; string author; string genre; int year_released; public: Song() { /* initialize attributes */} string get_name() { return name; } void set_name(string new_name) { name = new_name; } string get_author() { return author; } void set_author(string new_author) { author = int get_age(int curr_year) { return curr_year - year_released; new_author; } } void set_year_released(int new_year) { year_released = new_year ; } }; indicate the methods of this class. Insert Format Tools Table Edit View в IU д 12pt v Paragraph varrow_forwardclass Test { char paper[20]; int marks; public: Test () // Function 1 { strcpy (paper, "Computer"); marks = 0; } Test (char p[]) // Function 2 { strcpy(paper, p); marks = 0; } Test (int m) // Function 3 { strcpy(paper,"Computer"); marks = m; } Test (char p[], int m) // Function 4 { strcpy (paper, p); marks = m; } }; i. Write statements in C++ that would execute Function 1, Function 2, Function 3 and Function 4 of class Test. ii. Which feature of Object Oriented Programming is demonstrated using Function 1, Function 2, Function 3 and Function 4 together in the above class Test?arrow_forwardpublic class Person { private String personID; private String firstName; private String lastName; private String birthDate; private String address; public Person(){ personID = ""; firstName = ""; lastName = ""; birthDate = ""; address = ""; } public Person(String id, String first, String last, String birth, String add){ setPerson(id,first,last,birth,add); } public void setPerson(String id, String first, String last, String birth, String add){ personID = id; firstName = first; lastName = last; birthDate = birth; address = add; } public String getFirstName(){ return firstName; } public String getLastName(){ return lastName; } public String getBirthdate(){ return birthDate; } public String getAddress(){ return address; } public void print(){ System.out.print("\nPerson ID = " + personID); System.out.print("\nFirst Name = " +firstName); System.out.print("\nLast Name = " +lastName); System.out.print("\nBirth Date = " +birthDate); System.out.print("\nAddress = " +address); } public String…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
C++ Data Members; Author: CppNuts;https://www.youtube.com/watch?v=StlsYRNnWaE;License: Standard YouTube License, CC-BY