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

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...
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?
Each of the following statements contains an error. Describe each error and explain why the statement...
Each of the following statements contains an error. Describe each error and explain why the statement is wrong. (a) If the residuals are all negative, this implies that there is a negative relationship between the response variable and the explanatory variable. (b) A strong negative relationship does not imply that there is an association between the explanatory variable and the response variable. (c) A lurking variable is always something that can be measured.
Trace through the program and what the outputs will be. If there is an error explain...
Trace through the program and what the outputs will be. If there is an error explain what must be fixed and continue to trace through. #include <iostream> using namespace std; void beans(int y, int& n, int size); void spam(int& n, int& y); int main(){ int m = 7; int n = 4; cout<<"m is "<<m<<" n is "<<n<<endl; beans(n, m, 3); cout<<"m is "<<m<<" n is "<<n<<endl; spam(m, n); cout<<"m is "<<m<<" n is "<<n<<endl; beans(m, 2, n); cout<<"m is...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT