Answer to Question #289832 in C++ for Suju

Question #289832

specify 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:36:14-0500
#include <iostream>


class Item
{
public:
	Item();
	~Item();


	void put_data(int cost, int number) // use this to set value
	{
		this->cost = cost;
		this->number = number;
	}
	void get_data() // use this to print value
	{
		std::cout << "Cost : " << this->cost << " , Number : " << number << std::endl;
	}


private:
	double cost;
	int number;
};


Item::Item()
{
	cost = 0;
	number = 0;
}


Item::~Item()
{
}


int main()
{
	Item item; //creating item


	
	int temp_number; // getting data from kb
	std::cout << "Enter number : ";
	std::cin >> temp_number;


	double temp_cost;
	std::cout << "Enter cost : ";
	std::cin >> temp_cost;


	item.put_data(temp_cost, temp_number);//set value


	std::cout << std::endl << "Your item : " << std::endl;//print value
	item.get_data();




	system("Pause");
    return 0;
}




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