Advertisements
Advertisements
Question
Debug the following program.
%include(iostream.h)
#include<conio.h>
class A()
{ public;
int a1,a2:a3;
void getdata[]
{ a1=15; a2=13; a3=13; } }
class B:: public A()
{ PUBLIC
voidfunc()
{ int b1:b2:b3;
A::getdata[];
b1=a1;
b2=a2;
a3=a3;
cout<<b1<<’\t’<<b2<<’t\’<<b3; }
void main()
{ B der;
der1:func(); }
Answer in Brief
Solution
Modified Error Free Program :
using namespace std;
#include<iostream>
#include<conio.h>
class A
{
public:
int a1,a2,a3;
void getdata()
{
a1=15;
a2=14;
a3=13;
}
};
class B : public A
{
public:
void func()
{
int b1,b2,b3;
A::getdata();
b1=a1;
b2=a2;
b3=a3;
cout<<b1<<‘\n'<<b2<<‘\n'<<b3;
}
};
int main()
{
B der;
der.func();
getch();
return 0;
}
Output:
—————
15
14
13
shaalaa.com
Is there an error in this question or solution?