// This tut contains C++ Objects Memory Allocation & using Arrays in Classes
#include<iostream>
using namespace std;
class Store {
int itemId[50];
int itemPrice[50];
int counter;
public:
void initCounter(void){counter=0;}
void setPrice();
void displayPrice();
};
void Store :: setPrice(void){
cout<<"Enter itemId of an item "<<counter +1<<":"<<endl;
cin>>itemId[counter];
cout<<"Enter price of an item "<<counter +1<<":"<<endl;
cin>>itemPrice[counter];
counter++;
cout<<endl;
}
void Store :: displayPrice(void)
{
for (int i = 0; i < counter; i++)
{
cout<<"Displaying price of item with itemId "<<itemId[i]<<" is : "<<itemPrice[i]<<endl;
cout<<endl;
}
}
int main()
{
Store shop;
shop.initCounter();
// shop.setPrice();
// shop.setPrice();
// shop.setPrice();
// shop.displayPrice();
int no_of_items;
cout<<"Enter no of items shop :"<<endl;
cin>>no_of_items;
for (int i = 0; i < no_of_items; i++)
{
shop.setPrice();
cout<<endl;
}
shop.displayPrice();
return 0;
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.