What will the following
#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;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Starting Out With Visual Basic (7th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Absolute Java (6th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Computer Science: An Overview (13th Edition) (What's New in Computer Science)
- class Vehicle { private: int wheels; protected : int passenger: public : void inputdata(int, int); void outputdata(); }; class Heavyvehicle : protected Vehicle { int diesel_petrol; protected : int load; public: void readdata(int, int); void writedata(); }; class Bus : private Heavyvehicle char make[20]; public : void fetchdata(char); void displaydata(); (1) Name the base class and derived class of the class Heavyvehicle. (ii) Name the data member(s) that can be accessed from function displaydata(). (iii) Name the data member's that can be accessed by an object of Bus class. (iv) Is the member function outputdata() accessible to the objects of Heavyvehicle class.arrow_forwardJAVA Language Caesar Shift Question: Modify the Caesar class so that it will allow various sized shifts to be used, instead of just a shift of size 3. (Hint: Use an instance variable in the Caesar class to represent the shift, add a constructor to set it, and change the encode method to use it.) import java.util.*; public class TestCipher { public static void main(String[] args) { int shift = 7; Caesar caesar = new Caesar(); String text = "hello world"; String encryptTxt = caesar.encrypt(text); System.out.println(text + " encrypted with shift " + shift + " is " + encryptTxt); } } abstract class Cipher { public String encrypt(String s) { StringBuffer result = new StringBuffer(""); // Use a StringBuffer StringTokenizer words = new StringTokenizer(s); // Break s into its words while (words.hasMoreTokens()) { // For each word in s…arrow_forwardclass Base { public: int x, y: public: Base(int i, int j) { x = i; y = j; }}; class Derived : public Base public: Derived (int i, int j) { x = i; y = j; void display() {cout « x <<" "<< y; }}; int main(void) { Derived d(5, 5); d.display(); return e; Error O X=5,Y=5 X-0,Y=0 None of the above Other:arrow_forward
- 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