Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include using namespace std; // Here are class and function definitions used in program: // This program does run! Indicate output (if any) for each

#include

using namespace std;

// Here are class and function definitions used in program:

// This program does run! Indicate output (if any) for each numbered line.

// A class definition

class G // base class, thinking of Geometric objects

{

public:

G() { cout << "makeG ";}

~G() { cout << "Ggone " << endl;}

virtual void fun() const = 0;

protected:

int data;

};

// another class, thinking like a Box (rectangle)

class B : public G

{

public:

B(int i) : data(i) { cout << "makeB " << endl;}

~B() { cout << "Bgone ";}

void fun() const { cout << data * data << endl;}

// so the B fun does a square (data*data)

private:

int data;

};

// and another class, Circular reasoning

class C : public G

{

public:

C() { cout << "makeC " << endl; data = 8;}

~C() { cout << "Cgone ";}

void fun() const { cout << data << endl;}

};

// some functions using above classes

void gee(G& one) {one.fun();}

void bee(B& two) {cout << "bee works" << endl;}

void sea(C& the)

{

C *see = new C();

cout << "sea works ";

delete see;

}

// The main driver: Indicate output (if any) for each numbered line.

void main()

{

G *g; // 1.

B *b = new B(2); // 2.

C *c = new C(); // 3.

b->fun(); // 4.

c->fun(); // 5.

g = b; // 6.

g->fun(); // 7.

b->fun(); // 8.

c->fun(); // 9.

gee(*b); // 10.

bee(*b); // 11.

sea(*c); // 12.

// one of these casts could halt execution, thus the try-catch

// your answers below must clearly indicate where the exception is thrown:

try

{

static_cast(g)->fun(); // 13.

static_cast(g)->fun(); // 14.

dynamic_cast(g)->fun(); // 15.

dynamic_cast(g)->fun(); // 16.

}

catch (...) // catches any thrown exception in Visual Studio

{

cout << "can't do that" << endl;

}

// Some pointer math (start HEX with AAAAAAAA)

cout << g << endl; // 17.

cout << b << endl; // 18.

cout << c << endl; // 19.

c++;

cout << c << endl; // 20.

}

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_2

Step: 3

blur-text-image_3

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

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

What is the basis for Security Concerns in Cloud Computing?

Answered: 1 week ago

Question

Describe the three main Cloud Computing Environments.

Answered: 1 week ago