Answer to Question #234707 in C++ for SOM

Question #234707

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-09T04:10:06-0400
Errors
Invalid use of static keyword
Invalid use of member test::y
 Cannot call member function void test::output(); without an object.

The corrected code:

#include<iostream>
using namespace std;


class test
{  
private:
int x;


   int y;


public:


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


       void display()


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


        void output()


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


 };


int main()


{  test T1;


   T1.display();


 T1.output();


   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