Answer to Question #201838 in C++ for Prem Kamthe

Question #201838

Write a C++ program to create a class Number, which contain static data member 'cnt' and member function Display()'. Display() should print number of times display operation is performed irrespective of the object responsible for calling Display().


1
Expert's answer
2021-06-02T03:01:46-0400


#include <iostream>


using namespace std;
class Number{
    public:
        void display(){
            static int cnt=1;
            cout<<"\nDisplay function is called "<<cnt<<" times"<<endl;
            cnt++;
        }
};
int main()
{
    Number n1,n2;
    n1.display();
    n1.display();
    n2.display();
    n2.display();
    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