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
Digital Fundamentals (11th Edition)
Starting Out with C++ from Control Structures to Objects (8th Edition)
Starting Out with Java: From Control Structures through Objects (7th Edition) (What's New in Computer Science)
Computer Science: An Overview (12th Edition)
Programming in C
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- 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_forwardC++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_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_forwardProgramming 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_forward
- a) 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#include <iostream> using namespace std; class Product { private: double price; int weight; public: void info() { cout <<price<<", "<<weight; } }; class Fruit { public: string type; void setInfo(double p, int w) { price = p; weight = w; } }; int main() { Fruit obj; obj.type = "Apple"; obj.setInfo(4.99, 10); obj.info(); }arrow_forward
- 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_forwardQuestion 15 1(8).png public class numClass { private int a; private static int y = 10; public numClass(int newx) {a-newx; } public void set(int newx) {a=newx; y+=a;} public void setY(int newY) {y-newY; } public static int getY() { return y; } // end of class Blank 1 Blank 1 Add your answer public class output[ public static void main(String[] args) { numclass one new numClass(10); numclass two new numClass (2); try{ one.sety(30); two.set(4); if(one.getY()-30) throw new Exception ("30"); one. sety (40); } catch(Exception e) { two.setY(50); } System.out.println(two.getY()); // end of main } // end of class ***arrow_forward#include #include #include #include using namespace std; class AttackInfo{ public: }; int dmg; string description; AttackInfo() AttackInfo(int a, string b){ dmg = a; description = b; class BaseCharacter{ private: } string name; int maxHP,presentHP,dodgeChance; public: int strength, agility,intelligence, baseDamage; public: BaseCharacter() { BaseCharacter(string a, int b, int c, int d, int e, int f, int g){ name = a; strength = b; agility = c; intelligence = d; maxHP = e; presentHP = maxHP; dodgeChance = f; baseDamage=g; } AttackInfo primaryAttack(){ return AttackInfo(baseDamage,"strikes at"); } at"); AttackInfo secondaryAttack(){ return AttackInfo(baseDamage,""); } } void takeDamage(int a){} string toString(){ return "Name: "+getName()+"Max HP: "+to_string(getMaxHp())+" Present HP: "+to_string(getPresentHP())+"Dodge Chance: "+to_string(get DodgeChance()); } }; AttackInfo getAttack(){ return primaryAttack(); }; class Warrior: public BaseCharacter{ private: string getName(){return name;}…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