Answer to Question #242052 in C++ for Zeeshan

Question #242052
Write a class that displays a simple message “I am object no. __”, on the screen
whenever an object of that class is created.
1
Expert's answer
2021-09-25T05:20:32-0400
#include<iostream>
using namespace std;
 static int x = 0;
class Parent{
	public:
	
		
	
	Parent(){


	
		x++;
	}
};


int main(){
	Parent p;
	cout<<"I am object no "<<x<<endl;
	Parent n;
	cout<<"I am object no "<<x<<endl;
	Parent a;
	cout<<"I am object no "<<x<<endl;
	Parent b;
	cout<<"I am object no "<<x<<endl;
	Parent c;
	cout<<"I am object no "<<x<<endl;
	Parent d;
	cout<<"I am object no "<<x<<endl;
}

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