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++ MPL
Additional Engineering Textbook Solutions
Modern Database Management
Concepts Of Programming Languages
Problem Solving with C++ (10th Edition)
Java: An Introduction to Problem Solving and Programming (8th Edition)
Database Concepts (8th Edition)
Java How To Program (Early Objects)
- C++ #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_forwardc++ programmingarrow_forwardC++ Define and implement a class named Movie with the following members: std::string name; float cost; bool signedByDirector; Movie(); Movie(std::string movietitle); std::string getName (); float getCost(); void setCost (float newCost); // Price is modified by signing (see description) // Change cost to newCost // Returns signedByDirector bool issigned (); void signMovie(); Ensure each variable and function has been set an appropriate access modifier and your header file includes a header guard. Your methodgetCost() should return cost, but if the Movie is signed, it should return the cost plus a markup of 20%. For example, if a movie was worth $100, getCost () should return 100. If the same movie was signed by the author, then getCost() should return 120. Note: This function should not modify the class member cost, instead it should use cost and signedByDirector to determine the actual cost/value of the Movie. Your default constructor should set the cost to 0, the title to "NO TITLE".…arrow_forward
- #include using namespace std; (а) class Fraction{ int x, y; public: Fraction (int a, int b) {x=a; y=b;}; int getx(){return x;} int gety() {return y;} } ; int main() Fraction n(3, 7); ++n; cout << "x/y: " <« n.getx()<< "/" « n.gety()<arrow_forwardclockType.h file provided //clockType.h, the specification file for the class clockType#ifndef H_ClockType#define H_ClockType class clockType {public: void setTime(int hours, int minutes, int seconds); //Function to set the time. //The time is set according to the parameters. //Postcondition: hr = hours; min = minutes; // sec = seconds // The function checks whether the values of // hours, minutes, and seconds are valid. If a // value is invalid, the default value 0 is // assigned. void getTime(int& hours, int& minutes, int& seconds) const; //Function to return the time. //Postcondition: hours = hr; minutes = min; // seconds = sec void printTime() const; //Function to print the time. //Postcondition: The time is printed in the form // hh:mm:ss. void incrementSeconds(); //Function to increment the time by one…arrow_forwardRemove the errors from the given code. #include <iostream>using namespace std; class age{ public: void print(int y){ cout<<2023-y; }} int main(){ age:: print(2000.0); return 0;}arrow_forward#include<stdio.h> #include<stdarg.h> void fun1(int num, ...); void fun2(int num, ...); int main() { fun1(1, "Apple", "Boys", "Cats", "Dogs"); fun2(2, 12, 13, 14); return 0; } void fun1(int num, ...) { char *str; va_list ptr; va_start(ptr, num); str = va_arg(ptr, char *); printf("%s ", str); } void fun2(int num, ...) { va_list ptr; va_start(ptr, num); num = va_arg(ptr, int); printf("%d", num); }.arrow_forwardC++arrow_forwardClass Implementation Exercises EX1: Write a complete C++ program to implement a car class. The class has three attributes: Id, speed and color. Also, the class include the following methods: (setter) function, (getter) function, (default and parameterized constructor), and( print) to print the attributes values ➜ Create three objects in the main function then call the method. EX2: Write a complete C++ program to implement a student class. ➜ The class has three attributes:std-Id, Name and marks [3]. Also, the class include the following methods: (setter) function,(getter) functions (default and parameterized constructor), (average) and(print) to print the attributes values ➜ Create array of objects in the main function then call the method.arrow_forwardcomplex.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) in there now so that it will…arrow_forwardcomplex.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_forwardA return; else #include using namespace std; void division (int num, int denom); int main() { division (5, -1); division (10, 2); return 0; } void division (int num, int denom) {if (denom using namespace std; int main() (char List[4][10] = {"kareem", "ahmed", "ali", "mohamed"}; cout<arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_iosRecommended textbooks for you
- 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
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:PEARSONC 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