Question

In: Computer Science

What is invalid about each of the following program? Fixed the error once you find it....

What is invalid about each of the following program? Fixed the error once you find it. (You may find more than one errors in the code.)

Question

#include <iostream>
#include <iomanip>
using namespace std;
class B {
protected:
virtual void func1() { cout << "base:" << endl; }
};
class D1 : public B {
void func1() { cout << "D2:" << endl; }
};
class D2 : public B {};
int main() {
B Bobj;
D1 Dobj;
B* p = Dobj;
p->func1();
}

Solutions

Expert Solution

Below is the corrected code snippet.

#include <iostream>
#include <iomanip>
using namespace std;
class B {
public://make this function public
virtual void func1() { cout << "base:" << endl; }
};
class D1 : public B {
//this is private
void func1() { cout << "D2:" << endl; }
};
class D2 : public B {};
int main() {
B Bobj;
D1 Dobj;
B p = Dobj;
p.func1();//call function
}

============================


Related Solutions

Chapter 9 (Pointers) - Review Questions Find the Error Each of the following definitions and program...
Chapter 9 (Pointers) - Review Questions Find the Error Each of the following definitions and program segments has errors. Locate as many as you can. 46. int ptr* = nullptr; 47. int x, *ptr = nullptr; &x = ptr; 48. int x, *ptr = nullptr; *ptr = &x; 49. int x, *ptr = nullptr; ptr = &x; ptr = 100; //Store 100 in x cout << x << endl; 50. int numbers[] = {10, 20, 30, 40, 50}; cout <<...
There are at least 10 errors in the following C program. For each error you can...
There are at least 10 errors in the following C program. For each error you can find you should list the location of the error, describe what the error is, and state how the error can be fixed (write updated code for that line if necessary). Each error you find is worth 1.5 marks. Note that missing brackets, braces, etc count as only one error, even though the missing brackets may occur at two places. The program is supposed to...
There are at least 10 errors in the following C program. For each error you can...
There are at least 10 errors in the following C program. For each error you can find you should list the location of the error, describe what the error is, and state how the error can be fixed (write updated code for that line if necessary). Each error you find is worth 1.5 marks. Note that missing brackets, braces, etc count as only one error, even though the missing brackets may occur at two places. The program is supposed to...
There are at least 10 errors in the following C program. For each error you can...
There are at least 10 errors in the following C program. For each error you can find you should list the location of the error, describe what the error is, and state how the error can be fixed (write updated code for that line if necessary). Each error you find is worth 1.5 marks. Note that missing brackets, braces, etc count as only one error, even though the missing brackets may occur at two places. The program is supposed to...
Determine each of the following arguments’ forms to be valid or invalid. You may use the...
Determine each of the following arguments’ forms to be valid or invalid. You may use the Venn Diagram proof method, the rules/fallacies method, or any other method, of your choice. 1. Some athletes are not baseball players and some baseball players are not basketball players. Therefore, some athletes are not basketball players.2. All creationists are fundamentalists because all fundamentalists are religious people and all creationists are religious people. 3. As no conservationists are litterers, no environmentalists are litterers, because all...
Solve the following problems about margin of error basics. a. What is the margin of error...
Solve the following problems about margin of error basics. a. What is the margin of error for estimating a population mean, given the following information and a confidence level of 90%? σ =15 & n = 100 b. What is the margin of error for estimating a population mean given the following information and a confidence level of 90%? σ =5 & n = 500 c. What is the margin of error for estimating a population mean given the following...
Find the error in each of the following code segments and explain how to correct it....
Find the error in each of the following code segments and explain how to correct it. x = 1; while ( x <= 10 ); x++; } for ( y = .1; y != 1.0; y += .1 System.out.println( y ); switch ( n ) { case 1: System.out.println( “The number is 1” ); case 2: System.out.println( “The number is 2” ); break; default: System.out.println( “The number is not 1 or 2” ); break; } The following code should print...
What is the difference between a valid and an invalid complaint? Give an example of each....
What is the difference between a valid and an invalid complaint? Give an example of each. What is the difference in how these are treated from a customer service standpoint?
You find the following financial information about a company: net working capital = $1,032; fixed assets...
You find the following financial information about a company: net working capital = $1,032; fixed assets = $6,089; total assets = $8,542; and long-term debt = $4,567. What are the company's total liabilities?
What information do you need to find residual standard error?
What information do you need to find residual standard error?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT