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
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)
- C++ 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_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_forwardC++arrow_forward
- Class 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_forward
- JAVA 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_forwardModify the Student class presented above as follows. Each student object should contain the scores for three (3) tests. (1) Provide a constructor that sets all instance values based on parameter values. (2) ✓ Overload the constructor such that each test score is assumed to be initially zero. (5) Provide a method called setTestScore that accepts two (2) parameters: the test number (1 through 3) and the score. Also provide a method called getTestScore that accepts the test number and returns the appropriate score. (6) Provide a method called average that computes and returns the average test score for the student. (3) Modify the display method such that the test scores and average are included in the description of the students. (5) Implement the class to exercise the methods of Student. (8) NOTE WELL ✓ Ensure that your programs are documented (comments) as needed ✓ Make certain that your programs are debugged and working before submittingarrow_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
- do part 4 import java.util.*; // Car classclass Car{ private String name; // Variable to hold car name private String model; // Variable to hold car model // Default constructor Car(){ this.name = null; this.model = null; } // Parametrised constructor Car(String name, String model){ this.name = name; this.model = model; } // Function to get car name public String getName(){ return this.name; }} // Dealer classclass Dealer{ private Car[] arr; // Array holding car objects for a dealer private int count; // Variable to hold number of cars under a dealer // Default constructor Dealer(){ arr = new Car[50]; count=0; } // Function to add a car under a dealer public void addCar(Car obj){ this.arr[this.count] = obj; this.count++; } // Function to check if a car exists under a dealer or not public boolean contains(String name){…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//Please Fix this program #include<iostream>using namespace std;class Point{private:int x, y;public:Point() {}Point(int x1, int y1) { x = x1; y = y1; }Point(const Point &p1) {x = p1.x; y = p1.y; } // Copy constructorint getX() { return x; }int getY() { return y; }};int main(){Point p0(); // Calling Default ConstructorPoint p1(10, 15); // Calling Parameterized constructorPoint p2 = p1; // Calling Copy constructorcout << "p0.x = " << p0.getX() << ", p0.y = " << p0.getY();cout << "p1.x = " << p1.getX() << ", p1.y = " << p1.getY();cout << "\np2.x = " << p2.getX() << ", p2.y = " << p2.getY();return 0;}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