Problem Solving with C++ (9th Edition)
9th Edition
ISBN: 9780133591743
Author: Walter Savitch
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Textbook Question
Chapter 11.1, Problem 11STE
Given the following definitions:
const int x = 17;
class A
{
public:
A( );
A(int x);
int f( ) const;
int g(const A& x);
private:
int i;
};
Each of the three const keywords is a promise to the compiler that the compiler will enforce. What is the promise in each case?
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Object-Oriented Programming - Java programming.
A Java program that adds two numbers, provided that the conditions in the image below are met
Consider the following class declaration and variable definitions, then answer the following questions.
#include <stdio.h>
class A {
private:
class B {
public:
B() { x = 1; }
int x;
int& getx() { return x; }
void print() { printf(“%d”,x); }
};
private:
B b;
public:
class C {
private:
int w;
public:
C() { w = 5; }
B b;
int &getw() { return w; }
void print() { b.print(); printf(“%d”,w); }
};
C c;
void print() { b.print(); c.print(); }
int& getx() { return b.getx(); }
};
Assume each code snippet in each row below runs independently in a main function. For each one, say whether it's legal code or not. If it is, show the output and explain why it happens. If it’s illegal (e.g. syntax error), explain why. Try to do it without running the code, and then check and correct your answers as needed.
#
Code snippet
Errors?
(Yes or No)
Output or explanation of error.
1…
Chapter 11 Solutions
Problem Solving with C++ (9th Edition)
Ch. 11.1 - Write a function definition for a function called...Ch. 11.1 - What is the difference between a friend function...Ch. 11.1 - Suppose you wish to add a friend function to the...Ch. 11.1 - Prob. 4STECh. 11.1 - Notice the member function output in the class...Ch. 11.1 - Notice the definition of the member function input...Ch. 11.1 - The Pitfall section entitled Leading Zeros in...Ch. 11.1 - Give the complete definition of the member...Ch. 11.1 - Why would it be incorrect to add the modifier...Ch. 11.1 - What are the differences and the similarities...
Ch. 11.1 - Given the following definitions: const int x = 17;...Ch. 11.2 - What is the difference between a (binary) operator...Ch. 11.2 - Prob. 13STECh. 11.2 - Suppose you wish to overload the operator = so...Ch. 11.2 - Prob. 15STECh. 11.2 - Give the definition for the constructor discussed...Ch. 11.2 - Here is a definition of a class called Pairs....Ch. 11.2 - Following is the definition for a class called...Ch. 11.3 - Give a type definition for a structure called...Ch. 11.3 - Write a program that reads in five amounts of...Ch. 11.3 - Change the class TemperatureList given in Display...Ch. 11.3 - Prob. 22STECh. 11.3 - If a class is named MyClass and it has a...Ch. 11.4 - Prob. 24STECh. 11.4 - The following is the first line of the copy...Ch. 11.4 - Answer these questions about destructors. a. What...Ch. 11.4 - a. Explain carefully why no overloaded assignment...Ch. 11 - Modify the definition of the class Money shown in...Ch. 11 - Self-Test Exercise 17 asked you to overload the...Ch. 11 - Self-Test Exercise 18 asked you to overload the...Ch. 11 - Prob. 1PPCh. 11 - Define a class for rational numbers. A rational...Ch. 11 - Define a class for complex numbers. A complex...Ch. 11 - Enhance the definition of the class StringVar...Ch. 11 - Define a class called List that can hold a list of...Ch. 11 - Define a class called StringSet that will be used...Ch. 11 - This programming project requires you to complete...Ch. 11 - Redo Programming Project 6 from Chapter 9 (or do...Ch. 11 - Solution to Programming Project 11.12 To combat...Ch. 11 - Repeat Programming Project 11 from Chapter 10 but...
Additional Engineering Textbook Solutions
Find more solutions based on key concepts
Repair Bill Suppose automobile repair customers are billed at the rate of per hour for labor. Also, suppose co...
Introduction To Programming Using Visual Basic (11th Edition)
Using examples, illustrate the different types of adaptor needed to support sequential composition, hierarchica...
Software Engineering (10th Edition)
Alphabetic Telephone Number Translator Many companies use telephone numbers like 555-GET-FOOD so the number is ...
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
This statement can cause other program statements to execute only under certain conditions. 1. Conditional 2. D...
Starting Out With Visual Basic (8th Edition)
Write a program to print the value of EOF.
C Programming Language
If a method in a subclass has the same name as a method in its superclass with different parameter types, is th...
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
- C++ OOP use classes only...arrow_forwardclass A {protected int x1,y1,z; public: A(a, b,c):x1(a+2),y1(b-1),z(c+2) { for(i=0; i<5;i++) x1++; y1++;z++;}}; class B {protected: int x,y; public: B(a,b):x(a+1),y(b+2) { for(i=0; i<5;i++) x+=2; y+=1;}}; class D:public B, virtual public A { private: int a,b; public: D(k,m,n): a(k+n), B(k,m),b(n+2),A(k,m,n) { a=a+1;b=b+1;}}); int main() {D ob(4,2,5);} what the values of x1,y1 and zarrow_forwardFind the error(s) in the following code: class mystery //Line 1{ //Line 2friend mystery operator<(const mystery& a,const mystery& b); //Line 3//Returns true if object a is less than//object b; otherwise it returns false....private: //Line 4double r; //Line 5}; //Line 6arrow_forward
- 5) Consider the following code. public class Test { public static void main(String[] args){ NClass nc = new NClass(); nc.t += 1; } } class NClass { public imt t; private NClass() {//Constructor www. } } a) The program has a compilation error because the NClass class has a private constructor which is not accessible within the Test class. b) The program does not compile because the parameter list of the main method is wrong. c) The program compiles, but has a run time error because t has no initial value. d) The program compiles and runs fine.arrow_forwardObject oriented programming C++ Use Classes Write a C++ program in which each flight is required to have a date of departure, a time of departure, a date of arrival and a time of arrival. Furthermore, each flight has a unique flight ID and the information whether the flight is direct or not.Create a C++ class to model a flight. (Note: Make separate classes for Date and Time and use composition).add two integer data members to the Flight class, one to store the total number of seats in the flight and the other to store the number of seats that have been reserved. Provide all standard functions in each of the Date, Time and Flight classes (Constructors, set/get methods and display methods etc.).Add a member function delayFlight(int) in the Flight class to delay the flight by the number of minutes pass as input to this function. (For simplicity, assume that delaying a flight will not change the Date). Add a member function reserveSeat(int) which reserves the number of seats passed as…arrow_forwardPlease find the errors in the following program & explain why are they considered errors: 3 4 class Point2{ 5 6 8 9- 10 11 12- 13 14 15 - 16 17 18 19 20 21 } public : } float x,y; Point2(float iX, float iY):x(ix),y(iY){} static Point2 operator-(float shift) const { return Point2(x-shift, y-shift); } static void operator+=(float shift) const { x += shift; y+=shift; } int main() { Point2 p1(3,2); Point2 p2 1-p1; p2+ = 5; =arrow_forward
- The following class declaration has errors. Locate as many as you can. class Point {private: int xCoord; int yCoord; public:Point (int x, int y) { xCoord = x; yCoord = y; } // Overloaded + operator void operator+(const &Point Right) { xCoord += right.xCoord; yCoord += right.yCoord; }... Other member functions follow ...};arrow_forward// Is my code correct? //please make it more efficient as you can. Thank you //please correct it if there is some mistakes public class PartTimeEmployee extends Person { //private variables private double payRate; private double hoursWorked; public PartTimeEmployee() { super(); /*invokes the default constructor of class Person */ payRate = 0; hoursWorked = 0; } public PartTimeEmployee(String idPerson, String nameFirst, String nameLast, String date, String addressPerson, double pay, double hours) { super(idPerson, nameFirst, nameLast, date, addressPerson); /*invokes the non-default constructor in other words, override the parameters from Person() non-defaukt with another set of parameters, example 'idPerson' variable overrides 'id' in Person() */ this.payRate = pay; this.hoursWorked = hours; } public String toString(String idPerson,…arrow_forwardInstructions: Implement the Java class Customer by following the UML class diagram provided below. Implementation details: The class constructor must receive the arguments in the following order: String firstName, String lastName, String address, String cardNumber, int pin, String username The password must be generated inside the class constructor by the class method generatePassword(). The password to be generated must meet the following criteria: Must have at least one numeric character. Must have at least one lowercase character. Must have at least one uppercase character. Must have at least one special symbol among @#$% Password length to be generated is fixed and equal to 12. Do please use SecureRandom() class to achieve randomness during password generation. toString() return value format must be as follows:Customer [firstName='John', lastName='Monkey', cardNumber='11336688', pin='1234', username='j.monkey', password='zF$7zR#1lFAo', address='453 Manin st,…arrow_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
What is Abstract Data Types(ADT) in Data Structures ? | with Example; Author: Simple Snippets;https://www.youtube.com/watch?v=n0e27Cpc88E;License: Standard YouTube License, CC-BY