class with array in c++ (memory allocatin & using array in classes)

 class with array in c++ (memory allocatin & using array in classes)

#include<iostream>
using namespace std;
class shop
{
    int itemId[100];
    int itemprice[100];
    int counter;
    public:
    void initcounter(void){counter=0;}
    void setprice(void);
    void displayprice(void);
};
void shop::setprice(void){
 cout<<"Enter Id your item no "<<counter+1<<endl;
 cin>>itemId[counter];
  cout<<"Enter price your item"<<endl;
  cin>>itemprice[counter];
   counter++;
}
void shop::displayprice(void){
    for(int i=0;i<counter;i++)
    {

cout<<"the price of item with Id "<< itemId[i]  <<" is "<<itemprice[i]<<endl;   
    }
}
int main()
{
    shop dukan;
    dukan.initcounter();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.setprice();
    dukan.displayprice();
    return 0;

output___



Comments

Popular posts from this blog

constructor with default arguments

constructor overloading in c++ programming