Concept explainers
What will the following
#include <iostream>
#include <memory>
using namespace std;
class First
{
protected:
int a;
public:
First(int x = 1) { a = x; }
int getVal() const { return a; }
};
class Second : public First
{
private:
int b;
public:
Second(int y = 5) { b = y; }
int getVal() const { return b; }
};
int main()
{
Shared_ptr<First> object1 = make_shared<First>();
shared_ptr<Second> object2 = make_shared<Second>():
cout << object1->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 - Access
Additional Engineering Textbook Solutions
Modern Database Management (12th Edition)
Starting Out with Programming Logic and Design (4th Edition)
Software Engineering (10th Edition)
Starting out with Visual C# (4th Edition)
Java: An Introduction to Problem Solving and Programming (7th Edition)
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
- Write a program in java a class Box having three private data members (width, depth, height) The class has three constructors which are having no parameter – for setting values to zero or null. having three parameters for assigning values to height, width, depth respectively. Overload the above constructor and use this keyword to set the values of width, height & depth. Provide getters/setters for data members. Write a function calculateVolume() which calculates the volume of the box. Write test Application that demonstrates the Box class by calling all the three constructors and method, creating a Create Box object, and then displaying the Box’s width , height, length and volumearrow_forwardSuppose that a class is defined to represent a deck of cards or a player's hand in a card game. This class is implemented as below: A class, also, is defined to develop a card game in which a list of all players' names and their hand is stored. Part of the implementation of this class looks like the following code: A) Specify what should be the return type of getPlayersHand()? B) Assume that the cardGame is a composition of Deck. With this assumption, i) implemnt getPlayerHand(). ii) implement the overloaded constructor of Deck. No java methods can be used for part ii. C) Assume that cardGame is an aggregation of Deck. With this assumption, implement getPalyerHand(). D) An equals() method has been implemented for Deck class. Fill in the gaps to create a fully working equals() method.arrow_forwardAssume you have a system with the following (As in the picture) write the following in c++ (using Inheritance) and make menu Implement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. Create array of countries called Arab of 22 countries. Write a function fill that fills the array Arab Write a method that finds the city that has the max area in a country Write a method that sorts the cities in a country from the largest to the smallest areaarrow_forward
- Assume you have a system with the following (As in the picture) write the following in c++ (using Inheritance) and make menu Implement the above system using inheritance in the best possible way. Keep every object size as small as possible. Implement all methods (setter/getter/constructors and destructors) Note that the region area is 0 while the city is len*width and the country is the sum of their cities. Create array of countries called Arab of 22 countries. Write a function fill that fills the array Arab Write a method that finds the city that has the max area in a country Write a method that sorts the cities in a country from the largest to the smallest area Write a function that returns array of countries of the same area of Arab Write a function that compares between two countries. It returns true if country1 area greater than country2 area. Write a function to move a city from one country to another.arrow_forwardHello, I am having trouble with this homework assignment for C++ (See below for the output) 2. Implement the following: a. A class named Food. 1. dynamic data member: name 2. accessors and mutators 3. the big three b. A class named Cake that inherits from Food. 1. dynamic data member: topping (type of icing such as chocolate) 2. accessors and mutators 3. the big three c. Create an object of type Food and output its data member. d. Create an object of type Cake and output its data members. e. Test all inherited functions in main. (Cannot change the given int main. Any alteration is not accepted) int main() { cout << endl; Food f1("Bread"); f1.output(); cout << "\nf2: Copy Constructor" << endl; Food f2 = f1; f2.output(); cout << "\nf3: Assignment Overload" << endl; Food f3; f3 = f2; f3.output(); cout << "\nFood: Mutator" << endl; f1.setName("Pizza"); f2.setName("Sandwich"); f1.output(); f2.output(); f3.output(); cout << "\nCake:\n" <<…arrow_forwardUse the following partial class definitions to answer the questions a-c public class A1 { public int x; private int y; protected int z; ... } public class A2 extends A1 { protected int a; private int b; ... } public class A3 extends A2 { private int q; ... } a) Which of the following is true with respect to A1, A2 and A3? Group of answer choices A1 is a subclass of A2 and A2 is a subclass of A3 A3 is a subclass of A2 and A2 is a subclass of A1 A1 and A2 are both subclasses of A3 A2 and A3 are both subclasses of A1 A1, A2 and A3 are all…arrow_forward
- please use c++ to answer the following question Use inheritance and classes to represent a deck of playing cards. Create a Card class that stores the suit (e.g. Clubs, Diamonds, Hearts, Spades), and name (e.g. Ace, 2, 10, Jack)along with appropriate accessors, constructors, and mutators. Next, create a Deck class that stores a vector of Card objects. The default constructor should create objects that represent the standard 52 cards and store them in the vector. The Deck class should have functions to: Print every card in the deck Shuffle the cards in the deck. You can implement this by randomly swappingevery card in the deck. Add a new card to the deck. This function should take a Card object as a parameter and add it to the vector. Remove a card from the deck. This removes the first card stored in the vector andreturns it. Sort the cards in the deck ordered by name. Next, create a Hand class that represents cards in a hand. Hand should be derived from Deck. This is because a hand is…arrow_forwardHello, I am having trouble with this homework assignment for c++ 2. Implement the following:a. A class named Food.1. dynamic data member: name2. accessors and mutators3. the big threeb. A class named Cake that inherits from Food.1. dynamic data member: topping (type of icing such as chocolate) Due date: Jul 27, 11:59 PM2. accessors and mutators3. the big three c. Create an object of type Food and output its data member. d. Create an object of type Cake and output its data members. e. Test all inherited functions in main. (Cannot change the given int main. Any alteration is not accepted)int main() {cout << endl;Food f1("Bread");f1.output();cout << "\nf2: Copy Constructor" << endl;Food f2 = f1;f2.output();cout << "\nf3: Assignment Overload" << endl;Food f3;f3 = f2;f3.output();cout << "\nFood: Mutator" << endl;f1.setName("Pizza");f2.setName("Sandwich");f1.output();f2.output();f3.output();cout << "\nCake:\n" << endl;Cake c1("Ice Cream…arrow_forwardThe base class Pet has attributes name and age. The derived class Dog inherits attributes from the base class Pet class and includes a breed attribute. Complete the program to: Create a generic pet, and print the pet's information using print_info(). Create a Dog pet, use print_info() to print the dog's information, and add a statement to print the dog's breed attribute. Ex: If the input is: Dobby 2 Kreacher 3 German Schnauzer the output is: Pet Information: Name: Dobby Age: 2 Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer code to be used: python class Pet: def __init__(self): self.name = '' self.age = 0 def print_info(self): print('Pet Information:') print(' Name:', self.name) print(' Age:', self.age) class Dog(Pet): def __init__(self): Pet.__init__(self) self.breed = '' my_pet = Pet()my_dog = Dog() pet_name = input()pet_age = int(input())dog_name = input()dog_age =…arrow_forward
- The base class Pet has attributes name and age. The derived class Dog inherits attributes from the base class Pet class and includes a breed attribute. Complete the program to: Create a generic pet, and print the pet's information using print_info(). Create a Dog pet, use print_info() to print the dog's information, and add a statement to print the dog's breed attribute. Ex: If the input is: Dobby 2 Kreacher 3 German Schnauzer the output is: Pet Information: Name: Dobby Age: 2 Pet Information: Name: Kreacher Age: 3 Breed: German Schnauzer The code to be added is #TODO python class Pet: def __init__(self): self.name = '' self.age = 0 def print_info(self): print('Pet Information:') print(' Name:', self.name) print(' Age:', self.age) class Dog(Pet): def __init__(self): Pet.__init__(self) self.breed = '' my_pet = Pet()my_dog = Dog() pet_name = input()pet_age = int(input())dog_name =…arrow_forwardImplement “SoftwareEngineer” and “CheifEngineer” class derived from “Employee” class with necessary properties so that the expected output is generated. Do not change any given code. # Write your codes here.# Do not change the following lines of code.sw1 = SoftwareEngineer("Bob","Software Engineer",40,1200)print('1.------------------------------------')sw1.calculateWeeklyIncome()print('2.------------------------------------')print(sw1)print('3.------------------------------------')sw2 = SoftwareEngineer("Carol","Software Engineer",45,1200,5)print('4.------------------------------------')sw2.calculateWeeklyIncome()print('5.------------------------------------')print(sw2)print('6.------------------------------------')print(Employee.employeeInfo)print('7.====================================')ce1 = ChiefEngineer("John","Chief…arrow_forwardIN JAV1. Declare a class called country that contains a function called language that prints "English" Define 3 classes and they all inherit from country A brand named Australia A class named Saudi Rewrite the language function and change the implementation of the function so that it prints "Arabic" A class called Spain Rewrite the language function and change the implementation of the function so that it prints "Spanish" Build a Test class to test the code with the Main function and then create objects of the three classes that Workshop of the father's class Then call the language function The result should be as in the picture English Arabic Spanisharrow_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