-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patht18.cpp
More file actions
49 lines (43 loc) · 895 Bytes
/
Copy patht18.cpp
File metadata and controls
49 lines (43 loc) · 895 Bytes
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
/*--------------array of object using pointer-----------------------
*/
#include <iostream>
using namespace std;
class shopitem
{
int id;
float price;
public:
void setdata(int a, int b)
{
id = a;
price = b;
}
void getdata()
{
cout << "the id of item is" << id << endl;
cout << "the price of item is" << price << endl;
}
};
int main()
{
int a,i;
float b;
int size = 2;
shopitem *p = new shopitem[size];
shopitem *p1 = p;
for ( i = 0; i < size; i++)
{
cout << "enter id and price of item :" << i + 1 << endl;
cin >> a >> b;
// (*p).setdata(p,q);
p->setdata(a, b);
p++;
}
for (i = 0; i < size; i++)
{
cout << "item number:" << i + 1;
p->getdata();
p1++;
}
return 0;
}