Code:
********************************************
VideoItem class
************************************
#pragma once
#include <string>
using namespace std;
class VideoItem
{
public:
VideoItem(); //default constructor
~VideoItem(); //deconstructor
VideoItem (const VideoItem & vi);
VideoItem (string n, int c, int qStore, int qS, int qB, int qRO, int qFS, int qFR);
string ToString();
void FromString(string s);
static string HeaderString();
string getname();
int getCodeNum ();
int getStorequantity ();
void setStorequantity (int qStore);
int getForSalequantity ();
void setForSalequantity (int qFS);
int getForRentquantity ();
void setForRentquantity (int qFR);
void randomize();
private:
string name; // name of video
int CodeNum; //unique code of video
int Storequantity;//quantity store owned
int Soldquantity;//quantity sold
int Boughtquantity;//quantity bought
int RentedOutquantity;//quantity rented out
int ForSalequantity; //quantity for sale
int ForRentquantity;// quantity for rent
};
#include "VideoItem.h"
#include "misc.h"
#include <iostream>
using namespace std;
VideoItem::VideoItem()
{
name = " ";
CodeNum = 0;
Storequantity = 0;
Soldquantity = 0;
Boughtquantity = 0;//quantity bought
RentedOutquantity = 0;//quantity rented out
ForSalequantity = 0; //quantity for sale
ForRentquantity = 0;// quantity for rent
}
VideoItem::VideoItem (string n, int c, int qStore, int qS, int qB, int qRO, int qFS, int qFR)
{
name = n;
CodeNum = c;
Storequantity = qStore;
Soldquantity = qS;
Boughtquantity = qB;
RentedOutquantity = qRO;
ForSalequantity = qFS;
ForRentquantity = qFR;
}
void VideoItem::randomize()
{
name=randString(3);
CodeNum=randInt(1,999999999);
Storequantity=randInt(10,100000);
RentedOutquantity=randInt(0,10000);
Soldquantity=randInt(0,10000);
ForSalequantity=randInt(0,10000);
ForRentquantity=randInt(1,1000);
}
string VideoItem::ToString()
{
string result="";
result+=padRight(name,' ',15);
result+=padLeft(intToString(CodeNum),'0',10);
result+=padLeft(intToString(Storequantity),' ',8);
result+=padLeft(intToString(RentedOutquantity),' ',8);
result+=padLeft(intToString(Soldquantity),' ',6);
result+=padLeft(intToString(ForSalequantity),' ',6);
result+=padLeft(intToString(ForRentquantity),' ',6);
return result;
}
string VideoItem::HeaderString()
{
char fill='-';
string result="";
result+=padRight("Video Name",fill,15);
result+=padLeft("Code",fill,10);
result+=padLeft("In Store",fill,8);
result+=padLeft("Rented Out",fill,8);
result+=padLeft("Sold",fill,6);
result+=padLeft("For Sale",fill,6);
result+=padLeft("For Rent",fill,6);
return result;
}
VideoItem::~VideoItem()
{
}
*************************************************************
VideoStore class
****************************************************
#pragma once
#include "VideoItem.h"
using namespace std;
class VideoStore
{
public:
VideoStore();
~VideoStore();
void run ();
void listCommand();
void generateRandItems(int num);
void help();
void buy();
void rebuy();
void rent();
void sell();
void report();
void test();
private:
VideoItem inventory;
};
#include "VideoStore.h"
#include "misc.h"
#include <iostream>
using namespace std;
void VideoStore::run()
{
string command = "";
cout <<"Welcome to CW Video Store.\n"<<endl;
cout << "Please enter a command >";
cin>>command;
while((command!="QUIT")&&(command!="7"))
{
if ((command == "HELP")||(command == "0"))
listCommand();
else if ((command == "BUY")||(command =="1"))
buy();
else if ((command == "REBUY")||(command =="2"))
rebuy();
else if ((command == "RENT")||(command == "3"))
rent();
else if ((command == "SELL")||(command == "4"))
sell();
else if ((command == "REPORT")||(command == "5"))
report();
else if ((command == "TEST")||(command == "6"))
{
generateRandItems(10);
}
else if ((command == "Quit")||(command == "7"))
cout <<"Goodbye."<<endl;
else
cout << "** Not a valid command **" << endl;
cout << "Re-Enter a command: ";
cin >> command;
}
}
void VideoStore::listCommand()
{
cout <<"CW Video Store Commands"<<endl;
cout <<"**--------------------------------**"<<endl;
cout <<"0) HELP - list the commands"<<endl;
cout <<"7) QUIT - leave the store"<<endl;
cout <<"1) BUY - add new video to the inventory"<<endl;
cout <<"2) REBUY - add an existing video to the inventory"<<endl;
cout <<"3) RENT - rent a video"<<endl;
cout <<"4) SELL - sell a video"<<endl;
cout <<"5) REPORT - list of all videos"<<endl;
cout <<"6) TEST - generate 10 random videos"<<endl;
void VideoStore::buy()
{
string name;
int c;
int qB;
cout <<"Please enter the video's name: ";
cin >>name;
cout <<"Enter the code number: ";
cin >>c;
cout <<"Enter quantity being bought: ";
cin >>qB;
VideoItem newVideo(string n, int c, int qb);
inventory.push_back(newVideo);
cout <<"[video saved]" <<endl;
cout <<endl;
}
void VideoStore::rebuy()
{
int c;
int qB;
cout <<"Please enter the video's code number: "<<endl;
cin >>c;
cout <<"Enter quantity being bought: "<<endl;
cin >> qB;
refVi.setStorequantity (refVi.getStorequantity() + qB);
}
void VideoStore::rent()
{
int c;
int qFR;
cout <<"Please enter the video's code number: "<<endl;
cin >>c;
if (qStore!=0)
refVi.setquantityRentedOut (refVi.getquantityRentedOut() + 1);
else
{cout <<"There are no available videos"<<endl;}
}
void VideoStore::sell()
{
int c;
int qS;
cout <<"Please enter the video's code number: "<<endl;
cin >>c;
cout <<"Quantity being sold: "<<endl;
cin >>qS;
if (qStore!=0)
refVi.setStorequantity (refVi.getStorequantity()- 1);
else
{cout <<"There are no available videos"<<endl;}
}
void VideoStore::report()
{
cout<<VideoItem::HeaderString()<<endl;
for(unsigned int i=0;i<inventory.size();i++)
{
cout<< inventory.getItem(i).ToString()<<endl;
}
}
void VideoStore::generateRandItems(int num)
{
VideoItem vi;
for(int i=0;i<num;i++)
{
vi.randomize();
inventory.addNewVideo(vi);
//VideoItem.push_back(vi);
}
}
VideoStore::VideoStore()
{
inventory.clear();
}
VideoStore::~VideoStore()
{
inventory.clear();
}
int main()
{
VideoStore myStore;
myStore.run();
return 0;
}