Answer to Question #264306 in C++ for Amit

Question #264306

(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-11T07:31:55-0500
#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();
}

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