76 248
Assignments Done
Successfully Done
In May 2019

Answer to Question #40782 in C++ for tydoh priscilla

Question #40782
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.
Expert's answer
#include <iostream>
using namespace std;

class CounterClass {
static int counter;
int number;

CounterClass() {
number = ++counter;

void tell_number() {
cout << "I am object " << number << endl;

int CounterClass::counter = 0;

int main() {
CounterClass obj1;
CounterClass obj2;
CounterClass obj3;

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!


Assignment Expert
13.11.18, 17:13

Dear Vaikalya, you're welcome!

12.11.18, 18:14

thank you very much:)

Assignment Expert
22.05.14, 16:33

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!

19.05.14, 03:07

good job.
helped me a lot.
thank u sooooooooo much.

Leave a comment

Ask Your question

Privacy policy Terms and Conditions