/* On my honor: - I have not discussed the C++ language code in my program with anyone other than my instructor or the teaching assistants assigned to this course. - I have not used C++ language code obtained from another student, or any other unauthorized source, either modified or unmodified. - If any C++ language code or documentation used in my program was obtained from another source, such as a textbook or course notes, that has been clearly noted with a proper citation in the comments of my program. - I have not designed this program in such a way as to defeat or interfere with the normal operation of the Curator System. Deborah A Thompson */ // Project 2 for CS 1704 Spring 2004 // // Programmer: Deborah A Thompson // OS: Windows XP Professional // System: Pentium III 500, 256 MB Memory // Compiler: Visual C++ 6.0, Service Pack 4 // Last modified: Febraury 23, 2004 // // Purpose: // 1. To apply new-gained object oriented design principles // 2. To reinforce principles of parsing, and // 3. To exercise the use of classes. // You will be implementing a console, command line based Multimedia Organizer. // The basic idea is that your current Video, CD, DVD, cassette, etc collection // should be able to be organized along with other students' collections so that // we have a huge database of multimedia items that can be borrowed, traded, etc. // // librabries #include #include #include #include #include #include // header file #include "Organizer.h" #define NDEBUG // function void RdCommand(ifstream& ReadC, ofstream& Log); using namespace std; int main() { //open log file ofstream Log; Log.open("output.data"); //open "commands.data" file ifstream ReadC; ReadC.open("commands.data"); //read "commands.data" file RdCommand(ReadC, Log); //close ReadC file ReadC.close(); //close log file Log.close(); return 0; } //////////////////////////////////////////////////////////////// RdCommand // read from the command file and to parse the commands. // // Parameters: // ReadC - input stream file name // Log - output stream file name // // Pre: That both the input and output stream files have been opened. // // Post: get the commands from the command file and will parse the commands. // // Returns: Nothing // // Called by: main // Calls: cOrganizer.quit, cOrganizer.delete, cOrganizer.addItem, cOrganizer.pItem // cOrganizer.pStudent, cOrganizer.aStudent // void RdCommand(ifstream& ReadC, ofstream& Log) { string cName = DEFAULT, //read in name of student cPNum = "", //read in phone number cEmail = DEFAULT, //read in email cOther = DEFAULT, //read in other information cItem = DEFAULT, //read in item cType = DEFAULT, //read in type of item cAuthor = DEFAULT, //read in author of item cOwner = DEFAULT, //read in email address of item cPrice = "", //read in price of item cStatus = "EMPTY", //read in status of item Command = DEFAULT; //command bool correct; // checks phone & price are in correct format char CheckA[16]; // reading in phone and price as chars //initialize check for(int i = 0; i < 16; i++) { CheckA[i] = ' '; } //create organizer type Organizer cOrganizer; //create address type Address cAddress; // loops thru "commands.data" file while((ReadC) && (Command != "quit")) { //set everything to defaults cAddress.Apt = DEFAULT; cAddress.City = DEFAULT; cAddress.Entry = false; cAddress.State = DEFAULT; cAddress.Street = DEFAULT; cAddress.Zip = DEFAULT; cName = DEFAULT; cPNum = ""; cEmail = DEFAULT; cOther = DEFAULT; cItem = DEFAULT; cType = DEFAULT; cAuthor = DEFAULT; cOwner = DEFAULT; cPrice = ""; cStatus = "EMPTY"; //reads in line from command file getline (ReadC, Command, ' '); //check is quit followed by a '\n' if(Command == "quit\n") { //sets command to quit Command = "quit"; } // assert #1 error checker assert((Command == "delete") || (Command == "add") || (Command == "print") || (Command == "quit")); //if command is add then decide if student or item is next word if (Command == "add") { //read in next part of command getline (ReadC, Command, '\n'); //if command is student procceed if (Command == "student") { do { //ignore '@' char ReadC.ignore(1); //read next command getline (ReadC, Command, '\n'); //if command is name, then read in name of student if (Command == "Name:") { getline (ReadC, cName, '\n'); } //if command is phone number, then read in phone number if (Command == "Phone Number:") { correct = true; //sets array of chars to default, ' ' for (int a = 1; a < 16; a++) { CheckA[a] = ' '; } //read in first character ReadC >> CheckA[1]; //if that character is '(' then read next 3 characters if (CheckA[1] == '(') { for (int a = 2; a < 5; a++) { //read in characters ReadC >> CheckA[a]; //if char is not a number then correct is false if ((CheckA[a] < 48) || (CheckA[a] > 57)) { correct = false; } } } //else phone number format is incorrect else { correct = false; } //read in character at sixth place ReadC >> CheckA[5]; //set character at seventh place to ' ' CheckA[6] = ' '; //if character at sixth place is ')' then read in next 3 characters if (CheckA[5] == ')') { for (int a = 7; a < 10; a++) { //read in characters ReadC >> CheckA[a]; //check that characters are numbers if ((CheckA[a] < 48) || (CheckA[a] > 57)) { correct = false; //if not number then phone # is incorrect } } } //else phone # is incorrect else { correct = false; } //read in 11th place ReadC >> CheckA[10]; //checks that 11th place is a '-' (correct format) if (CheckA[10] == '-') { //then read in next 3 characters for (int a = 11; a < 15; a++) { //read in next character ReadC >> CheckA[a]; //checks that character is a number if ((CheckA[a] < 48) || (CheckA[a] > 57)) { //if character is not number then it is not right format correct = false; } } } //else character is in wrong format else { correct = false; } //if phone number format is correctly inputted //then put phone number into string in correct format if (correct = true) { for (int a = 1; a < 15; a++) { cPNum = cPNum + CheckA[a]; } } //ignore blank line ReadC.ignore(100,'\n'); } //if command is email, read in email if (Command == "E-mail:") { getline(ReadC, cEmail, '\n'); } //if command is address line 1 read in street //and set that address entry exists to true if (Command == "Address Line 1:") { cAddress.Entry = true; getline(ReadC, cAddress.Street, '\n'); } //if command is address line 2 read in apt //and set that address entry exists to true if (Command == "Address Line 2:") { cAddress.Entry = true; getline(ReadC, cAddress.Apt, '\n'); } //if command is city read in city //and set that address entry exists to true if (Command == "City:") { cAddress.Entry = true; getline(ReadC, cAddress.City, '\n'); } //if command is state read in state //and set that address entry exists to true if (Command == "State:") { cAddress.Entry = true; getline(ReadC, cAddress.State, '\n'); } //if command is zipcode read in zip //and set that address entry exists to true if (Command == "Zipcode:") { cAddress.Entry = true; getline(ReadC, cAddress.Zip, '\n'); } //if command is other then read in other if (Command == "Other:") { getline(ReadC, cOther, '\n'); } } while (Command != "@"); //add student information to database cOrganizer.aStudent(Log, cName, cPNum, cEmail, cAddress, cOther); } //reading in item information else { do { //ignore '@' ReadC.ignore(1); //read in command getline (ReadC, Command, '\n'); //if command is Item, then read in Item name if (Command == "Item:") { getline (ReadC, cItem, '\n'); } //if command is Media Type, then read in Media Type if (Command == "Media Type:") { getline (ReadC, cType, '\n'); } //if command is by, then read in the Author if (Command == "by:") { getline (ReadC, cAuthor, '\n'); } //if commmand is owner, then read in the Owner if (Command == "Owner:") { getline (ReadC, cOwner, '\n'); } //if command is price, then check format of price //and read in the price if format is correct if (Command == "Price:") { //set defaults for (int a = 1; a < 10; a++) { CheckA[a] = ' '; } correct = true; //read in charactor ReadC >> CheckA[1]; //if charactor reads '$' if (CheckA[1] != '$') { correct = false; } //read in charactor ReadC >> CheckA[2]; //if charactor is not a number, else format is incorrect if ((CheckA[2] < 48) || (CheckA[2] > 57)) { correct = false; } //read in charactor ReadC >> CheckA[3]; //if charactor is '.' if (CheckA[3] == '.') { //read in next 2 characters for (int a = 4; a < 6; a++) { ReadC >> CheckA[a]; //if charactor is not a number, else format is incorrect if ((CheckA[a] < 48) || (CheckA[2] > 57)) { correct = false; } } } //if format is correct, put price into a string if (correct = true) { for (int a = 1; a < 6; a++) { cPrice = cPrice + CheckA[a]; } } //ignore the line ReadC.ignore(100,'\n'); } //if command is availablility, then read in Status if (Command == "Availability:") { getline(ReadC, cStatus, '\n'); } } while (Command != "@"); //add Item to Item database list cOrganizer.addItem(Log, cItem, cType, cAuthor, cOwner, cPrice, cStatus); } //ignore the line ReadC.ignore(100,'\n'); } //if command is print, then decide students & items if (Command == "print") { //read in command getline (ReadC, Command, '\n'); //if command is students, then go to print students if (Command == "students") { cOrganizer.pStudent(Log); } //if command is items, then go to print items if (Command == "items") { Command = "DEFAULT"; //want to print all items cOrganizer.pItem(Log, Command); Command = "items"; } //if command is , then go to print if ((Command != "students") && (Command != "items")) { cOrganizer.pItem(Log, Command); } Command = "DEFAULT"; //set to default ReadC.ignore(100,'\n'); //ignore line } //if command is delete, then read in delete and go to delete if (Command == "delete") { getline (ReadC, cEmail, '\n'); cOrganizer.Delete(Log, cEmail); ReadC.ignore(100,'\n'); } //if command is quite, then read in quit if (Command == "quit") { cOrganizer.Quit(Log); } } //while((ReadC) || (Command != "quit")); return; }