Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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::~OurStack()

{

}

template

bool OurStack::isEmpty() const {

if( ourStack.empty())

return true;

else

false;

}

template

bool OurStack::push(const T& newEntry) {

ourStack.push(newEntry);

if (ourStack.top() == newEntry)

return true;

else

return false;

}

template

bool OurStack::pop() {

if (!ourStack.empty()) {

ourStack.pop();

return true;

}

else

return false;

}

template

const T& OurStack::top() const {

return ourStack.top();

}

//InventoryEquipment.h

#include

#include

using namespace std;

#ifndef INVENTORYEQUIPMENT_H

#define INVENTORYEQUIPMENT_H

class InventoryEquipmentPurchase

{

private:

stack no_of_tracker;

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;

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 31st International Conference Dexa 2020 Bratislava Slovakia September 14 17 2020 Proceedings Part 1 Lncs 12391

Authors: Sven Hartmann ,Josef Kung ,Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil

1st Edition

303059002X, 978-3030590024

More Books

Students also viewed these Databases questions

Question

Understand how to view variable importance in predicting turnover

Answered: 1 week ago

Question

8. Provide recommendations for how to manage knowledge.

Answered: 1 week ago