#include #include #include #include #include "container.h" int ProcessCommands(Container &Library, ofstream &Log);//processes the commands.data input file. string CharToString(char input[], int size);//converts character arrays to string. int main() { Container Library; //The class for holding everything. ofstream Log("output.data"); //open file stream for output. ProcessCommands(Library, Log);//call the function that processes all of the commeands. return 1;//exit } int ProcessCommands(Container &Library, ofstream &Log) { //this functionj processes the commands.data input file char tempch[200];//temporary holding spot for a line inputted before conversion to string. string Command;//holds the command inputted from the input file. string Input;//holds the second part of the command line (if one exists) int Index = 0;//necessary for a few of the commands - holds data inputed from the file ifstream RouteDataIn("commands.data"); //open file stream for input while(!RouteDataIn.eof())//keep on inputting as long as there exists data to input. { for (int i = 0; i < 200;i++)//format our temporary char array { tempch[i] = ' ';//do actual formatting } RouteDataIn.getline(tempch, 200);//input data from file Command = CharToString(tempch,200);//convert to string for (int j = 0; j < (int)Command.length(); j++)//this loop splits the command string into two parts if there exists 2 parts. example: "add student" becomes "add" and "student { if (Command[j] == ' ')//if we find point to split on... { break; } } if (j != 0)//makes sure we found a split point... { Input = Command.substr(j+1, Command.length()-j-2);//set the input string to second half of input. for (int k = Input.length()-1; k >0; k--) //this loop deletes extraneous spaces at end of string { if (Input[k]== ' ' ) Input = Input.substr(0,Input.length()-1); } //cout << "'" << Input << "'" << endl; Command = Command.substr(0,j);//sets the command string to just the first part of itself... } if (Command == "print") { Log << Command << " " << Input << endl;//print to output.data which command is being run if (Input == "students") { Library.PrintStudents(Log);//print all of the students } if (Input == "items") { Library.PrintMedia(Log);//print all of the items } if(Input != "items" && Input != "students") { Library.PrintStudent(Log, Input);//print a specific student - pass input data to that function. } } if (Command == "delete") { Log << Command << " " << Input << endl;//print to output.data which command is being run Library.DeleteStudent(Log, Input);//pass on the input data for which student to delete } if (Command == "add") { Log << Command << " " << Input << endl;//print to output.data which command is being run if (Input == "student") { Library.AddStudent(Log, RouteDataIn);//add a student } if (Input == "item") { Library.AddItem(Log, RouteDataIn);//add an item } } if (Command == "quit") { Log << "quit" << endl;//print to output.data which command is being run return 1;//return successful completion. } } return 0; } string CharToString(char input[], int size) { //converts from a C-style array of chars to a full string. Very simple addition. string output = ""; for(int i =0;i