Answer to Question #289831 in C++ for Nik

Question #289831

Spspecify a class item having data members item number and item cost also specify two member function getdata() and putdata() create object of item class and called the function


1
Expert's answer
2022-01-22T16:33:06-0500
#include<iostream>

using namespace std;

class Item
{
	int itNumber;
	double itCost;
public:
	Item(int _itNumber, int _itCost):itNumber(_itNumber),itCost(_itCost){}
	Item(){}
	
	void putdata()
	{
		cout << "\nPlease, enter an item number: ";
		cin >> itNumber;
		cout << "Please, enter an item cost: ";
		cin >> itCost;
	}
	void getdata()
	{
		cout << "\nItem number is "<<itNumber;
		cout << "\nItem cost is " << itCost;
	}
};

int main()
{
	Item a(1, 80);
	a.getdata();
	Item b;
	b.putdata();
	b.getdata();
}

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