Hello, I am trying to get the stock count to print for each of the toys: ps3, elmo, and wii. I don't have any clue on how to do it. To print the stockcount, i created the function getStock to try to do the job. Can someone help me get the stock count to print for each toy? Thanks!
My .cpp and .h file is below
Here is the code:
.cpp file
#include <iostream>
#include <iomanip>
using namespace std;
#include "Unknown.h"
int main()
{
toyType ps3("Playstation3",500,2000);
toyType elmo;
cout<<"Toyname"<<" Cost "<<" Stock"<<endl;
ps3.print();
cout<<"Toyname"<<" Cost"<<" Stock"<<endl;
elmo.print();
elmo.modifyALL();
ps3.sale(2);
cout<<endl;
cout<<"Toyname"<<" Cost"<<" Stock"<<endl;
elmo.print();
cout<<endl;
cout<<"Toyname"<<" Cost "<<" Stock"<<endl;
ps3.print();
cout<<endl;
elmo.changeCost(100);
elmo.add2stock(100);
elmo.print();
toyType Wii("Wii");
cout<<endl;
cout<<"There is a new toy called: "<<endl;
Wii.print();
elmo.getStock();
ps3.getStock();
Wii.getStock();
getStock.print();
system ("PAUSE");
return 0;
}
.h file
class toyType
{
public:
void print() const;
void modifyALL();
toyType(string m, double c, int stoc);
toyType();
void sale(int s);
void changeCost(double cos);
void add2stock(int s);
toyType(string m);
void getStock() const;
private:
string toyname;
double cost;
int stockcount;
};
void toyType::print()const
{
// cout<<"Toyname"<<" Cost "<<"Stock"<<endl;
cout<<toyname<<" $ "<<cost<<" "<<stockcount<<endl;
}
toyType::toyType(string m, double c, int stoc)
{
toyname = m;
cost = c;
stockcount = stoc;
}
toyType::toyType()
{
toyname = "Unknown";
cost = 0;
stockcount = 0;
}
void toyType::modifyALL()
{
cout<<endl;
cout<<"Enter new information below..."<<endl;
cout<<"Enter Toy name: "<<endl;
cin>>toyname;
cout<<"Enter Cost of toy: "<<endl;
cin>>cost;
cout<<"Enter number in stock: "<<endl;
cin>>stockcount;
}
void toyType::sale(int s)
{
cout<<endl;
cout<<"Entering the sales section..."<<endl;
cout<<"2 Playstation3(s) sold. There are now 1998 Playstation3(s) in stock"<<endl;
cout<<endl;
stockcount -= s;
}
void toyType::changeCost (double cos)
{
cost += cos;
}
void toyType::add2stock(int s)
{
cout<<"The cost and stock for Elmo has changed to..."<<endl;
cout<<endl;
stockcount+=s;
}
toyType::toyType(string m)
{
toyname = m;
cost = 0;
stockcount = 0;
}
int toyType::getStock()
{
cout<<"There are currently "<<getStock.print()<<" ps3s in stock."<<endl;
cout<<endl;
cout<<"There are currently "<<getStock.print()<<" wiis in stock."<<endl;
cout<<endl;
cout<<"There are currently "<<getStock.print()<<" elmos in stock."<<endl;
cout<<endl;
}