Question: In C++ Add a static member variable to InventoryItem class called number_articles, of type int. This variable should keep how item articles are sold by
In C++
Add a static member variable to InventoryItem class called number_articles, of type int. This variable should keep how item articles are sold by the store. Add a static member function called getNumberArticles that return that number.
InventoryItem.h ===========================================================================
class InventoryItem {
public: // Constructor InventoryItem(char *desc, double c, int u); // Destructor ~InventoryItem();
const char *getDescription() const;
double getCost() const;
int getUnits() const;
private: char *description; // The item description double cost; // The item cost int units; // Number of units on hand
};
--------------------------------------------------------------------------------------------------------------------------------
InventoryItem.cpp =======================================================================
#include "InventoryItem.h"
using namespace std;
InventoryItem::InventoryItem(char *desc, double c, int u){
description = desc;
cost = c;
units = u;
}
InventoryItem::~InventoryItem(){
}
const char* InventoryItem::getDescription() const{
return description;
}
double InventoryItem::getCost() const{
return cost;
}
int InventoryItem::getUnits() const{
return units;
}
---------------------------------------------------------------------------------------------------------------------------
test_main.cpp ======================================================================
#include "InventoryItem.h"
#include
using namespace std;
int main(){
InventoryItem i1 = InventoryItem("Apples", 10.09, 5);
cout<<"Item Details-";
cout<<" Description: "< cout<<" Cost: "< cout<<" Units: "< return 0; } --------------------------------------------------------------------------------------------------------------------
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
