//Jacob M. Dawson //23 February 2004 //Media Organizer Project #include using namespace std; #include #include "mlist.h" //Look to definitions for descriptions void readcomms(ifstream &ifile,ofstream &ofile,mlist smed); void quit(ifstream &ifile,ofstream &ofile); void commcatch(ifstream &file,string &line); int main(int argc,char* argv[]) { //Open initialization files ifstream stfile("students.data"); ifstream itfile("items.data"); assert((stfile)&&(itfile)); //breaks, if files not opened. mlist smed(stfile,itfile); //initialize the list. stfile.close(); //done with students file itfile.close(); //done with items file //Open the command and output files ifstream ifile("commands.data"); ofstream ofile("output.data"); //The important part. The REALLY important part. readcomms(ifile,ofile,smed); return 0; } void readcomms(ifstream &ifile,ofstream &ofile,mlist smed) { string line="",c1="",c2=""; int space=0; while(ifile) { getline(ifile,line); space=line.find(' '); //find the space in a 2-part command. if(space>0) { c1=line.substr(0,space); //First part of command c2=line.substr(space+1,line.length()-space); //second part of command. } else c1=line; //no space, one part, keep going. ofile<14) { if(tempc[14]=='1') //@Address Line 1: commcatch(ifile,sA1); if(tempc[14]=='2') //@Address Line 2: commcatch(ifile,sA2); } if(tempc[1]=='C') //@City: commcatch(ifile,sCity); if(tempc[1]=='S') //@State: commcatch(ifile,sState); if(tempc[1]=='Z') //@Zipcode: commcatch(ifile,sZip); if(tempc[1]=='O') //@Other: commcatch(ifile,sOther); } }while (!(tempc[1]=='@'&&tempc[0]=='@')&&ifile); if(ifile) if(sEmail.length()>0) { int osucc=0; osucc=smed.addstudent(sName,sNum,sEmail,sA1,sA2,sCity,sState,sZip,sOther); if(osucc==1) ofile<<"Success"; else ofile<<"Failure"; } } else if(c2=="item") { string tempc; string iTitle,iType,iAuth,iOwn,iAvail,tiPrice; //fields for media/item class, tiPrice is raw string from file int iPrice=-32768; do{ //loop to read all of entry for item getline(ifile,tempc); //read command if(tempc[0]=='@'&&tempc[1]!='@') //if command, but not end of listing, check type, respond appropriately { if(tempc[1]=='I') //@Item: commcatch(ifile,iTitle); if(tempc[1]=='M') //@Media Type: commcatch(ifile,iType); if(tempc[1]=='b') //@by: commcatch(ifile,iAuth); if(tempc[1]=='O') //@Owner: commcatch(ifile,iOwn); if(tempc[1]=='P') //@Price: commcatch(ifile,tiPrice); if(tempc[1]=='A') //@Availability: commcatch(ifile,iAvail); } }while(!(tempc[1]=='@'&&tempc[0]=='@')&&ifile); string stiPrice=""; //compacted version of price string //compacts it to just numbers. for(ui x=0;x='0'&&tiPrice[x]<='9') stiPrice+=tiPrice[x]; istringstream sPrice(stiPrice); sPrice>>iPrice; if(ifile) if(iOwn.length()>0) { int osucc=0; osucc=smed.additem(iTitle,iType,iAuth,iOwn,(ui)iPrice,iAvail); if(osucc==1) ofile<<"Success"; else ofile<<"Failure"; } } } //if a delete command if(c1=="delete") { int osucc=0; osucc=smed.eDel(c2); if(osucc==1) ofile<<"Success"; else ofile<<"Failure"; } //if a print command (item/student/email) if(c1=="print") { if(c2=="students") smed.sPrint(ofile); else if(c2=="items") smed.iPrint(ofile); else if(smed.ePrint(c2,ofile)!=1) ofile<