CIS 22B quiz 2 Write 7. Write the member string your name here now opening line
ID: 3903879 • Letter: C
Question
CIS 22B quiz 2 Write 7. Write the member string your name here now opening line and private data for a class named CompleteStockltem. It has an int data named onHand. It inherits from the class Stockitem which has member data description and double cost. Donot code the closing ). yet, we win oode public: I/ this makes the functions that are coded later public 8. Write a default constructor code. for the class CompleteStockltem, using a minimum amount of class 9. Write a copy constructor for the class CompleteStockltem using a constructor initialization list to invoke the base class copy constructor 10. Write a constructor that has three parameters and sets the values of the member data to the values of the parameters. It shall use a constructor initialization list to invoke the base class constructor that takes two parameters. 11. Write a function that returns the total cost. The total cost is the product of cost and onHand. bvExplanation / Answer
class CompleteStockItem : public StockItem {
private:
int onHand;
public:
CompleteStockItem() : StockItem() {
onHand = 0;
}
CompleteStockItem(const CompleteStockItem &c) : StockItem(c) {
this->onHand = c.onHand;
}
CompleteStockItem(string desc, double cost, int onHand) : StockItem(desc, cost) {
this->onHand = onHand;
}
double getTotalCost() {
return onHand * cost;
}
}