Simple Program for Static Data and Member Function Using C++ Programming
Aim
To count the object value using the storage keyword static.
Static Data and Member Function Algorithm/Steps:
- STEP 1: Start the program.
- STEP 2: Declare the class name as Stat with data members and member functions.
- STEP 3: The constructor Stat() which is used to increment the value of count as 1 to assign the variable code.
- STEP 4: The function show code() to display the code value.
- STEP 5: The function showcount() to display the count value.
- STEP 6: Stop the program.
Simple Program for Static Data and Member Function
#include<iostream.h>
#include<conio.h>
class stat {
int code;
static int count;
public:
stat() {
code = ++count;
}
void showcode() {
cout << "\n\tObject number is :" << code;
}
static void showcount() {
cout << "\n\tCount Objects :" << count;
}
};
int stat::count;
void main() {
clrscr();
stat obj1, obj2;
obj1.showcount();
obj1.showcode();
obj2.showcount();
obj2.showcode();
getch();
}
Sample Output
Count Objects: 2
Object Number is: 1
Count Objects: 2
Object Number is: 2
C++ Function Example Programs
- Simple Example Program for Function In C++
- Simple Example Program for Function Find Smallest Number In C++
- Simple Example Program for Function to Find Factorial In C++
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Function Overloading Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Area Of Circle using Friend Function - C++Program
Read More Articles
- Simple Merge Sort Program in C++
- Scope Resolution Operator In C++
- Simple Program for Virtual Functions Using C++ Programming
- Simple Class Example Program For Find Prime Number In C++
- Simple Example Program For Parameterized Constructor In C++
- Define Constructor in Outside Class Example Program In C++
- Simple Program for Function Overloading Using C++ Programming
- Simple Example Program For Copy Constructor In C++
- Simple Program for Single Inheritance Using C++ Programming
- Simple Program for Inline Function without Class Using C++ Programming
- Factorial Using Function Example Program In C++
- Simple Example Program For Constructor Overloading In C++
- Simple Example Program For Constructor In C++
- Simple Addition ( Add Two Integers ) Example Program
- Simple Example Program for Inline Function Using C++ Programming
- Simple Program for Read user Input Using cin
- Factorial Using Loop Example Program In C++
- Simple Stack Program in C++ Programming
- Simple Program for Friend Function Using C++ Programming
- Simple Program for Static Data and Member Function Using C++ Programming
- Simple Program for Unary Operator Overloading Using C++ Programming
- Simple Program for Multiple Inheritance Using C++ Programming
- Do While Loop Example Program In C++
- Simple Copy Constructor Example Program For Find Factorial In C++
- Simple Program for Function Template Using C++ Programming