Starting Out with C++: Early Objects
Starting Out with C++: Early Objects
8th Edition
ISBN: 9780133360929
Author: Tony Gaddis, Judy Walters, Godfrey Muganda
Publisher: Addison-Wesley
bartleby

Videos

Textbook Question
Book Icon
Chapter 15.3, Problem 15.4CP

What will the following program display?

#include <iostream>

#include <memory>

using namespace std;

class First

{

protected:

int a:

public:

First (int x = 1) { a = x; }

void twist() { a *= 2; }

int getVal() { twist(); return a; }

};

class Second : public First

{

private:

int b;

public:

Second(int y = 5) { b = y; }

void twist() { b *= 10; }

};

int main()

{

shared_ptr<First> objectl = make_shared<First>();

shared_ptr<Second> object2 = make_shared<Second>();

cout << objectl->getVal() << endl;

cout << object2->getVal() << endl;

return 0;

}

Blurred answer
Students have asked these similar questions
Hello, I am having trouble with this homework question for my c++ course.   Implement a Rational Number class with the following specifications. Data members a) numerator and denominator Functions a) Constructors: 1) default constructor 2) single parameter constructor to create numerator/1 3) dual parameter constructor to create numerator/denominator 4) Use constructor delegation across all constructors. b) Accessors and Mutators for both data members. c) Static recursive GCD function using Euclid's algorithm. d) Static LCM function for two numbers. e) Reduce function simplify a rational number. This function modifies its calling object. f) Your program should work with the supplied driver program.   Notes LCM (Least Common Multiple) This function returns the smallest multiple of a and b. Step 1: Multiply a and b to find a common multiple. Step 2: Divide the common multiple by the GCD of a and b. Step 3: Return the result of Step 2. Reduce: This function reduces a fraction to…
Can someone help me with this c++ code? Criteria:   Program executes without crashing Appropriate Internal Documentation Base Animal Class:      Correct Private Data Members      Constructors function appropriately (correct number of      constructors, number of  arguments, output of messages, etc.)       Correct get and set functions Derived Dog, Rabbit, Fish, and Snake classes      Correct Private Data Members      Constructors/destructors function appropriately (correct number of constructors, number of  arguments, output of messages, etc.)       Correct get and set functions   Move function implementation Dynamic allocation of animals Random generation of ages and correct seed value Output contains appropriate information Array used to store 5 animals correctly Memory is deallocated appropriately
This is C++. Please explain in details so I can understand the questions.What is the output of the following C++ program? #include <iostream>#include <string>using namespace std;class baseClass{public:void print() const;baseClass(string s = " ", int a = 0);//Postcondition: str = s; x = a;protected:int x;private:string str;};class derivedClass: public baseClass{public:void print() const;derivedClass(string s = "", int a = 0, int b = 0);//Postcondition: str = s; x = a; y = b;private:int y;};int main(){baseClass baseObject("This is the base class", 2);derivedClass derivedObject("DDDDDD", 3, 7);baseObject.print();derivedObject.print();system("pause");return 0;}void baseClass::print() const{cout << x << " " << str << endl;}baseClass::baseClass(string s, int a){str = s;x = a;}void derivedClass::print() const{cout << "Derived class: " << y << endl;baseClass::print();}derivedClass::derivedClass(string s, int a, int b) :baseClass("Hello…

Chapter 15 Solutions

Starting Out with C++: Early Objects

Knowledge Booster
Background pattern image
Computer Science
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
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education
Call By Value & Call By Reference in C; Author: Neso Academy;https://www.youtube.com/watch?v=HEiPxjVR8CU;License: Standard YouTube License, CC-BY