-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtut23.cpp
46 lines (40 loc) · 940 Bytes
/
tut23.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
// C++ Objects Memory Allocation & using Arrays 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 of your item no. " << counter + 1 << endl;
cin >> itemid[counter];
cout << "Enter Price of 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 dukaan ;
dukaan.initcounter();
// you can call them inside the loop also.
dukaan.setPrice();
dukaan.displayPrice();
// dukaan.setPrice();
// dukaan.setPrice();
// dukaan.displayPrice();
return 0;
}