Answer to Question #239531 in C++ for Happy

Question #239531

Find the errors in the following program and correct them.

[Assume the necessary header files and namespaces included]

class test

{ static int x;

int y;

public:

test( ){x=0;y=0;}

static void display()

{ cout<<x<<”\t”<<y<<endl; }

void output()

{cout<<x<<”\t”<<y<<endl;}

};

int main()

{ test T1;

T1.display();

test::output();

return 0;

}


1
Expert's answer
2021-09-21T04:02:46-0400
#include <iostream>

using namespace std; 

class test{ 
static int x;
int y;

public:
test( ){
	y=0;
}
static void display()

{
	 cout<<x<<"\t"<<endl; }

void output()

{cout <<x<<"\t"<<y<<endl;}

};
int test::x=1;


int main()

{ test T1;

T1.output();

test::display();

return 0;

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS