Question 1 A) What is the output of this program when it is executed? [4 marks] B) Now suppose we edit this program and

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Question 1 A) What is the output of this program when it is executed? [4 marks] B) Now suppose we edit this program and

Post by answerhappygod »

Question 1
Question 1 A What Is The Output Of This Program When It Is Executed 4 Marks B Now Suppose We Edit This Program And 1
Question 1 A What Is The Output Of This Program When It Is Executed 4 Marks B Now Suppose We Edit This Program And 1 (86.27 KiB) Viewed 14 times
A) What is the output of this program when it is executed?
[4 marks]
B) Now suppose we edit this program and remove all occurrences of
the word virtual
from the code. When we recompile and execute it, what output does
it produce?
[4 marks]
C) When we execute this modified program with all the virtuals
removed, are there
any runtime errors? Justify your answer.
[3 marks
#include <iostream> #include <string> using namespace std; class Fruit { public: private: }; class Local Fruit : public Fruit { public: get_name (); } private: }; int main() { Fruit (string name) { name = new string (name); } virtual Fruit() { delete name; } virtual string get_name () const { return *name_;} string get_description () const { return "fruit: " + get_name(); } virtual string get_info() const { 11 return get_description () + on the table"; } string *name_; //fruit name. LocalFruit (string name, string type) Fruit (name) { type = new string (type); } virtual Local Fruit() { delete type_; } string get_description () const { return "local fruit "+ *type + ": virtual string get_info() const { return get_description () + " in the basement"; } string *type_; //fruit type Fruit *b = new Fruit ("Fruit King"); Fruit t = new Local Fruit ("Durian", "Musang King"); cout << b->get_description () << endl; cout << b->get_info() << endl; cout << t->get_description () << endl; cout << t->get_info () << endl; delete b; delete t; return 0; } continued on next page
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply