Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Expert Solution & Answer
Chapter 15.1, Problem 2STE
Explanation of Solution
Program:
//include library
#include<iostream>
using namespace std;
//class definition
class SmartBut : public Smart
{
//access specifier
public:
// declaration of constructors
SmartBut( );
SmartBut(int newA, int newB, bool newCrazy);
bool isCrazy( ) const;
//access...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Analysis the following class definition and answer the following question.
class Student{
private int id, age;
protected float mark;
int getAge (int a){
return a ; }
protected void setMark (float m){
mark = m; }
float result(){
return mark / 2;
}
}
What is the access specifier of the result in the above code?
a.
No access specifier
b.
private
c.
float
d.
public
e.
void
Define a class that captures airline tickets. Name the class as Airline Ticket.
Each ticket lists the departure and arrival cities, a flight number, and a seat
assignment. A seat assignment has both a row and a letter for the seat within
the row (such as 12F). Include appropriate constructor, destructor and a print
fucntion in your class definition. Make two examples of tickets and print the
values using the print member function.
1- Create a class SchoolKid that is the base class for children ar aschool . It should have attributes of the child’s name and age ,the name of the child’s teacher ,and the greeting. It should haveappropriate accessor and mutator methods for each of the attributes. Derive a class ExaggeratingKid from schoolkid , as described above . The new class should override the accessor method for the age , reporting the actual plus 2. It also should override the accessor for the greeting ,returning the child’s greeting concatenated with the words “I am the best”
Chapter 15 Solutions
Problem Solving with C++ (10th Edition)
Ch. 15.1 - Is the following program legal (assuming...Ch. 15.1 - Prob. 2STECh. 15.1 - Is the following a legal definition of the member...Ch. 15.1 - The class SalariedEmployee inherits both of the...Ch. 15.1 - Give a definition for a class TitledEmployee that...Ch. 15.1 - Give the definitions of the constructors for the...Ch. 15.2 - You know that an overloaded assignment operator...Ch. 15.2 - Suppose Child is a class derived from the class...Ch. 15.2 - Give the definitions for the member function...Ch. 15.2 - Define a class called PartFilledArrayWMax that is...
Ch. 15.3 - Prob. 11STECh. 15.3 - Why cant we assign a base class object to a...Ch. 15.3 - What is the problem with the (legal) assignment of...Ch. 15.3 - Suppose the base class and the derived class each...Ch. 15 - Write a program that uses the class...Ch. 15 - Listed below are definitions of two classes that...Ch. 15 - Solution to Programming Project 15.1 Give the...Ch. 15 - Create a base class called Vehicle that has the...Ch. 15 - Define a Car class that is derived from the...Ch. 15 - Prob. 4PPCh. 15 - Consider a graphics system that has classes for...Ch. 15 - Flesh out Programming Project 5. Give new...Ch. 15 - Banks have many different types of accounts, often...Ch. 15 - Radio Frequency IDentification (RFID) chips are...Ch. 15 - The goal for this Programming Project is to create...Ch. 15 - Solution to Programming Project 15.10 Listed below...Ch. 15 - The computer player in Programming Project 10 does...Ch. 15 - Prob. 12PP
Knowledge Booster
Similar questions
- Define a class for a type called Counter . An object of this type is used to count things. Include a default constructor that sets the counter to zero and a constructor with one argument that sets the counter to the value specified by its argument. Write member functions to increase the value by one (called increment ) and decrease the value by one (called decrement ), don’t let the value go below 0. Write a member function ( print ) that prints out the value of the counter.*The first photo is the driver program that you should include to test your class ****The second is what the program should look like****arrow_forwardDefine a class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), Account number (int), Account type (string, check/savings/business), Balance (double), Interest rate (double) – store interest rate as a decimal number. Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Implement all appropriate member functions of a class. Write a program that illustrate how to use your class. Your program should have the following: Declare an array of 20 components of type bankAccount to process up to 20 customers. void menu() – helps the user to select if the customer is new or if they already exist. Furthermore, it prints the customer’s data or exits the program. Use a switch statement which uses the value from menu() as an expression to call the following user-defined functions: void addCustomber() – this function…arrow_forwardThe Critter class is a base class with some basic functionality for running simulations of different kinds of critters. Critters can move, act, and remember their history. A typical simulation contains a number of critters of different types. In each step of the simulation, the act member function will be called on each critter. Define a class Sloth derived from Critter that simulates a sloth. Sloths alternate between eating and sleeping. Add the word "eat" or "sleep" to the history each time the act function is called. The implementation of the Critter class is not shown. Complete the following file: sloth_Tester.cpp #include <iostream>using namespace std; #include "critter.h" /**A sloth eats and sleeps.*/class Sloth : public Critter{public:Sloth();. . .private:. . .}; Sloth::Sloth(){. . .} void Sloth::act(){if (...) {add_history("eat");...}else{add_history("sleep");... }} int main(){Sloth sloth;sloth.act();cout << sloth.get_history() << endl;cout <<…arrow_forward
- 2. Implement the class below such that it should provide structure with necessary Data Members to all the sub-classes of itself. The object creation of this class is not mandatory. Book -name:String -author:Author -price:double -qty:int = 0arrow_forwardJAVA PROGRAM!arrow_forwardDefine the class bankAccount to implement the basic properties of a bank account. An object of this class should store the following data: Account holder’s name (string), account number (int), account type (string, checking/saving), balance (double), and interest rate (double). (Store interest rate as a decimal number.) Add appropriate member functions to manipulate an object. Use a static member in the class to automatically assign account numbers. Also declare an array of 10 components of type bankAccount to process up to 10 customers and write a program to illustrate how to use your class.arrow_forward
- Define a default constructor that initializes the data members, string title and integer year, with the default values "Empty" and -1, respectively. Ex: If the input is Magnolia 1989, then the output is: Title: Empty, Year: -1 Title: Magnolia, Year: 1989 Note: The class's print function is called first after the default constructor, then again after the inputs are passed to the setters. 5 class Book { 6 public: 7 8 9 10 11 12 13 14 15 }; 16 Book(); void SetTitle(string bookTitle); void Set Year (int bookYear); void Print (); private: string title; int year; 17 Your code goes here */ 18 19 void Book::SetTitle(string hook Title) { CS Scarint (19 bi Title mscanner 22 23 void Book Set Year(int bookYear) [ 2arrow_forwardConsider following DListNode class definition. What is the type of next and prev? class DListNode( int value; next; prev; } ;arrow_forward4. Given, an abstract class as the following: abstract class Test{ abstract void add(); } Which one of the following statement is valid? a. Test to =new Test() b. new Test(); c. Test [Jarray=new Test[5]; d. Test to =new Test(10);arrow_forward
- C----------insk.arrow_forward1. Below is a refined Person class public class Person { private String firstName; private String lastName; private String City; private char State(2]; Implement the Person class and add proper set and get methods. Also Add the method display that displays a Person's data on the screen. 2. Extend the Person class by creating a subclass called Student. In addition to attributes inherited from the Person class, the Student class has got the following additional attributes. //Additional attributes in the Student class String major; //The student's major area like 'Computer Science' or 'English' Pr. Saadia LGARCH float gpa; //The student's gpa boolean degreePlanlnFile; //Whether the student's degree plan has been filed or not Implement the Student class and add proper setand get methods. Override the display method, so it displays a student's data on the screen. 3. Define an objects ps of type class Person that hold an object of type class Student. Call display method for that object. 4.…arrow_forwardConsider the following class: public final class Midterm{ int x 1; public Midterm(){} } What can be said of this class? Select all of the true statements about it. Midterm is a valid reference data type. That is, you can have variables of type Midterm. Midterm is a concrete class. That is, you can create actual Midterm objects. Subclasses of Midterm are valid reference data types. Once a Midterm object is created it cannot be modified.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology PtrC++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning