Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include using namespace std; class Student { public: Student() { cout < < Student(), constructor called. < < endl; } explicit Student(string stuName) :

#include

#include

using namespace std;

class Student {

public:

Student() {

cout << "Student(), constructor called." << endl;

}

explicit Student(string stuName) : stuName(stuName) {

cout << "Student(stuName), constructor called." << endl;

}

~Student() {

cout << "~Student(), destructor called." << endl;

}

string getName() {

return this->stuName;

}

virtual void sayHi() {

cout << "Student: Hi!" << endl;

}

void sayHello() {

cout << "Student: Hello!" << endl;

}

private:

string stuName{ "Student" };

};

class CSStudent : public Student {

public:

CSStudent() {}

explicit CSStudent(string stuName) : Student() {}

void sayHello() {

cout << "CSStudent: Hello!" << endl;

}

};

class CSStudent340 : public CSStudent {

public:

CSStudent340() {

cout << "CSStudent340(), constructor called." << endl;

}

explicit CSStudent340(string stuName) : CSStudent(stuName) {

cout << "CSStudent340(stuName), constructor called." << endl;

}

~CSStudent340() {

cout << "~CSStudent340(), destructor called." << endl;

}

void sayHi() {

cout << "CSStudent340: Hi!" << endl;

}

};

int main() {

CSStudent340 stuM{ "Mickey" };

cout << "Stu: " << stuM.getName() << endl;

unique_ptr stu{ make_unique("Minnie") };

stu->sayHi();

stu->sayHello();

return 0;

}

I know that the program output 10 lines but I do not know why. Can you please explain.

These are the line the program outputs. Student(), constructor called. CSStudent340(stuName), constructor called. Stu: Student Student(), constructor called. CSStudent340(stuName), constructor called. CSStudent340: Hi! Student: Hello! ~Student(), destructor called. ~CSStudent340(), destructor called. ~Student(), destructor called.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Concepts Of Database Management

Authors: Joy L. Starks, Philip J. Pratt, Mary Z. Last

9th Edition

1337093424, 978-1337093422

More Books

Students also viewed these Databases questions

Question

Understand the importance of strategic HR planning.

Answered: 1 week ago

Question

Explain the functions of financial management.

Answered: 1 week ago

Question

HOW MANY TOTAL WORLD WAR?

Answered: 1 week ago

Question

Discuss the scope of financial management.

Answered: 1 week ago

Question

Discuss the goals of financial management.

Answered: 1 week ago

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago