Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
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
In number theory, a value can be categorized as a natural number (a whole number >0, often denoted ℕ), an integer (zero or a positive or negative whole number, including the natural numbers, often denoted ℤ), or a real number (which includes the natural numbers and integers, along with all other positive and negative numbers that are not integers, often denoted ℝ). a) write a definition for a number class that contains: (i) A single field suitable for storing either a natural number, or an integer, or a real number; (ii) Setter and getter methods for manipulating this field; (iii) A constructor that initializes new objects of number to have the value 1 (unity); (iv) a method that determines which kind of number is currently stored (returning 0 if the number is real and an integer and a natural number, 1 if the number is real and integer but not a natural number, and 2 if the number is real but neither an integer nor a natural number)
Java code needed
Given the definition of a class called Bag as following:
class Bag
{
private:
public:
int items[100];
int itemCount;
Bag();
bool add(int item);
};
Please provide the implementation of the member function: int getLast()
function returns the last number that was placed into the bag.
This
Design a class that implements the basic properties of a die. Consider the definition of the
following class die.(Beginner)
class die
{
public:
die();
//Default constructor
//Sets the default number rolled by a die to 1
void roll();
//Function to roll a die.
//This function uses a random number generator to randomly
//generate a number between 1 and 6, and stores the number
//in the instance variable num.
int getNum() const;
//Function to return the number on the top face of the die.
//Returns the value of the instance variable num.
private:
int num;
};
a) Write the definitions of the functions to implement the operations for the class die.
b) Write a program that uses the class die to roll 10 dice. (Use an array of size 10 to
implement 10 dice.) The program prompts the user to enter the desired sum and
the number of times the dice are to be rolled.
The program outputs the number of times the desired sum was rolled. Test run
your program to roll the 10 dice 10000 times with the desired…
Chapter 15 Solutions
Problem Solving with C++ (9th 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
- 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. voidarrow_forwardDefine 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.arrow_forward1- 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”arrow_forward
- 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
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