Write a
C++ program to create a class Item with data members Item_code, Item_name,Item_price.
Write member functions to accept and display Item information also display number of
objects created for a class. (Use static data member and Static member function)
#include<iostream.h>
#include<conio.h>
class Item
{
int Item_code;
char Item_name[30];
int Item_price;
static int count;
public:
void getdata()
{
cout<<"\nEnter the code of the
Item:";
cin>>Item_code;
cout<<"\nEnter the name of the
Item:";
cin>>Item_name;
cout<<"\nEnter the price of
the Item:";
cin>>Item_price;
cout<<"************************************";
}
void displaydata()
{
cout<<"\n1.Item
Code:"<<Item_code;
cout<<"\n2.Item
Name:"<<Item_name;
cout<<"\n3.Item
price:"<<Item_price;
}
static void cnt()
{
count++;
cout<<"\nNumber of Objects
Created:"<<count;
}
};
int Item::count;
int main()
{
int i,n;
Item t[10];
clrscr();
cout<<"\n\n*********** Accepting
Book Details ***********";
cout<<"\nHow many records you
want to enter:";
cin>>n;
for(i=0;i<n;i++)
{
t[i].getdata();
}
for(i=0;i<n;i++)
{
t[i].displaydata();
}
for(i=0;i<n;i++)
{
t[i].cnt();
}
getch();
return 0;
}