What will the following
#include <iostreara>
#include <memory>
using namespace std;
class Base
{
protected:
int baseVar;
public:
Base(int val = 2) { baseVar = val; }
int getVar() const { return baseVar; }
};
class Derived : public Base
{
private:
int deriVar;
public:
Derived(int val = 100) { deriVar = val; }
Int getVar() const { return deriVar; }
};
int main()
{
shared_ptr<Base> optr = make_shared<Derived>();
cout << optr->getVar() << endl;
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 15 Solutions
STARTING OUT WITH C++ MPL
Additional Engineering Textbook Solutions
Database Concepts (8th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Electric Circuits. (11th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Web Development and Design Foundations with HTML5 (8th Edition)
- complex.h #pragma once #include <iostream> #include "imaginary.h" using namespace std; class Complex { private: int real; Imaginary imagine; public: //YOU: Implement all these functions Complex(); //Default constructor Complex(int new_real, Imaginary new_imagine); //Two parameter constructor Complex operator+(const Complex &rhs) const; Complex operator-(const Complex &rhs) const; Complex operator*(const Complex &rhs) const; bool operator==(const Complex &rhs) const; Complex operator^(const int &exponent) const; friend ostream& operator<<(ostream &lhs,const Complex& rhs); friend istream& operator>>(istream &lhs,Complex& rhs); }; complex.cc #include <iostream> #include "complex.h" using namespace std; //Class definition file for Complex //YOU: Fill in all of these functions //There are stubs (fake functions)…arrow_forwardProblem: Employee and ProductionWorker Classes Write a python class named ProductionWorker that is a subclass of the Employee class. The ProductionWorker class should keep data attributes for the following information: • Shift number (an integer, such as 1, 2, or 3)• Hourly pay rateThe workday is divided into two shifts: day and night. The shift attribute will hold an integer value representing the shift that the employee works. The day shift is shift 1 and the night shift is shift 2. Write the appropriate accessor and mutator methods for this class. Once you have written the class, write a program that creates an object of the ProductionWorker class, and prompts the user to enter data for each of the object’s data attributes. Store the data in the object, then use the object’s accessor methods to retrieve it and display it on the screen Note: The program should be written in python. Sample Input/Output: Enter the name: Ahmed Al-AliEnter the ID number: 12345Enter the department:…arrow_forwardExplain 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_forward
- C++arrow_forward#include <iostream> using namespace std;struct Triple{int row, col, value;}; class Matrix; class MatrixNode{friend class Matrix;friend istream& operator>>(istream&, Matrix&);private:MatrixNode *down, *right;bool head;union{MatrixNode *next;Triple triple;};MatrixNode(bool, Triple*);}; MatrixNode::MatrixNode(bool b, Triple *t){head = b;if (b){right = down = this;}else triple = *t;};class Matrix{friend istream& operator>>(istream&, Matrix&);public:~Matrix();MatrixNode*private:MatrixNode *headnode;}; Matrix::~Matrix(){// Return all nodes to the av list, which is a chain linked// via the right field.// av is a static variable pointing to the first of the av list.if (!headnode )return; // no nodes to deleteMatrixNode *x = headnode->right; headnode->right = av;av = headnode; // return headnode while (x != headnode) { // return nodes by rowsMatrixNode *y = x->right;x->right = av;av = y;x = x->next; // next row}headnode = 0;} istream&…arrow_forward#include <iostream> using namespace std;struct Triple{int row, col, value;}; class Matrix; class MatrixNode{friend class Matrix;friend istream& operator>>(istream&, Matrix&);private:MatrixNode *down, *right;bool head;union{MatrixNode *next;Triple triple;};MatrixNode(bool, Triple*);}; MatrixNode::MatrixNode(bool b, Triple *t){head = b;if (b){right = down = this;}else triple = *t;};class Matrix{friend istream& operator>>(istream&, Matrix&);public:~Matrix();MatrixNode*private:MatrixNode *headnode;}; Matrix::~Matrix(){// Return all nodes to the av list, which is a chain linked// via the right field.// av is a static variable pointing to the first of the av list.if (!headnode )return; // no nodes to deleteMatrixNode *x = headnode->right; headnode->right = av;av = headnode; // return headnode while (x != headnode) { // return nodes by rowsMatrixNode *y = x->right;x->right = av;av = y;x = x->next; // next row}headnode = 0;} istream&…arrow_forward
- class 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#include <iostream>using namespace std;class Box {double width;public:friend void printWidth( Box box ); //declare friendsvoid setWidth( double wid );};// Member function definitionvoid Box::setWidth( double wid ) {width = wid;}// Note: printWidth() is not a member function of any class.// it is written directly without Box::void printWidth( Box box ) {/* Because printWidth() is a friend of Box, it candirectly access any member of this class */cout << "Width of box : " << box.width <<endl;}// Main function for the programint main() {Box box;// set box width without member functionbox.setWidth(10.0);// Use friend function to print the wdith.// call directly that can access private variables of box.printWidth( box );return 0;} -By using above code To make points and length parameters of triangles and ellipses to be private. Make a counter for how many triangle-objects that are created. The counter is a static variable. - Display the areas and the counting values.…arrow_forwardpackage myq2; class Sale { int sellerID, milksale, buttersale; Sale(int sid, int ms, int bs) { sellerID = sid; milksale- ms; buttersale - bs; } elling dairy ifferent days using OOP ers, based on YQ2 int totalsaving(){ return milksale + buttersale; } } ale public class Myq2 { public static void main(String[] args) { Sale s = new Sale(111, 10, 20); System.out.println("Seller ID" + s.sellerID ); System.out.println("Total Saving "+s.totalsaving()); } } 4) Use the parameterized constructor to initialize the member variables of the class. 5) Display the following details of seller using object of Sale class. seller ID, totalsaving Solution to programarrow_forward
- Programming Exercise 11-2 dateType.h file provided #ifndef date_H #define date_H class dateType { public: void setDate(int month, int day, int year); //Function to set the date. //The member variables dMonth, dDay, and dYear are set //according to the parameters //Postcondition: dMonth = month; dDay = day; // dYear = year int getDay() const; //Function to return the day. //Postcondition: The value of dDay is returned. int getMonth() const; //Function to return the month. //Postcondition: The value of dMonth is returned. int getYear() const; //Function to return the year. //Postcondition: The value of dYear is returned. void printDate() const; //Function to output the date in the form mm-dd-yyyy. bool isLeapYear(); //Function to determine whether the year is a leap year. dateType(int month = 1, int day = 1, int year = 1900); //Constructor to…arrow_forwarda) Given the following code segments: class MyClass { String name; double value; MyClass (String n, double v) { name = n; value =v; String getName () { return name; } double getValue () { return value; } }arrow_forwardQ2: Complete the main programs and writing its functions, classes and find the Area for each shape: 1- Main() { Circle C [3]={12,51,7}; C.setdate('3'); // Circle class has private members: radius,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