forked from codebloded/BackToBasics.cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayOfObjects.cpp
More file actions
42 lines (38 loc) · 910 Bytes
/
arrayOfObjects.cpp
File metadata and controls
42 lines (38 loc) · 910 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
#include<iostream>
using namespace std;
class Items{
private:
int id;
float price;
public:
void setData(int a , int b)
{
id =a;
price = b;
}
void getData(void){
cout<<"The id of item is: "<<id<<endl;
cout<<"The price of the item is:"<<price<<endl;
}
};
int main()
{
int i ,x, size=2 ;
float y;
Items *ptr = new Items[size];
//This is the another pointer which stores the address of ptr ;
Items *temp =ptr;
for(i=0; i<size ; i++){
cout<<"Enter the values of item id and price "<<i+1<<endl;
cin>>x>>y;
ptr->setData(x,y);
ptr++;
}
//Loop fo displaying the value of the items id and item price ;
for(i=0; i<size; i++){
cout<<"Item number: "<<i+1<<endl;
temp->getData();
temp++;
}
return 0;
}