-
Notifications
You must be signed in to change notification settings - Fork 0
/
23_malloc_using_array.cpp
64 lines (53 loc) · 1.39 KB
/
23_malloc_using_array.cpp
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
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <iostream>
using namespace std;
class Shop
{
int itemId[100];
int itemPrice[100];
int counter;
public:
void initCounter(void) { counter = 0; }
void setData(void);
void displayPrice(void);
// void setData(void)
// {
// cout << "Enter the Id of your item no " << counter + 1 << endl;
// cin >> itemId[counter];
// cout << "Enter the Price of your item " << endl;
// cin >> itemPrice[counter];
// counter++;
// }
// void displayPrice(void)
// {
// for (int i = 0; i < counter; i++)
// {
// cout << "The price of the item with Id " << itemId[i] << " is " << itemPrice[i] << endl;
// }
// }
};
//We can declare any function outside of the class using scope resolution operator (::)
void Shop :: setData(void)
{
cout << "Enter the Id of your item no " << counter + 1 << endl;
cin >> itemId[counter];
cout << "Enter the Price of your item " << endl;
cin >> itemPrice[counter];
counter++;
}
void Shop :: displayPrice(void)
{
for (int i = 0; i < counter; i++)
{
cout << "The price of the item with Id " << itemId[i] << " is " << itemPrice[i] << endl;
}
}
int main()
{
Shop s;
s.initCounter();
s.setData();
s.setData();
s.setData();
s.displayPrice();
return 0;
}