here is most of the relavent code:
Code:
//THIS IS THE HEADER FILE
#include<string>
#include<fstream>
#include<vector>
//I know, don't do this in a header, but at this point I am just trying to get it to work
using namespace std;
class item
{
public:
/*
This constructor accepts a string and creates an object with that name
@parameter- inputName: The name of the of the item
*/
item(string inputName);
/*
This function intializes a blank object
*/
item();
/*
This function returns the name of the item
@return: The name of the item
*/
string getName() const;
/*
This function outputs the members of item
@param stream: The stream the output is being written to
@param inputItem: The item that is being written to the stream
@return: The outputstream
*/
friend ostream &operator<<(ostream &stream, item inputItem);
/*
this function outputs the size of the name string followed by the name of the item to the stream given
@param outputStream: The stream to be written to
*/
void save(ofstream &outputStream);
/*
This function inputs the size of the name vector and then loads the name vector
@param inputStream: the file stream to be read from
@return: Whether the load was successful or not
*/
bool load(ifstream &inputStream);
/*
This function constructs an item with the contents of another item
@param inputItem: The item to be copied from
*/
// item(item const& inputItem);
/*
This operator assigns the values of another item to itself and returns a pointer to itself
@param inputItem: The item the values are being taken from
@return: a pointer to this item
*/
// item& operator = (item &inputItem);
private:
string name;
};
/*
This constructor accepts a string and creates an object with that name
@parameter- inputName: The name of the of the item
*/
item::item(string inputName)
{
name=inputName;
}
/*
This function intializes a blank object
*/
item::item()
{
}
/*
This function returns the name of the item
@return: The name of the item
*/
string item::getName() const
{
return name;
}
/*
This function outputs the members of item, first the length of the vector and then the vector name
@param stream: The stream the output is being written to
@param inputItem: The item that is being written to the stream
@return: The outputstream
*/
ostream &operator<<(ostream &stream, item inputItem)
{
stream<<inputItem.name.length() << inputItem.name;
return stream;
}
/*
this function outputs the size of the name string followed by the name of the item to the stream given
@param outputStream: The stream to be written to
*/
void item::save(ofstream &outputStream)
{
outputStream << *this;
}
/*
This function inputs the size of the name vector and then loads the name vector
@param inputStream: the file stream to be read from
@return: Whether the load was successful or not
*/
bool item::load(ifstream &inputStream)
{
int i;
char ch;
if(inputStream)
{
inputStream>>i;
}
else
{
return false;
}
for(int ii=0; ii<i && inputStream; ii++)
{
inputStream.get(ch);
name.push_back(ch);
}
if(i!=name.length())
{
return false;
}
else
{
return true;
}
}
/*
This function constructs an item with the contents of another item
@param inputItem: The item to be copied from
*/
/*
item::item(item const& inputItem)
{
name=inputItem.getName();
}
*/
/*
This operator assigns the values of another item to itself and returns a pointer to itself
@param inputItem: The item the values are being taken from
@return: a pointer to this item
*/
/*
item& item::operator = (item &inputItem)
{
name=inputItem.getName();
return this*;
}
*/
//This is a menu made of items
class itemMenu
{
public:
/*
This function loads all of the items in the file and saves them in the listOfItems
@Param inputStream: The file stream that the items are to be read from
*/
itemMenu(ifstream &inputStream);
/*
This loads an empty menu
*/
itemMenu();
/*
This function adds an item to the listOfItems
@param inputItem: the item to be added
*/
void addItem(item inputItem);
/*
This function erases the item with the given name in the listOfItems
@param itemName: The name of the item to be deleted
*/
void deleteItem(string itemName);
/*
This function erases the last item on the menu
*/
void deleteItem();
/*
This function couts all of the items in the listOfItems
*/
void showItems();
/*
This function saves all of the items in the listOfItems
@param outputStream: The file stream for the items to be saved to
*/
void saveMenu(ofstream &outputStream);
/*
This function returns a copy of an item in the menu and a blank item if the index is wrong
@param inputIndex: The index of the item to be accessed
*/
item getItem(int inputIndex);
private:
vector<item> listOfItems;
};
/*
This function loads all of the items in the file and saves them in the listOfItems
@Param inputStream: The file stream that the items are to be read from
*/
itemMenu::itemMenu(ifstream &inputStream)
{
item null;
listOfItems.push_back(null);
while(listOfItems[listOfItems.size()-1].load(inputStream))
{
listOfItems.push_back(null);
}
listOfItems.pop_back();
}
/*
This loads an empty menu
*/
itemMenu::itemMenu()
{
}
/*
This function adds an item to the listOfItems
@param inputItem: the item to be added
*/
void itemMenu::addItem(item inputItem)
{
listOfItems.push_back(inputItem.getName());
}
/*
This function erases the item with the given name in the listOfItems
@param itemName: The name of the item to be deleted
*/
void itemMenu::deleteItem(string itemName)
{
for(int i=0; i<listOfItems.size(); i++)
{
if(listOfItems[i].getName()==itemName)
{
listOfItems.erase(listOfItems.begin()+i-1);
}
}
}
/*
This function erases the last item on the menu
*/
void itemMenu::deleteItem()
{
listOfItems.pop_back();
}
/*
This function couts all of the items in the listOfItems
*/
void itemMenu::showItems()
{
for(int i=0; i<listOfItems.size(); i++)
{
cout << listOfItems[i];
}
}
/*
This function saves all of the items in the listOfItems
@param outputStream: The file stream for the items to be saved to
*/
void itemMenu::saveMenu(ofstream &outputStream)
{
for(int i=0; i<listOfItems.size(); i++)
{
listOfItems[i].save(outputStream);
}
}
/*
This function returns a copy of an item in the menu and a blank item if the index is wrong
@param inputIndex: The index of the item to be accessed
*/
item itemMenu::getItem(int inputIndex)
{
if(inputIndex<listOfItems.size())
{
return listOfItems.at(inputIndex);
}
else
{
item noName;
return noName;
}
}
class burgerMan
{
public:
/*
This function load's burgerMan's menu from the file so he can take orders
@param inputStream: the file stream with the menu items
*/
burgerMan(ifstream &inputStream);
/*
This function takes in a natural language restarant order and extracts the which order types are required and how much of each
@param inputString: The natural langauge request
@return: The order
*/
string takeOrder(string inputString);
private:
itemMenu menu;
};
/*
This function load's burgerMan's menu from the file so he can take orders
@param inputStream: the file stream with the menu items
*/
burgerMan::burgerMan(ifstream &inputStream):menu(inputStream)
{
}
/*
This function takes in a natural language restarant order and extracts the which order types are required and how much of each
@param inputString: The natural langauge request
@return: The order
*/
string burgerMan::takeOrder(string inputString)
{
bool numberActive=false;
vector<string> tokens;
bool whiteSpace=true;
string buffer;
//tokenizing
for(int i=0; i<inputString.size();i++)
{
if(inputString[i]!=' ')
{
if(whiteSpace)
{
buffer.append(1,inputString[i]);
tokens.push_back(buffer);
whiteSpace=false;
}
else
{
tokens[tokens.size()-1].append(1,inputString[i]);
}
}
else
{
whiteSpace=true;
buffer="";
}
}
for(int i=0; i<tokens.size(); i++)
{
cout << tokens[i]<<i << "\n";
}
}
//THIS IS THE MAIN FILE
#include<fstream>
#include<iostream>
#include<string>
#include</home/hewhosurvives/c++/order/item.h>
#include</home/hewhosurvives/c++/order/functions.h>
using namespace std;
int main(int argc, char* argv[])
{
ifstream streamer("orderMenu");
burgerMan mani(streamer);
mani.takeOrder("This is a sentice. this not. Can you tell the difference?");
cout <<"\n";
return 0;
}
The takeOrder function of the burgerMan class has most of the code that actually get exicuted