Concept explainers
What will the following program display?
#include <iostream>
#include <string>
#include <memory>
using namespace std;
class Base
{
public :
Base() { cout << "Entering the base .\n"; }
Base(string str)
{
cout << "This base is " << str << " .\ n";
}
virtual ~Base() { cout << "Leaving the base.\n"; }
};
class Camp : public Base
{
public :
Camp() { cout << "Entering the camp.\n"; }
Camp(string str1, string str2) : Base (str1)
{
cout << "The camp is " << str2 << " . \n";
}
};
int main()
{
shared_ptr<Camp>
outpost= make_shared<Camp> ("secure", "secluded");
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Starting Out With C++: Early Objects, Student Value Edition & Myprogramminglab With Pearson Etext -- Standalone Access Card Package, 9/e
Additional Engineering Textbook Solutions
Starting Out with Programming Logic and Design (5th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Data Structures (3rd Edition)
Concepts of Programming Languages (11th Edition)
Starting Out with Java: Early Objects (6th Edition)
Concepts Of Programming Languages
Introduction To Programming Using Visual Basic (11th Edition)
- 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_forwardCreate parent class Shapes with protected parameters width and height and function printarea() and a virtual function cal_area(). Create two sub classes Rectangle and Sqaure. In main() create 2 pointers of Shapes and assign Rectangle and Square to it. Call printarea function with the pointers. Note: use OOP C++arrow_forwardCPS506 Lab 6 Haskell: Type classes and custom types Preamble In this lab you'll create a custom type in Haskell and make it an instance of several built-in Haskell type-classes. Getting Started The provided cabal project defines a module called Lab6. This module will define a custom type called DigitalTime. The DigitalTime type will be used to represent time as a 3-tuple of integers. One for hour, minute, and second, respectively. Thus, the type definition should look like this: data DigitalTime = DigitalTime (Int, Int, Int) Next, you will implement several type classes over this type. These type classes and their operations can be found below. Assume that the hour range is 1-12. Do not use 24h time. Type Classes to Implement Show: show DigitalTime (h, m, s) Print the time in the format "<hh:mm:ss>" Eq: (==) (DigitalTime (h1, m1, s1)) (DigitalTime (h2, m2, s2)) Two times are considered equal if they have the same hour, minute, and second values. Ord: (<=) (DigitalTime (h1, ml,…arrow_forward
- T/F In Java a constructor must always return an int.arrow_forwardWhat is the output of the given code? #include<iostream> using namespace std; class Base { public: Base() { cout<<"Constructing Base \n"; } virtual~Base() { cout<<"Destructing Base \n"; } }; class Derived: public Base { public: Derived() { cout<<"Constructing Derived \n"; } ~Derived() { cout<<"Destructing Derived \n"; } }; int main(void) { Derived *d = new Derived(); Base *b = d; delete b; return 0; }arrow_forwardWrite a program which has a class named binary which has a character array to store a binary string. The class decimal derives from class binary and contains an integer data member. Another class called octal also derives from binary. Each class should contain constructors and appropriate data members to input and display the elements. The display function of binary class displays the binary equivalent, octal class’s display function displays octal equivalent whereas decimal class’s display function displays the decimal equivalent (question is a part of c++)arrow_forward
- THIS NEEDS TO BE DONE IN C#!! Create a class called Coordinate, which will store the x and y coordinates of a point. Create the following operations for this class: X and Y properties for accessing/modifying the coordinates. constructor - allows the user to pass in an initial x and y coordinate. operator+ - overload the + operation to add 2 coordinates together. To add two coordinates together: (x1, y1) + (x2, y2) = (x1 + x2, y1 + y2) Example: (3, 4) + (2, 4) = (5, 8) ToString - Output the coordinates as followed: (X, Y) In main, create two coordinates based on the example above. Print them out using ToString. Create a third coordinate that is the result of the two coordinates added. Print it out as well.arrow_forwarddo 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_forwardCreate an overloaded output operator operator<< as a stand-alone function for your DivSales class. You may not use friend .The output operator should display the sales for each quarter of a single division (single object of the class) with labels. Remember DivSales represents the quarterly sales of one division of a company. Use it in your main program to output the quarterly sales for each division in the company (for each object in the divisions array). You will need a loop. After all divisions are displayed, display the total corporate sales for the year.arrow_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 areaarrow_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 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_forwardin C++ There should be three files: header file containing the definition of class .h, file containing the class implementation should be .cpp, and the driver code (i.e., the main() function) main.cpp Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test your class. Complex numbers have the form: realPart + imaginaryPart * i where i is √−1.Use double variables to represent the private data of the class. Provide a constructor function that enables an object of this class to be initialized when it is declared. The constructor should contain default values in case no initializers are provided. Provide public member functions for each of the following: a) Addition of two Complex numbers: The real parts are added together and the imaginary parts are added together. b) Subtraction of two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand and the imaginary part of the right…arrow_forward
- C++ for Engineers and ScientistsComputer ScienceISBN:9781133187844Author:Bronson, Gary J.Publisher:Course Technology Ptr