-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathshopsUsingClassAndArray.cpp
More file actions
51 lines (44 loc) · 1.3 KB
/
Copy pathshopsUsingClassAndArray.cpp
File metadata and controls
51 lines (44 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//Q/ shop and its product details using array and class
#include<iostream>
using namespace std;
class shop
{
// private by default
int itemId[100], itemPrice[100], counter;
public:
//can be accessed outside the class
void initCounter(void){ counter=0; } //counter function
void setPrice(void);
void displayPrice(void);
};
//take input from the user for the price
void shop :: setPrice(void){
cout<<"enter Id of your item number: "<<counter+1 <<endl;
cin>>itemId[counter];
cout<<"enter price of your item : " <<endl;
cin>>itemPrice[counter];
counter++;
}
//it will show the price of the item
void shop ::displayPrice(void){
for(int i=0; i<counter ;i++)
{
// here itemId and item Price are private data members so they can be accessed through member functions
cout<<"price of the item with itemId: "<<itemId[i]<< " is: "<<itemPrice[i]<<endl;
}
}
int main(){
int n;
//here dukan is a object
shop dukaan;
//counter function needed to be called before using counter variable
//otherwise it will throw show some garbage value
dukaan.initCounter();
cout<<"enter the number of items your shop have"<<endl;
cin>> n;
for (int j=0; j<n; j++){
dukaan.setPrice();
}
dukaan.displayPrice();
return 0;
}