// Project 2 for CS 1704 Spring 2004 // // Programmer: Matthew Meade // OS: Windows XP Professional // System: Athlon XP 3000+, 512 MB Memory // Compiler: Visual Studio.Net, 2003 // Last modified: 2/26/2004 // // purpose: the purpose of this program is to store media types by // a persons email address. The program is composed of 3 classes. // one class stores student information while another stores item // information and the last classes is made up of two arrays to store // student and item objects. This program accepts two 3 files and // outputs its data to a data file. The 3 files inputted are composed // of student info, item info and a list of commands. The output file // keeps track of the commands and determines whether the command was // executed or not. // // 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 text book 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. // // Matthew C. Meade 9043-23162 #include "Header.h" // preprocessor headers #include "Organizer.h" void command(Organizer org); void quit(); int main() // main function { Organizer test; // type Organizer to inialize the arrays test.update_array(); // opens the file "students.data" // and stores the student info in // the organizer class test.update_array1(); // opens the file "items.data" // and stores the item info in the class command( test ); // function for the commands passes type // organizer to keep track of the arrays return 0; // return 0 t/f to the OS } //////////////////////////////////////////////////////////////// //this function accepts command from a file and then calls certain //functions depending on what command is inputted. this function // also passes objects to the two arrays to be updated. // // Parameters: // Organizer type org // // Returns: void // // Called by: main // Calls: // update_name, access_name, update_phone, access_phone, update_email // access_email, update_address1, access_address1, update_address2 // access_address2, update_city, access_city, update_state // access_state, update_zip, access_zip, update_other, access_other // update_item, access_item, update_media, access_media, update_by // access_by, update_owner, access_owner, update_price, access_price // update_avail, access_avail, quit // // void command( Organizer org ) { string zip1; // variable declarations zip for zipcode string email2; // email2 for the email string temp; // temp stores the commands string old; string name1; // stores the names of informations string print1; // stores the string after print comm string add1; // stores the string after the add comm Student std; // Student type std Multimedia multi; // multimedia type multi string bnk = "blank"; // for a default value of the objects bool tru; // boolean truth value ifstream infile("commands.data"); // opens a input file ofstream outfile("output.data"); // opens a file for output std.update_name(bnk); // sets the Student type to default values std.update_phone(bnk); std.update_email( bnk ); std.update_address1(bnk); std.update_address2(bnk); std.update_city(bnk); std.update_state(bnk); std.update_zip( bnk); std.update_other(bnk); multi.update_item( bnk ); // sets the Multimedia type to default values multi.update_media(bnk); multi.update_by( bnk ); multi.update_owner( bnk ); multi.update_price( bnk ); multi.update_avail( bnk ); while( !infile.eof() ) // while not = end of file { infile >> temp; // cin a comm from input file switch( temp[0] ) // switch statement for commands { case 'd': // if comm = delete infile >> email2; // input the email address to be deleted outfile << temp << " " << email2 << endl; // output the command to outfile tru = org.delete1( email2 ); // pass the email address to be deleted if( tru == true ) // if tru is true outfile << "Success\n"; // output sucess to output file else // otherwise outfile << "Failure\n"; // output failure break; // break from switch statement case 'p': // if comm = print infile >> print1; // cin the next command if( print1 == "students" ) // if print1 = students { outfile << "print students\n"; // echo the command to output file tru = org.print_students( outfile ); // passes output file to print function if( tru == false ) outfile << "Failure\n"; } else if( print1 == "items" ) // if print1 = items { outfile << "print items\n"; tru = org.print_items( outfile ); // passes output file to print items function if( tru == false ) outfile << "Failure\n"; } else // else must be an email address { outfile << temp << " " << print1 << endl; tru = org.print_email( print1, outfile ); // passes output and email address to print email function if( tru == false ) { outfile << print1 << " not found.\n"; } } break; case 'a': // if comm = add infile >> add1; // cin add1 for next phrase getline( infile, temp, '\n' ); // get white space if( add1 == "item" ) // if add1 = item { multi.update_item( bnk ); // sets default object multi.update_media(bnk); multi.update_by( bnk ); multi.update_owner( bnk ); multi.update_price( bnk ); multi.update_avail( bnk ); outfile << "add item\n"; // echos command getline( infile, temp, '\n'); // stores the command string while( temp != "@@" ) // while not = to @@ { if( temp == "@Item:" ) // if comm = item { getline( infile, name1, '\n' ); // store string item name multi.update_item( name1 ); // pass the string to be updated to teh } // item object else if( temp == "@Media Type:") // stores media type { getline( infile, name1, '\n' ); multi.update_media( name1 ); } else if( temp == "@by:" ) // stores author { getline( infile, name1, '\n' ); multi.update_by(name1); } else if(temp == "@Owner:") // stores email address { getline( infile, name1, '\n' ); multi.update_owner(name1); } else if(temp == "@Price:") // stores price { getline( infile, name1, '\n' ); multi.update_price( name1 ); } else if(temp == "@Availability:") // stores availibility { getline( infile, name1, '\n' ); multi.update_avail( name1 ); } else break; // otherwise break from the loop getline( infile, temp, '\n' ); // get next command } getline(infile, temp, '\n' ); // gets the whitespace tru = org.add_item( multi ); // passes the object to be added to the array if( tru == true ) outfile << "Success\n"; else outfile << "Failure\n"; } else if( add1 == "student" ) // add student commands { outfile << "add student\n"; // echos command to file getline( infile, temp, '\n' ); // stores command std.update_name(bnk); // sets default values of the object std.update_phone(bnk); std.update_email( bnk ); std.update_address1(bnk); std.update_address2(bnk); std.update_city(bnk); std.update_state(bnk); std.update_zip( bnk); std.update_other(bnk); while( temp != "@@" ) // while not = @@ { if( temp == "@Name:" ) { getline( infile, name1, '\n' ); std.update_name( name1 ); // updates the name of the object } else if( temp == "@Phone Number:") { getline( infile, name1, '\n' ); std.update_phone( name1 ); // updates the phone # of the object } else if( temp == "@E-mail:" ) { getline( infile, name1, '\n' ); std.update_email( name1 ); // updates the email address of the object } else if(temp == "@Address Line 1:") { getline( infile, name1, '\n' ); std.update_address1( name1 ); // updates the address of the object } else if(temp == "@Address Line 2:") { getline( infile, name1, '\n' ); std.update_address2( name1 ); // updates the address } else if(temp == "@City:") { getline( infile, name1, '\n' ); std.update_city( name1 ); // updates the city to the object } else if(temp == "@State:") { getline( infile, name1, '\n' ); std.update_state( name1 ); // updates the state to the object } else if(temp == "@Zipcode:") { getline( infile, name1, '\n' ); std.update_zip( name1 ); // updates the zip code of the object } else if(temp == "@Other:") { getline( infile, name1, '\n' ); std.update_other( name1 ); // updates the other string to the object } else break; // otherwise break from the loop getline( infile, temp, '\n' ); // stores the commands } getline( infile, temp, '\n' ); // stores the white space tru = org.add_student( std ); // updates the object to the array if( tru == true ) outfile << "Success\n"; else outfile << "Failure\n"; } else cout << "error2\n"; break; // break out of switch statement case 'q': outfile << "quit"; quit(); // quits out of program break; default: // default case for switch statement cout << "error11\n"; break; } } } //////////////////////////////////////////////////////////////// //