-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPointers4.cpp
More file actions
41 lines (37 loc) · 852 Bytes
/
Copy pathPointers4.cpp
File metadata and controls
41 lines (37 loc) · 852 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
#include<iostream>
using namespace std;
class ShopItem{
int id;
float price;
public:
void setData(int i, float p){
id = i;
price = p;
}
void getData(){
cout<<"The id of this item is: "<<id<<endl;
cout<<"The price of this item is: "<<price<<endl;
}
};
int main() {
int size = 5;
// int *ptr = &size;
// int *ptr = new int[34];
int p;
float q;
ShopItem *ptr = new ShopItem[size];
ShopItem *ptrTemp = ptr;
for(int i = 0; i < size; i++){
cout<< "Enter the Id and Price of this item "<< i+1<<endl;
cin>>p>>q;
ptr->setData(p,q);
ptr++;
}
for (int i = 0; i < size; i++)
{
cout<<"Item number: "<<i+1<<endl;
ptrTemp->getData();
ptrTemp++;
}
return 0;
}