In this program, we are going to see how to increment COUNT as per user input in C++ Programming Language.
The Code given below can be used in TURBO C++ Compilers: -
//C++ program to increment COUNT whenever called from the user.
#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
class Class
{
public:
static int count;
Class();
};
int Class::count = 0;
Class::Class()
{
count++;
}
void main()
{
system("cls");
cout << "Initial value of count:- " << Class::count << endl;
int x, i = 0;
cout << "How many times object is to be called?\n";
cin >> x;
Class obj[x];
cout << "Value of count after object is initialized : " << Class::count;
getch();
}
//.........Coded by YASH ALAPURIA
The Code given below can be used in gcc/g++ Compilers: -
//C++ program to increment COUNT whenever called from the user.
#include<iostream>
#include<stdlib.h>
using namespace std;
class Class
{
public:
static int count;
Class();
};
int Class::count = 0;
Class::Class()
{
count++;
}
int main(void)
{
system("cls");
cout << "Initial value of count:- " << Class::count << endl;
int x, i = 0;
cout << "How many times object is to be called?\n";
cin >> x;
Class obj[x];
cout << "Value of count after object is initialized : " << Class::count;
return 0;
}
//.........Coded by YASH ALAPURIA
#ENJOY CODING
Post a Comment
FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP