Answer to Question #183040 in C++ for Smith

Question #183040

Create a class Index which keeps track of the Index value. Write an overloaded function to display the index value after increment and decrements the Index value.


1
Expert's answer
2021-04-19T07:03:29-0400
#include <iostream>
 
using namespace std;
 
class Index
{
public:
	Index();
	~Index();
	static void Display();
private:
	static int index;
};
 
int Index::index = 0;
 
Index::Index()
{
	index++;
	Display();
}
 
Index::~Index()
{
	index--;
	Display();
}
 
void Index::Display()
{
	cout << "Index current value is: " << index << endl;
}
 
int main()
{
	Index Obj1;
	Index Obj2;
	Index Obj3;
 
	cout << endl;
	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