Please Help. I\'ve included both the question of the program and the part that I
ID: 3631848 • Letter: P
Question
Please Help. I've included both the question of the program and the part that I have completed and I need help real bad to complete the rest. Part A thru J are completed, can someone finish the rest, the highlighted areas. What I have included does compile. Below is the question of the program and after is the part I've done. There are 2 more posts related to this and I will award lifesaver ratings to those also.
Question:
Write a inventory program that will manage an inventory of videos owned by the store that buys videos from a wholesaler and then sells them and rents them to customers. It will now also manage a list of customers that are renting the videos.
A) Each video record will manage a name , a code number (unique), a quantity owned by the store, a quantity that are currently rented out and a quantity that have been sold.
B) The program will accept the following commands listed below:
C) HELP will list the commands.
D) QUIT will end the program.
E) BUY will prompt the user for a name, code and quantity bought by the store. It will then add the new item to the inventory. (This command is used the first time a specific video is bought by the store from the wholesaler.)
F) REBUY will prompt the user for a code and a quantity bought by the store. It will then add this quantity to the amount owned by the store. (This command is used when the store buys additional videos for an item that it has previously bought from the wholesaler.)
G) RENT will prompt the user for a code and will then increase (by one) the quantity of the number rented out for that video provided that a video is available. Otherwise it will print a polite message saying that no videos are currently available.
H) SELL will prompt the user for a code and will then decrease (by one) the quantity of the number owned by the store and increase (by one ) the number sold provided that a video is available. Otherwise it will print a polite message saying that no videos are currently available.
I) REPORT will neatly display a list all the videos on the screen. For each video listed there will be a name, code, quantity owned by the store, a quantity rented out, a quantity sold and a quantity available for sale or rent.
J) TEST will generate and add 10 random videos to the inventory with appropriate values for all the information on each video. Each of these new videos will have a random name with 3 letters.
K) You will add a new class called Person. Each Person will have a string name and a string phoneNumber and a string address.
L) You will add a new class called Renter which will inherit from Person as described in class. Each renter will have a unique ID number and a vector of integers for keeping track of the video codes of the videos that they have currently rented out.
M) The new command ADD_RENTER will allow a new Renter of videos to be added to the system. Each renter will have a string name, a string phone number, a string address and a integer id number. The command will prompt for each of these fields.
N) The new command REPORT2 will neatly display on the screen the list of all the renters sorted by the renter’s code number. The display will show their ID number followed by the name followed by their phone number. (All on one line.) Indented underneath this line will be listed all of the videos that he or she has currently rented out. Each video in this sub list will include the Code number of the video and the
name of the video. For Example the REPORT2 could display something that looks like this:
Renter IDNumber Name Phone number
0000146 John Doe 555-555-5555
Video IDNumber 0000002 Road Trip
Video IDNumber 0008523 Wine Tasting for Dummies
Renter IDNumber Name Phone number
0007412 Jane Doe 210-555-5555
Video IDNumber 0008523 Wine Tasting For Dummies
VIdeo IDNumber 0008745 Jaws
Renter IDNumber Name Phone number
0002548 John Smith 718-555-5555
Renter IDNumber Name Phone number
0009874 Mary Poppins 866-555-5555
Video IDNumber 0008523 Wine Tasting For Dummies
Video IDNumber 0008745 Jaws
O) The RENT command will also prompt the user for the ID number of the renter. It will also add the Video’s Code number to the list of videos rented out by the specified renter. It will create a polite error message if the entered ID or Code numbers are not valid.
P) The RETURN command will prompt for a Video Code Number and a Renter ID Number and in the Video’s record it will reduce the number rented out by one and in the Renter’s record will remove the Video’s ID from the list of rented records. It will create a polite error message if the entered ID or Code numbers are not valid or if the renter specified has not rented out the video specified.
Q) The class VideoStore will be persistent.
R) You will provide in the same directory as your sln file a file called CriteriaNotMet.txt where you will list the criteria in this assignment that you have not met on a single line separated by commas.
S) The system must now support names of videos and renters that include blanks. It must also support blanks in the address and phone numbers of renters. (Use getline to input these values.)
T) The system must support a LOAD and SAVE command that will allow the entire state of the VideoStore to be saved on the hard drive.
Answer A thru J:
//Inventory Class:
//Inventory.h
#pragma once
#include "VideoItem.h"
#include <vector>
using namespace std;
enum SortStatus {unsorted,sortedByName,sortedByCode};
class Inventory
{
public:
Inventory(){sortStatus=unsorted;}
void addNewItem(const VideoItem & vi);
//void ADD_RENTER(const Renter & ri);
unsigned int size() { return vectorOfVideoItem.size();}
//unsigned int code() { return vectorOfVideoItem.code();}
VideoItem getItem(int i);
VideoItem & getItemByCode(int c);
void sortByCode();
void sortByName();
void clear(){sortStatus=unsorted;vectorOfVideoItem.clear();}
SortStatus getSortStatus(){return sortStatus;}
void setSortStatus(SortStatus ss){sortStatus=ss;}
bool isUsedCode(int c);
private:
VideoItem & Inventory::getItemByCodeInRange(int c,int startIndex, int endIndex);
SortStatus sortStatus;
vector<VideoItem> vectorOfVideoItem;
};
//Inventory.cpp
#include "Inventory.h"
#include <algorithm>
void Inventory::addNewItem(const VideoItem & vi)
{
vectorOfVideoItem.push_back(vi);
sortStatus=unsorted;
}
VideoItem Inventory::getItem(int i)
{
return vectorOfVideoItem[i];
}
bool Inventory::isUsedCode(int c)
{
VideoItem & refGi = getItemByCode(c);
if(refGi.getName()=="")
{
return false;
}
else
{
return true;
}
}
VideoItem & Inventory::getItemByCode(int c)
{
sortByCode();
return getItemByCodeInRange(c,0,vectorOfVideoItem.size()-1);
}
VideoItem & Inventory::getItemByCodeInRange(int c,int startIndex, int endIndex)
{
int middle=(startIndex+endIndex)/2;
if(endIndex==-1)
{
VideoItem * pNullItem = new VideoItem;
return *pNullItem;
}
if(vectorOfVideoItem[middle].getCode()==c)
{
return vectorOfVideoItem[middle];
}
else if(startIndex==endIndex)
{
VideoItem * pNullItem = new VideoItem;
return *pNullItem;
}
else if(startIndex==middle)
{
return getItemByCodeInRange(c,endIndex,endIndex);
}
else if(c<vectorOfVideoItem[middle].getCode())
{
return getItemByCodeInRange(c,startIndex,middle);
}
else
{
return getItemByCodeInRange(c,middle,endIndex);
}
}
void Inventory::sortByCode()
{
if(sortStatus!=sortedByCode)
{
sort(vectorOfVideoItem.begin(),vectorOfVideoItem.end());
sortStatus=sortedByCode;
}
}
void Inventory::sortByName()
{
if(sortStatus!=sortedByName)
{
sort(vectorOfVideoItem.begin(),vectorOfVideoItem.end(),compareVideoItemsByName);
sortStatus=sortedByName;
}
}
//*****************************************************//
//VideoItem class
//VideoItem.h
#pragma once
#include <string>
using namespace std;
class VideoItem
{
public:
VideoItem();
VideoItem(const VideoItem & vi);
VideoItem(string n,int c,int q);
~VideoItem();
string ToString();
void FromString(string s);
static string HeaderString();
void randomize();
string getName() {return name;}
void setName(string s){name=s;}
int getCode(){return code;}
int getQuantityStoreOwn() {return quantityStoreOwn;}
void setQuantityStoreOwn(int qso) {quantityStoreOwn=qso;}
int getQuantitySold() { return quantitySold;}
void setQuantitySold(int qs) {quantitySold = qs;}
int getQuantityRented() {return quantityRented;}
void setQuantityRented(int qr) {quantityRented = qr;}
bool operator < (const VideoItem & rhs);
bool isLessThan(const VideoItem & rhs);
private:
string name;
int code;
int quantityStoreOwn;
int quantitySold;
int quantityRented;
};
bool compareVideoItemsByName(VideoItem & gi1,VideoItem & gi2);
//VideoItem.cpp
#include "VideoItem.h"
#include "misc.h"
VideoItem::VideoItem()
{
name="";
code=0;
quantityStoreOwn=0;
quantitySold=0;
quantityRented=0;
}
VideoItem::VideoItem(const VideoItem & vi)
{
name=vi.name;
code=vi.code;
quantityStoreOwn=vi.quantityStoreOwn;
quantitySold=vi.quantitySold;
quantityRented=vi.quantityRented;
}
VideoItem::VideoItem(string n,int c,int q)
{
name=n;
code=c;
quantityStoreOwn=q;
quantitySold=0;
quantityRented=0;
}
bool VideoItem::operator < (const VideoItem & rhs)
{
bool b =(code<rhs.code);
return b;
}
bool VideoItem::isLessThan(const VideoItem & rhs)
{
bool b =(code<rhs.code);
return b;
}
void VideoItem::randomize()
{
name=randString(3);
code=randInt(1,99999);
quantityStoreOwn=randInt(10,1000);
quantitySold=randInt(0,1000);
quantityRented=randInt(0,quantityStoreOwn + 1);
}
void VideoItem::FromString(string s)
{
int startAt=0;
int fieldWidth;
fieldWidth=15;
name=s.substr(startAt,fieldWidth);
startAt+=fieldWidth;
fieldWidth=10;
code = stringToInt(s.substr(startAt,fieldWidth));
startAt+=fieldWidth;
fieldWidth=8;
quantityStoreOwn = stringToInt(s.substr(startAt,fieldWidth));
startAt+=fieldWidth;
fieldWidth=8;
quantitySold = stringToInt(s.substr(startAt,fieldWidth));
startAt+=fieldWidth;
fieldWidth=6;
quantityRented = stringToInt(s.substr(startAt,fieldWidth));
startAt+=fieldWidth;
}
string VideoItem::ToString()
{
string result="";
result+=padRight(name,' ',15);
result+=" " + padLeft(intToString(code),'0',12);
result+=padLeft(intToString(quantityStoreOwn),' ',10);
result+=padLeft(intToString(quantitySold),' ',10);
result+=padLeft(intToString(quantityRented),' ',10);
int avail = quantityStoreOwn - quantityRented;
result+=padLeft(intToString(avail),' ',15);
return result;
}
string VideoItem::HeaderString()
{
char fill='-';
string result="";
result+=padRight("Item Name",fill,15);
result+=padLeft("Code",fill,12);
result+=padLeft("In Store",fill,10);
result+=padLeft("Sold",fill,10);
result+=padLeft("Rented",fill,10);
result+=padLeft("ForRent/Sale",fill,15);
return result;
}
VideoItem::~VideoItem()
{
}
bool compareVideoItemsByName(VideoItem & gi1, VideoItem & gi2)
{
return gi1.getName()<gi2.getName();
}
**********************************************************************//
//VideoStore class
//VideoStore.h
#pragma once
#include "Inventory.h"
using namespace std;
class VideoStore
{
public:
VideoStore(){load("VideoStore.txt");}
~VideoStore(){save("VideoStore.txt");}
void run();
void rebuyVideoItem();
void saleOfVideoItem();
void addNewVideoItem();
void rentalOfVideoItem();
void ADD_RENTER();
void inventoryReport();
void inventoryReportByCode();
void inventoryReportByName();
void inventoryReportByRenterID();
void generateRandItems(int num);
void help();
void save();
void load();
void save(string fileName);
void load(string fileName);
private:
Inventory inventory;
};
//VideoStore.cpp
#include "VideoStore.h"
#include "Renter.h"
#include "misc.h"
#include <iostream>
#include <fstream>
using namespace std;
void VideoStore::run()
{
help();
string command="";
while((command!="QUIT")&&(command!="99"))
{
cout<<"Enter a command >";
cin>>command;
stringToUpper(command);
if((command=="BUY")||(command=="1"))//buy new videeo
{
addNewVideoItem();
}
else if((command=="INVENTORYREPORTBYNAME")||(command=="31"))//report by name
{
inventoryReportByName();
}
else if((command=="INVENTORYREPORTBYCODE")||(command=="32"))//report by code
{
inventoryReportByCode();
}
else if((command=="REBUY")||(command=="2"))//rebuy an existing item
{
rebuyVideoItem();
}
else if((command=="RENT")||(command=="3"))//rental of video
{
rentalOfVideoItem();
}
else if((command=="SELL")||(command=="4"))//sale of video
{
saleOfVideoItem();
}
else if((command== "NEW RENTER")||(command=="20"))//add new renter
{
ADD_RENTER();
}
else if((command=="TEST")||(command=="71"))//random test
{
generateRandItems(10);
inventoryReportByCode();
}
//else if ((command=="REPORT2")||(command=="25"))//print REPORT2
//{
//inventoryReportByRenterID();
//}
else if((command=="QUIT")||(command=="99"))
{
cout <<"Goodbye"<<endl;
}
else if ((command=="HELP")||(command=="0"))
{
help();
}
else if ((command=="SAVE")||(command=="41"))
{
save();
}
else if ((command=="LOAD")||(command=="42"))
{
load();
}
else
{
cout<<"Unrecognized command."<<endl;
}
}
}
void VideoStore::help()
{
cout<<"Welcome to C++ VideoStore"<<endl;
cout<<"*---------------------------------------*"<<endl;
cout<<"*---------------------------------------*"<<endl;
cout<<"COMMANDS ARE "<<endl;
cout<<"----------------------"<<endl;
cout<<" 0) HELP"<<endl;
cout<<endl;
cout<<" 1) BUY"<<endl;
cout<<" 2) REBUY"<<endl;
cout<<" 3) RENT"<<endl;
cout<<" 4) SELL"<<endl;
cout<<endl;
cout<<"20) NEW RENTER"<<endl;
cout<<endl;
cout<<"25) INVENTORYREPORTBYRENTERID"<<endl;
cout<<endl;
cout<<"31) INVENTORYREPORTBYNAME"<<endl;
cout<<"32) INVENTORYREPORTBYCODE"<<endl;
cout<<endl;
cout<<"41) SAVE"<<endl;
cout<<"42) LOAD"<<endl;
cout<<endl;
cout<<"71) TEST"<<endl;
cout<<endl;
cout<<"99) QUIT"<<endl;
cout<<endl;
}
void VideoStore::save()
{
string fileName;
cout<<"File name >";
cin >> fileName;
save(fileName);
}
void VideoStore::save(string fileName)
{
inventory.sortByCode();
ofstream fout;
fout.open(fileName.c_str());
for(unsigned int i=0;i<inventory.size();i++)
{
fout<< inventory.getItem(i).ToString()<<endl;
}
cout<<"File saved to "<<fileName<<endl;
}
void VideoStore::load()
{
string fileName;
cout<<"File name >";
cin >> fileName;
load(fileName);
}
void VideoStore::load(string fileName)
{
ifstream fin;
fin.open(fileName.c_str());
if(!fin.fail())
{
string inputLine;
VideoItem gi;
inventory.clear();
do
{
getline(fin,inputLine);
if(!fin.eof())
{
gi.FromString(inputLine);
inventory.addNewItem(gi);
}
}
while(!fin.eof());
inventory.setSortStatus(sortedByCode);
}
}
void VideoStore::rebuyVideoItem()//rebuy video
{
int c;
int q;
cout<<"Enter Code >";
cin >> c;
VideoItem & refVi = inventory.getItemByCode(c);
if(refVi.getName()=="")
{
cout<<"Error: "<<c<<" is an invalid Video Item Code."<<endl;
}
else
{
cout<<"Quantity being rebought >";
cin >> q;
refVi.setQuantityStoreOwn(refVi.getQuantityStoreOwn() + q);
}
}
void VideoStore::saleOfVideoItem()//sell video
{
int c;
int qS;
cout<<"Please Enter Video Code >";
cin >> c;
VideoItem & refVi = inventory.getItemByCode(c);
if(refVi.getName()=="")
{
cout<<"Error: "<<c<<" is an invalid Video Item Code."<<endl;
}
else
{
cout<<"Quantity being sold >";
cin >> qS;
refVi.setQuantityStoreOwn(refVi.getQuantityStoreOwn() - qS);
refVi.setQuantitySold(refVi.getQuantitySold() + qS);
}
}
void VideoStore::rentalOfVideoItem()//rent video
{
int c;
cout<<"Please Enter Code >";
cin >> c;
VideoItem & refVi = inventory.getItemByCode(c);
if(refVi.getName()=="")
{
cout<<"Error: "<<c<<" is an invalid Video Item Code."<<endl;
}
if(refVi.getQuantityStoreOwn() - refVi.getQuantityRented() > 0)
{
refVi.setQuantityRented (refVi.getQuantityRented() + 1);
}
else
{
cout<<"The video is not available. >"<<endl;
}
}
void VideoStore::addNewVideoItem()//buy new video
{
string n;
int c;
int q;//quantity
cout<<"Enter Video Name >";
cin >> n;
cout<<"Enter the Code >";
cin >> c;
while(inventory.isUsedCode(c))
{
cout<<"Warning: "<< c <<" code is already in use."<<endl;
cout<<"Enter different Code >";
cin >> c;
}
cout<<"quantity being bought >";
cin >> q;
VideoItem vi(n,c,q);
inventory.addNewItem(vi);
}
void VideoStore::ADD_RENTER()//add new renter
{
string n; //name
string p; //phone number
string a; //address
int ID; //id number
cout<<"Please Enter Your Name> "<<endl;
cin >> n;
cout<<"Your phone number> "<<endl;
cin >> p;
cout<<"Your address> "<<endl;
cin >> a;
cout<<"Enter a six-digit number for your ID> "<<endl;
cin >> ID;
Renter ri(n,p,a,ID);
//VideoStore.ADD_RENTER(ri);
}
void VideoStore::inventoryReport()
{
cout<<VideoItem::HeaderString()<<endl;
for(unsigned int i=0;i<inventory.size();i++)
{
cout<< inventory.getItem(i).ToString()<<endl;
}
}
void VideoStore::inventoryReportByCode()
{
inventory.sortByCode();
inventoryReport();
}
void VideoStore::inventoryReportByName()
{
inventory.sortByName();
inventoryReport();
}
void VideoStore::generateRandItems(int num)
{
VideoItem vi;
for(int i=0;i<num;i++)
{
vi.randomize();
while(inventory.isUsedCode(vi.getCode()))
{
vi.randomize();
}
inventory.addNewItem(vi);
}
}
***************************************************************************
//misc class
//misc.h
#pragma once
#include <string>
using namespace std;
void stringToLower(string & s);
void stringToUpper(string & s);
string padLeft(string s, char fill, unsigned int size);
string padRight(string s,char fill, unsigned int size);
string intToString(int x);
int stringToInt(string s);
string intToDollarString(int x);
int dollarStringToInt(string s);
string randString(int numOfChars);
int randInt(int lower,int upper);
//misc.cpp
#include "misc.h"
void stringToLower(string & s)
{
for(unsigned int i=0;i<s.length();i++)
{
s[i]=tolower(s[i]);
}
}
void stringToUpper(string & s)
{
for(unsigned int i=0;i<s.length();i++)
{
s[i]=toupper(s[i]);
}
}
string padLeft(string s,char fill, unsigned int size)
{
while(s.length()<size)
{
s= fill + s;
}
return s;
}
string padRight(string s,char fill, unsigned int size)
{
while(s.length()<size)
{
s= s + fill;
}
return s;
}
string intToString(int x)
{
string result;
char temp[256];
_itoa_s(x,temp,255,10);
result=temp;
return result;
}
int stringToInt(string s)
{
return atoi(s.c_str());
}
int dollarStringToInt(string s)
{
string s1 = s.erase(s.length()-3,1);
return stringToInt(s1);
}
string intToDollarString(int x)
{
string result=intToString(x);
result=padLeft(result,'0',3);
result.insert(result.length()-2,".");
return result;
}
string randString(int numOfChars)
{
string result;
for(int i=0;i<numOfChars;i++)
{
result+='A'+rand()%26;
}
return result;
}
int randInt(int lower,int upper)
{
if(upper-lower<RAND_MAX)
{
return (rand()%(upper-lower))+lower;
}
else
{
int r=rand()*RAND_MAX+rand();
return (r % (upper-lower))+lower;
}
}
//***********************************************************************************//
//Person class
//Person.h
#pragma once
#include <string>
using namespace std;
class Person
{
public:
Person();
Person(const Person & pi);
Person(string n, string p, string a);
~Person();
string getName() {return name;}
void setName (string n) {name =n;}
string getphoneNumber() {return phoneNumber;}
void setphoneNumber(string p) {phoneNumber =p;}
string getaddress() {return address;}
void setaddress (string a) {address = a;}
private:
string name;
string phoneNumber;
string address;
};
//*************************************************//
//Renter class
//Renter.h
//****************************************************//
#pragma once
#include <string>
#include <vector>
#include "Inventory.h"
#include "Person.h"
#include "VideoItem.h"
using namespace std;
class Renter : public Person
{
public:
Renter(string n, string p, string a, int ID);
int getIDNumber() {return IDNumber;}
void setIDNumber(int ID) { IDNumber = ID;}
//unsigned int size() {return VectorOfCodesOfVideosRentedOut.size();}
~Renter();
private:
int IDNumber;
//vector<int>VectorOfCodesOfVideosRentedOut; //vector of integers of videos codes checked out
};
//************************************************************************//
//main.cpp
#include "VideoStore.h"
using namespace std;
int main()
{
VideoStore myStore;
myStore.run();
return 0;
}