Write a C++ program to classes with static member functions.




Algorithm:
Step 1: Create a class as the item.
Step 2: Declare the data members.
Step 3: Declare the member functions.
Step 4: In the main, create an object for the class.
Step 5: Call the function.
Step 6: Get the output.
Step 7: Stop the program.

Program Code:
#include<iostream.h>
#include<conio.h>
class item
{
static int count;
int num;
public:
void getdata(int a)
{
num=a;
count++;
cout<<"Number : "<<num<<endl;
}
void showcount()
{
cout<<"count : ";
cout<<count<<”\n”;
}
};
int item::count;
int main()
{
item a,b,c;
clrscr();
a.showcount();
b.showcount();
c.showcount();
a.getdata(20);
b.getdata(30);
c.getdata(40);
a.showcount();
b.showcount();
c.showcount();
getch();
}




Output:
count : 0
count : 0
count : 0
Number : 20
Number : 30
Number : 40
count : 3
count : 3
count : 3
Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: