Answer to Question #266093 in C++ for 1H|2|=

Question #266093

(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.


1
Expert's answer
2021-11-15T00:30:56-0500
#include<iostream>
using namespace std;
class Item{
	private:
		int number;
		float price;
	public:
		void inputData(){
			cout<<"Enter the number of items: ";
			cin>>number;
			cout<<"Enter the price of the items:  "; cin>>price;
		}
		void display(){
			cout<<"Number of items is:  "<<number<<"\nPrice of items is: "<<price<<endl;
		}
};


int main(){
	Item i1;
	i1.inputData();
	i1.display();
	
	Item * i2;
	i2 = &i1;
	i2->display();
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS