Question
C++ Problem Im having a hard time making this work, please help! OurStack class is a code from a different file i have to impliment
C++ Problem
Im having a hard time making this work, please help! OurStack class is a code from a different file i have to impliment to the program i made. How can i get this to run?
//OurStack.h
#ifndef OURSTACK_H
#define OURSTACK_H
#include
#include
using namespace std;
template
class OurStack :
{
private:
int nomberOfItems;
float costPerItem;
public:
bool isEmpty() const; //Test if stack is empty
const T& top() const;//Returns refference to top
bool pop(); // removes top of stack
bool push(const T& newEntry);
~OurStack();
};
#include"OurStack.cpp"
#endif
//OurStack.cpp
#include
#include
#include"OurStack.h"
//OurStack.cpp
template
OurStack
{
}
template
bool OurStack
if( ourStack.empty())
return true;
else
false;
}
template
bool OurStack
ourStack.push(newEntry);
if (ourStack.top() == newEntry)
return true;
else
return false;
}
template
bool OurStack
if (!ourStack.empty()) {
ourStack.pop();
return true;
}
else
return false;
}
template
const T& OurStack
return ourStack.top();
}
//InventoryEquipment.h
#include
#include
using namespace std;
#ifndef INVENTORYEQUIPMENT_H
#define INVENTORYEQUIPMENT_H
class InventoryEquipmentPurchase
{
private:
stack
int totalUnits;
float totalPurchaseCost;
float currentCost;
float currentSalesPrice;
//float money;
public:
InventoryEquipmentPurchase();
void purchase(int no_of_unit, int purchase_price); //purchse algo
void sales(int no_of_unit); //sales algo
void setCurrentCost(float _current_cost);
float getNetWorth();
int getInventory();
};
#endif
//InventoryEquipment.cpp
#include "InventoryEquipment.h"
#include"OurStack.h"
#include
using namespace std;
InventoryEquipmentPurchase::InventoryEquipmentPurchase()
{
totalPurchaseCost = 0;
totalUnits = 0;
}
void InventoryEquipmentPurchase::purchase(int no_of_unit, int purchase_price) //purchse algo
{
struct ourStack temp;
temp.nomberOfItems = no_of_unit;
temp.costPerItem = purchase_price;
no_of_tracker.push(temp);
totalPurchaseCost += no_of_unit * purchase_price;
//money-=no_of_unit*purchase_price; //money out for purchase
totalUnits += no_of_unit;
currentCost = purchase_price;
currentSalesPrice = 1.2*currentCost; //20% higher than current_cost
cout << no_of_unit << " fitness tracker purchased at price " << purchase_price << "." << endl;
}
void InventoryEquipmentPurchase::sales(int no_of_unit) //sales algo
{
ourStack temp;
temp = no_of_tracker.top();
int latest_unit = temp.nomberOfItems;
no_of_tracker.pop();
while (latest_unit { temp = no_of_tracker.top(); latest_unit += temp.nomberOfItems; no_of_tracker.pop(); } if (latest_unit>no_of_unit) { temp.nomberOfItems = latest_unit - no_of_unit; no_of_tracker.push(temp); //money+=no_of_unit*current_sales_price; //money come from sales } totalUnits -= no_of_unit; cout << no_of_unit << " fitness tracker slaed at price " << currentSalesPrice << "." << endl; cout << "Now " << totalUnits << " fitness tracker remaining." << endl; } void InventoryEquipmentPurchase::setCurrentCost(float _current_cost) { currentCost = _current_cost; currentSalesPrice = 1.2*currentCost; cout << "Now, current_sales_price=" << currentSalesPrice << endl; } float InventoryEquipmentPurchase::getNetWorth() { float totalSalePrice = totalUnits * currentSalesPrice; float purchase_cost = 0; stack demo = no_of_tracker; struct ourStack temp; int counter = demo.size(); for (int i = counter; i>0; i--) //get purch cost of remaining unit { temp = demo.top(); purchase_cost += temp.nomberOfItems*temp.costPerItem; demo.pop(); } return totalSalePrice - purchase_cost; } int InventoryEquipmentPurchase::getInventory() { return totalUnits; } //Main #include #include #include"InventoryEquipment.h" using namespace std; int main() { InventoryEquipmentPurchase i1; i1.purchase(10, 100); i1.purchase(10, 125); i1.purchase(10, 150); i1.setCurrentCost(200); i1.sales(15); cout << "Currnt Networth=" << i1.getNetWorth() << endl; system("pause"); return 0; } Thank You!!!!!!!!!!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started