C++ programme to calculate the no.of objects created of a particular class type



#include<iostream.h>
#include<conio.h>

class just
{
               int x;
               public:
               void enter()
               {              cout<<"Enter a value of x:";
                              cin>>x;
               }
               void out()
               {
                              cout<<"The value is:"<<x<<endl;
               }
};


int main()
{
               just j;
               char ch='y';
               int i=0;
               while(ch=='y')
               {
                              j.enter();
                              i++;
                              cout<<"Do you eant to continue:";
                              cin>>ch;
               }
               cout<<"The number of objects created are:"<<i;
               return 0;
}

OUTPUT:


Enter a value of x:4
Do you want to continue
Enter a value of x:7
Do you want to continue
The number of objects created are:2

No comments:

Post a Comment