Concept explainers
What will the following
#include <iostream>
#include <memory>
using namespace std;
class Base
{
public:
Base () { cout << "Entering the base .\n"; }
virtual ~Base () { cout << "Leaving the base.\n"; }
} ;
class Camp : public Base
{
public :
Camp() { cout << "Entering the camp.\n"; }
virtual ~Camp() { cout << "Leaving the camp.\n"; }
};
int main()
{
shared _ptr<Camp> outpost = make_shared<Camp> ();
return 0;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Starting Out With C++: Early Objects (10th Edition)
Additional Engineering Textbook Solutions
Starting Out with C++: Early Objects
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Software Engineering (10th Edition)
Problem Solving with C++ (10th Edition)
Starting Out with C++ from Control Structures to Objects (9th Edition)
Concepts of Programming Languages (11th Edition)
- #include <iostream> using namespace std; class Creature { public: Creature(); void run() const; protected: int distance;}; Creature::Creature(): distance(10){} void Creature::run() const{ cout << "running " << distance << " meters!\n";} class Wizard : public Creature { public: Wizard(); void hover() const; private: int distFactor;}; Wizard::Wizard() : distFactor(3){} void Wizard::hover() const{ cout << "hovering " << (distFactor * distance) << " meters!\n";} int main(){ cout << "Creating an Creature.\n"; Creature c; c.run(); cout << "\nCreating a Wizard.\n"; Wizard w; w.run(); w.hover(); return 0;} Reorganize your previous file’s (creature.cpp) content into three parts: declaration, imple-mentation of the classes and your test program. Name the files Creature.h,Creature.cpp and testcreature.cpp.arrow_forward#include <iostream> using namespace std; class Creature { public: Creature(); void run() const; protected: int distance;}; Creature::Creature(): distance(10){} void Creature::run() const{ cout << "running " << distance << " meters!\n";} class Wizard : public Creature { public: Wizard(); void hover() const; private: int distFactor;}; Wizard::Wizard() : distFactor(3){} void Wizard::hover() const{ cout << "hovering " << (distFactor * distance) << " meters!\n";} int main(){ cout << "Creating an Creature.\n"; Creature c; c.run(); cout << "\nCreating a Wizard.\n"; Wizard w; w.run(); w.hover(); return 0;}arrow_forward#include <iostream> using namespace std; class Rectangle { // define class public: Rectangle() { length = 0; width = 0; } // constructor float getlength() { return length; } // return length float getWidth() { return width; } // return width float area() { return length* width; } // return area float perimeter() { return 2 * length + 2 * width; } void setValues(float, float); private: float length, width; }; void Rectangle::setValues(float len, float wid) { if (len <= 0 || len >= 20) { cout << "Enter new value for length "; cin >> len; } length = len; if (wid <= 0 || wid >= 20) { cout << "Enter new value for width "; cin >> wid; } width = wid; } int main() { float length, width; Rectangle r; cout << "Enter a value for length and width between 0 and…arrow_forward
- Nonearrow_forwardDate class to use: #ifndef DATE_H_ #define DATE_H_ #include <iostream> #include <iomanip> using namespace std; class Date { friend ostream &operator<<( ostream &, const Date & ); private: int day; int month; int year; static const int days[]; // array of days per month void helpIncrement(); // utility function for incrementing date public: Date(int=1, int=1, int=0); void setDate(int,int,int); bool leapYear( int ) const; // is date in a leap year? bool endOfMonth( int ) const; // is date at the end of month? Date &operator++(); // prefix increment operator Date operator++( int ); // postfix increment operator const Date &operator+=( int ); // add days, modify object bool operator<(const Date&) const; void showdate(); }; const int Date::days[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; Date::Date(int d, int m, int y) { day = d; month = m; year = y; // initialize static member at file scope; one classwide copy } // set month,…arrow_forwardC++arrow_forward
- #include using namespace std; class Student{ public: Student() { cout<<"Hello"<arrow_forward1. Assume the following: class Complex{public:Complex(int, int); //initializes the private data members to the passed in values: // real = value of the first argument // imag = value of the second argumentComplex add( Complex ); //returns a Complex object that holds the sum of two //Complex objectsvoid print(); //prints the values of the private data members in the format: // (real, imag)private:int real, imag;}; Will these two lines work below in a driver program for the class? Complex c1(40,50); //create object (line 1) c1.real=55; //move in value of 55 (line 2) a. yes it will work fine b. no, you will get a compiler error c. need more information on the object d. line 1 will cause an error line 2 will work finearrow_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_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_forwardc++ programmingarrow_forwardMake Album in c++ You are going to develop a new class named Album. This class will has (at a minimum) teh following attributes and features: Attributes: Album Title Artist Name Array of song names (Track Listing) Array of track lengths (decide on a unit) At most there can be 20 songs on an album. Behaviors: Default and at least one argumented constructor Appropriate getters for attributes bool addTrack(string name, type duration) - adds track to album. You decide type on duration. Make sure you document what dis is. getAlbumLength() - method dat returns total length of album matching watever units / type you decide. getAlbumLength_string() - method dat returns total length of album in mm:ss format string. I would suggest using you're other getLength function here. string shuffleAlbum(int n) - method dat returns a formatted string made up of n random tracks from teh album. The string will be in the format [1] track_name (mm:ss), [2] track_name (mm:ss)... Well formatted print()…arrow_forwardarrow_back_iosSEE MORE QUESTIONSarrow_forward_ios
- Microsoft Visual C#Computer ScienceISBN:9781337102100Author:Joyce, Farrell.Publisher:Cengage Learning,