What will the following
#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;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
Starting Out with C++: Early Objects (9th Edition)
Additional Engineering Textbook Solutions
Degarmo's Materials And Processes In Manufacturing
Electric Circuits. (11th Edition)
Management Information Systems: Managing The Digital Firm (16th Edition)
SURVEY OF OPERATING SYSTEMS
Modern Database Management
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Explain below code #include <iostream>#include <cmath>using namespace std; const int DIAMETER = 20; // diameter of each ringconst int SPACE = 5; // space between rings class Circle{ public: void drawOlympicRings(int RINGS) { for (int y = 0; y < DIAMETER; y++) { for (int x = 0; x < RINGS * (DIAMETER + SPACE) - SPACE; x++) { bool draw = false; // calculate the distance from the center of each ring for (int i = 0; i < RINGS; i++) { int cx = (DIAMETER / 2) + i * (DIAMETER + SPACE); int cy = DIAMETER / 2; int dx = x - cx; int dy = y - cy; float d = sqrt(dx * dx + dy * dy); if (d <= DIAMETER / 2) { draw = true;…arrow_forwardC++arrow_forward#include using namespace std; class Student{ public: Student() { cout<<"Hello"<arrow_forwardclass 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_forwardC++ #include <string>#include <cmath> class DollarAmount {public:// initialize amount from an int64_t valueexplicit DollarAmount(int64_t value) : amount{value} { } // add right's amount to this object's amountvoid add(DollarAmount right) {// can access private data of other objects of the same classamount += right.amount; } // subtract right's amount from this object's amountvoid subtract(DollarAmount right) {// can access private data of other objects of the same classamount -= right.amount;} // uses integer arithmetic to calculate interest amount, // then calls add with the interest amountvoid addInterest(int rate, int divisor) {// create DollarAmount representing the interestDollarAmount interest{(amount * rate + divisor / 2) / divisor}; add(interest); // add interest to this object's amount} // return a string representation of a DollarAmount objectstd::string toString() const {std::string dollars{std::to_string(amount / 100)};std::string…arrow_forwardarrow_back_iosarrow_forward_ios
- 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