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.5CP

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: }

virtual void twist() { a *= 2; }

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

};

class Second : public First

{

private:

int b:

public:

Second(Int y = 5) { b = y: }

virtual 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
Please code in C++ and U can take time for this one and please follows all the instruction. Thank you so much. A. Create an abstract base class called Currency with two integer attributes, both of which are non-public (Python programmers - it is understood that there is nothing private in Python but try to not access the attributes directly from outside the classes). The int attributes will represent whole part (or currency note value) and fractional part (or currency coin value) such that 100 fractional parts equals 1 whole part.  B. Create two derived classes - Dollar and Pound - with one additional non-public string attribute which will contain the name of the currency (Dollar or Pound) respectively. DO NOT add this attribute to the base Currency class. C. In your base Currency class, add public methods for the following, where appropriate (C++ students are allowed to use friend methods as long as a corresponding class method is defined as well): Default Construction (i.e. no…
Reuse your Car class . In a main, build an object of that class, and print out the object using System.out.println(). Notice that this simply reports the memory address of the object in question, and we’d like to do something more useful. To replace (or override) the toString (or equals) function. Now, build a toString function that prints out the make, model, and odometer reading for a vehicle object. public class Car {    //instance variables    private int odometer;    private String make;    private String model;        //overloading    //constructors    public Car(int odometer,String make, String model) {        this.odometer = odometer;        this.make = make;        this.model = model;    }    public Car(String make, String model) {        this.make = make;        this.model = model;    }        public Car(String make) {        this.make = make;    }        /*     *getter & setter methods     */    public int getOdometer() {        return odometer;    }     public void…
Q2: Consider the following statements: public class YClass { private int a; private int b; public void one() { } public void two(int x, int y); { } public YClass() { } } class XClass extends YClass { private int z; public void one() { } public XClass() { } } YClass yObject; XClass xObject;     Write the definition of the default constructor of YClass so that the instance variables of YClass are initialized to 0. Write the definition of the default constructor of XClass so that the instance variables of XClass are initialized to 0. Write the definition of the method two of YClass so that the instance variable a is initialized to the value of the first parameter of two and the instance variable b is initialized to the value of the second parameter of two. please I want solution :(

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