(Pointers to objects) Define a class Item that is used to store and display the information regarding the item number and its price. Write a program to store and display the details of one items by using both normal object and pointer to object separately. Display
appropriate message wherever necessary.
#include<iostream>
using namespace std;
class Item{
public:
int num,p;
double price;
void getDetails(){
cout<<"Enter the number of the items: ";
cin>>num;
cout<<"Enter the price of the item: ";
cin>>p;
price=num*p;
}
void Display(){
cout<<"The price of the item is: "<<price;
}
};
int main(){
Item m;
m.getDetails();
m.Display();
}
Comments
Leave a comment