1.

Identify the error(s) in the following code fragment:class X {int a b;void count(void){a++;}public:int x;void init(int,int,int);void print(void);};void X::init(int i,int j,int k)  {a = i;b = j;x = k;}void X::print(void){count();cout<<"a="<<a;<<"b=" <<b<<"x="<<x<<"\";}void func(void);X Ob1;int main() {X Ob2;Ob1.init(0,1,2);Ob2.init(2,3,4);Ob1.print();Ob2.print();Ob1.count();Ob2.count();}void func(void)X Ob3;Ob1.init(4,5,6);Ob2.init(7,8,9);Ob3.init(9,10,11);Ob3.a = Ob3.b = Ob3.x;Ob1.count();Ob2.count();Ob3.count();Ob1.print();Ob2.print();Ob3.print();}

Answer»

# include<iostream.h>

# include <stdio.h>

class X  {

public:

int a,b;

void count(void)

{

a++;

}

int x; 

void init(int,int,int);

void print(void);

};

 void X::init(int i,int j,int k)

{

a = i; 

b = j;

x = k;

}

void X :: print(void)

{

count();

cout<<"a="<<a<<"b="

 <<b<<"x="<<x<<” ”;

}

void func(void);

 X Ob1;

 X Ob2;

int main() {

Ob1.init(0,1,2);

Ob2.init(2,3,4);

Ob1.print();

Ob2.print();

Ob1.count();

Ob2.count();

}

void func(void)

{

X Ob3;

Ob1.init(4,5,6);

Ob2.init(7,8,9);

Ob3.init(9,10,11);

Ob3.a = Ob3.b = Ob3.x;

Ob1.count();
Ob2.count();
Ob3.count();
Ob1.print();
Ob2.print();
Ob3.print();
}


Discussion

No Comment Found

Related InterviewSolutions