// Project 2 for CS 1704 Spring 2004 // // Programmer: John Puckett // OS: Windows XP Professional // System: Pentium 4 2.4Ghz, 1 GB Memory // Compiler: Visual C++ 7.1, Service Pack 4 // Last modified: February 24, 2004 // // Purpose // This program reads a list of student names and items from two input files // creates 2 arrays from the data, then uses another input file to run different // algorithms on the arrays // // The program then writes the given commands and the results to // an output file #include #include #include #include #include #include #include #include #include"students.h" #include"multimedia.h" #include"manager.h" using namespace std; int main() { ifstream studentFile("students.data", ios::in); //input file containing students ifstream itemFile("items.data", ios::in); //input file containing items ifstream commFile("commands.data", ios::in); //input file containing commands to be executed ofstream printFile("output.data", ios::out); //output file assert(commFile.is_open() == true); //Assert statement 1 struct sIn { string nameIn, phoneIn, emailIn, add1In, add2In, cityIn, stIn, zipIn, infoIn; //strings to be read from students.data }; struct iIn { string itemIn, typeIn, authorIn, ownerIn, priceIn, availIn; //strings to be read in from items.data }; sIn a; iIn b; char command[60]; string tempA, tempB; manager cmds(studentFile, itemFile); while(!commFile.eof()) //while command file is not done { commFile.getline(command, 50, '\n'); switch(command[0]) //input case switch { case 'd': //delete case tempA.clear(); for(int ct = 7; ct < 22; ct++) tempA += command[ct]; cmds.deleteEmail(tempA, printFile); commFile.getline(command, 50, '\n'); break; case 'a': //add case if(command[4] == 's') { a.nameIn = a.add1In = a.add2In = a.cityIn = a.stIn = " "; a.phoneIn = "7035698461"; a.emailIn = "none"; a.zipIn ="66666"; a.infoIn = "W00T"; commFile.getline(command, 50, '\n'); while(!(command[1] == '@')) { switch(command[1]) //selects proper function to excecute { case 'N': commFile.getline(command, 50, '\n'); a.nameIn = command; break; case 'E': commFile.getline(command, 50, '\n'); a.emailIn = command; break; case 'P': commFile.getline(command, 50, '\n'); a.phoneIn= command; break; case 'A': if(command[14] == '1') { commFile.getline(command, 50, '\n'); a.add1In = command; } else { commFile.getline(command, 50, '\n'); a.add2In = command; } break; case 'C': commFile.getline(command, 50, '\n'); a.cityIn = command; break; case 'S': commFile.getline(command, 50, '\n'); a.stIn = command; break; case 'Z': commFile.getline(command, 50, '\n'); a.zipIn = command; break; case 'O': commFile.getline(command, 50, '\n'); a.infoIn = command; break; default: break; } commFile.getline(command, 50, '\n'); } cmds.addStudent(a.nameIn, a.phoneIn, a.emailIn, a.add1In, a.add2In, a.cityIn, a.stIn, a.zipIn, a.infoIn, printFile); a.nameIn = a.add1In = a.add2In = a.cityIn = a.stIn = " "; a.phoneIn = "7035698461"; a.emailIn = "none"; a.zipIn ="66666"; a.infoIn = "W00T"; } else { b.itemIn = b.typeIn = b.authorIn = b.availIn = " "; b.ownerIn = "none"; b.priceIn = "0.0"; commFile.getline(command, 50, '\n'); while(!(command[1] == '@')) { switch(command[1]) //selects proper function to excecute { case 'I': commFile.getline(command, 50, '\n'); b.itemIn = command; break; case 'M': commFile.getline(command, 50, '\n'); b.typeIn = command; break; case 'b': commFile.getline(command, 50, '\n'); b.authorIn = command; break; case 'O': commFile.getline(command, 50, '\n'); b.ownerIn = command; break; case 'P': commFile.getline(command, 50, '\n'); b.priceIn = command; break; case 'A': commFile.getline(command, 50, '\n'); b.availIn = command; break; } commFile.getline(command, 50, '\n'); } cmds.addItem(b.itemIn, b.typeIn, b.authorIn, b.ownerIn, b.priceIn, b.availIn, printFile); b.itemIn = b.typeIn = b.authorIn = b.availIn = " "; b.ownerIn = "none"; b.priceIn = "0.0"; } commFile.getline(command, 50, '\n'); break; case 'p': //print case if(command[6] == 's' && command[8] == 'u') cmds.printStudents(printFile); else if(command[6] == 'i' && command[8] == 'e') cmds.printItems(printFile); else { tempB.clear(); for(int t = 6; t < 21; t++) tempB += command[t]; cmds.printEmail(tempB, printFile); } break; } } return 0; }