Question 3 Three class definitions and a main function are given below: class A { public: }; class B public A { public: }; int }; class C public B { public: } -A() { std::cout << "-A()" << std::endl; } void f1() { std::cout << "A.fl()" << std::endl; } void f2() { std::cout << "A.f2()" << std::endl; } virtual void f3() = 0; B() {} virtual void f1() { std::cout << "B.fl()" << std::endl; } void f2() { std::cout << "B.f2()" << std::endl; } void f3() { std::cout << "B.f3()" << std::endl; } } C() { c = new int(0); } -C() { delete c; std::cout << "~C()" << std::endl; } void f1() { std::cout << "c.fl()" << std::endl; } void f2() { std::cout << "C.f2()" << std::endl; } void f3() { std::cout << "c.f3()" << std::endl; } int* c; The parts below provide a definition for the function f() called in main. For each part, 1) write the output of the program using the provided definition for f(), 2) if the code will result in a compilation error, write ERROR and briefly state why, and 3) if a memory leak exists, briefly state where the leak exists. } main() { f(); return 0; a. void f() { B b; A a = b; a.f2(); b. void f() { A a new C(); a->fl(); a->f2(); a->f3(); delete a; C. void f() { с с; B b = c; } b.fl(); b.f2(); b.f3(); d. void f() { } B* b = new C(); A* a = b; a->f1(); a->f2(); a->f3(); delete a;
Question 3 Three class definitions and a main function are given below: class A { public: }; class B public A { public: }; int }; class C public B { public: } -A() { std::cout << "-A()" << std::endl; } void f1() { std::cout << "A.fl()" << std::endl; } void f2() { std::cout << "A.f2()" << std::endl; } virtual void f3() = 0; B() {} virtual void f1() { std::cout << "B.fl()" << std::endl; } void f2() { std::cout << "B.f2()" << std::endl; } void f3() { std::cout << "B.f3()" << std::endl; } } C() { c = new int(0); } -C() { delete c; std::cout << "~C()" << std::endl; } void f1() { std::cout << "c.fl()" << std::endl; } void f2() { std::cout << "C.f2()" << std::endl; } void f3() { std::cout << "c.f3()" << std::endl; } int* c; The parts below provide a definition for the function f() called in main. For each part, 1) write the output of the program using the provided definition for f(), 2) if the code will result in a compilation error, write ERROR and briefly state why, and 3) if a memory leak exists, briefly state where the leak exists. } main() { f(); return 0; a. void f() { B b; A a = b; a.f2(); b. void f() { A a new C(); a->fl(); a->f2(); a->f3(); delete a; C. void f() { с с; B b = c; } b.fl(); b.f2(); b.f3(); d. void f() { } B* b = new C(); A* a = b; a->f1(); a->f2(); a->f3(); delete a;
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
f18
In c++

Transcribed Image Text:### Question 3
Three class definitions and a main function are given below:
```cpp
class A {
public:
~A() { std::cout << "~A()" << std::endl; }
void f1() { std::cout << "A.f1()" << std::endl; }
void f2() { std::cout << "A.f2()" << std::endl; }
virtual void f3() = 0;
};
class B : public A {
public:
B() {}
virtual void f1() { std::cout << "B.f1()" << std::endl; }
void f2() { std::cout << "B.f2()" << std::endl; }
void f3() { std::cout << "B.f3()" << std::endl; }
};
class C : public B {
public:
C() { c = new int(0); }
~C() { delete c; std::cout << "~C()" << std::endl; }
void f1() { std::cout << "C.f1()" << std::endl; }
void f2() { std::cout << "C.f2()" << std::endl; }
void f3() { std::cout << "C.f3()" << std::endl; }
int* c;
};
int main() {
f();
return 0;
}
```
The parts below provide a definition for the function `f()` called in `main`. For each part:
1. Write the output of the program using the provided definition for `f()`.
2. If the code will result in a compilation error, write ERROR and briefly state why.
3. If a memory leak exists, briefly state where the leak exists.
#### a.
```cpp
void f() {
B b;
A a = b;
a.f2();
}
```
#### b.
```cpp
void f() {
A* a = new C();
a->f1();
a->f2();
a->f3();
delete a;
}
```
#### c.
```cpp
void f() {
C c;
B b = c;
b.f1();
b.f2();
b.f3();
}
```
#### d.
```cpp
void f() {
B* b = new C();
A* a
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education