create a class that includes a data member that holds a serial number for each object created from a class. that is the first object will be numbered 1 , the second 2 and so on. then each object is create , its constructor can examine this count member variable to determine thhe approprate serial number for the new object.
add a member function that permits an object to report its own serial number . then the main() program that creates three objects and queries each one about its serial number. they should respond i am object 2, and so on.
1
Expert's answer
2014-04-07T12:17:42-0400
#include <iostream> using namespace std;
class CounterClass { private: static int counter; int number;
public: CounterClass() { number = ++counter; };
void tell_number() { cout << "I am object " << number << endl; }; };
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Dear Vaikalya, you're welcome!
thank you very much:)
Dear Ayesha, You're welcome. We are glad to be helpful. If you liked our service please press like-button beside answer field. Thank you!
good job. helped me a lot. thank u sooooooooo much.
Leave a comment