-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtut52.cpp
More file actions
48 lines (43 loc) · 998 Bytes
/
tut52.cpp
File metadata and controls
48 lines (43 loc) · 998 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
#include <iostream>
using namespace std;
class shop
{
int id;
int price;
public:
void setdata(int a, int b)
{
id = a;
price = b;
}
void getdata()
{
cout << "The id of the item is: " << id << endl;
cout << "The price of the item is: " << price << endl;
}
};
int main()
{
int p,size = 3;
float q;
shop *pr = new shop[size];
shop *temp = pr;
for (int i = 0; i < size; i++)
{
cout << "Enter the data of the item: " << i + 1<<endl;
cin >> p >> q;
// (*pr).setdata(p, q);
pr->setdata(p, q);
pr++;
}
for (int i = 0; i <size ; i++)
{
cout<<"The item no is: "<<i+1<<endl;
temp->getdata();
temp++;
}
return 0;
}
/* we use two pointer becaue after first for loop pointer is increment at the end
and the point to another pointer or array so we made temp which was eaqual to the first
pointer and point for printitng the loop */