Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Language / Type:C + + inheritance polymorphism Consider the following classes; assume that each is defined in its own file. class Hamburger : public Bacon

Language/Type:C++ inheritance polymorphism
Consider the following classes; assume that each is defined in its own file.
class Hamburger : public Bacon {
public:
virtual void m2(){
cout "H 2" endl;
Bacon::m2();
}
virtual void m4(){
cout "H 4" endl;
}
};
class Mayo : public Hamburger {
public:
virtual void m3(){
cout "M 3" endl;
m1();
}
virtual void m4(){
cout "M 4" endl;
}
};
class Lettuce {
public:
virtual void m1(){
cout "L 1" endl;
m2();
}
virtual void m2(){
cout "L 2" endl;
}
};
class Bacon : public Lettuce {
public:
virtual void m1(){
Lettuce::m1();
cout "B 1" endl;
}
virtual void m3(){
cout "B 3" endl;
}
};
Now assume that the following variables are defined:
Lettuce* var1= new Bacon();
Bacon* var2= new Mayo();
Lettuce* var3= new Hamburger();
Bacon* var4= new Hamburger();
Lettuce* var5= new Lettuce();
In the table below, indicate in the right-hand column the output produced by the statement in the left-hand column. If the statement produces more than one line of output, indicate the line breaks with slashes as in "x / y / z" to indicate three lines of output with "x" followed by "y" followed by "z". If the statement does not compile, write "COMPILER ERROR". If a statement would crash at runtime or cause unpredictable behavior, write "CRASH".You passed 15 of 18 tests. Try again.
\table[[#,question,your answer,result],[1,var1->m1(),L1/L2/B1,pass],[2,var1->m2();,L2,pass],[3,var1->m3(),COMPILER ERROR,pass],[4,var2->m1(),M 4/L1/L2,ox fail],[5,var2->m2(),H2/L2,pass],[6,var2->m3(),M 4/L1/L2,ox fail],[7,var2->m4(),COMPILER ERROR,pass],[8,var3->m1(),M 4/L1/L2,x fail],[9,var3->m2(),H2/L2,pass],[10,var4->m2(),H 2/ L 2,pass],[11,var4->m3(),B 3,pass],[12,var4->m4(),COMPILER ERROR,pass],[13,(( Bacon*) var 1)->m1();,L1/L2/B1,pass],[14,(( Bacon*) var1)->m3();,B 3,pass],[15,(( Mayo*) var5)->m3();,CRASH,pass],[16,((Lettuce*) var4)->m3();,COMPILER ERROR,pass],[17,(( Hamburger*)var2)->m4();,M 4,pass],[18,(( Mayo*)var2)->m4(),M 4,pass]]
image text in transcribed

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

Databases Illuminated

Authors: Catherine M. Ricardo

1st Edition

0763733148, 978-0763733148

More Books

Students also viewed these Databases questions

Question

Describe the various ways in which secured interests are perfected.

Answered: 1 week ago