Question: Create a class named Item that has a double data member cost. The class also has a static int data member number. This static data

Create a class named Item that has a double data member cost. The class also has a static int data member number. This static data member records how many Item objects were created. It should be initialized to 0. Whenever a new object is created, number should be incremented by 1. Your class should provide the following:
(a) A constructor (cost defaults to 1.0). Note: the cost should be at least 1.0.
(b) A destructor that decrements number by 1 and prints "An Item has been destroyed".
(c) A set and a get function for the data member cost.
(d) A static member function getNumber that returns the value of number.
(e) A toString member function that returns the string representation of an /tem object. e.g., Assume that there is an Item object with the data member cost 12.34, x.toString() should return "$12.34".
Write a main function to test the class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!