// Project 2 for CS 1704 Spring 2004 // // Programmer: Robert Houtman // OS: Windows XP Professional // Last modified: 24 FEB 2004 // // Purpose // This program reads a list of students and multimedia collections that // each student has. // // The program then gets commands from an input file to manage the // database. // //This .cpp file holds the implementations for the ItemInfo class #include "ItemInfo.h" #include #include #include using namespace std; //////////////////////////////////////////////////////////////// ItemInfo() // Constructs default Item class // // Parameters: // none // // Pre: none // // Post: The class will be initialized with the fullorempty variable reading EMPTY // // Returns: none // // Called by: Info::Info() // Calls: none // ItemInfo::ItemInfo() { Item = "none"; Type = "none"; Artist = "none"; Owner = "none"; Price = "none"; Availability = "none"; } //////////////////////////////////////////////////////////////// ItemInfoSet(iFile, category) // Constructs Item class with given input information // // Parameters: // iFile - file stream used to get information from the input file // category - variable to hold what category the information is // // Pre: there is information in the input file // // Post: The class will be initialized with information from the input file // // Returns: none // // Called by: Info::Info() // Calls: none // void ItemInfo::ItemInfoSet(ifstream &iFile, string category) { bool Ownertest = false; //variable to test if there is an owner field string tempItem = "none"; string tempMedia = "none"; string tempArtist = "none"; string tempOwner = "none"; string tempPrice = "none"; string tempAvail = "none"; //variables to hold information temporarily //This while loop gets all the information for the item and inserts it into temporary variables //so that it may be added to the database while(category != "@@") { if(category == "@Item:") { getline(iFile, tempItem, '\n'); } else if(category == "@Media Type:") { iFile >> tempMedia; } else if(category == "@by:") { getline(iFile, tempArtist, '\n'); } else if(category == "@Owner:") { getline(iFile, tempOwner, '\n'); Ownertest = true; } else if(category == "@Price:") { getline(iFile, tempPrice, '\n'); } else if(category == "@Availablility:") { getline(iFile, tempAvail, '\n'); } getline(iFile, category, '\n'); } //This if statement makes sure there is an Owner field and if there is it adds the //information if(Ownertest == true) { Item = tempItem; Type = tempMedia; Artist = tempArtist; Owner = tempOwner; Price = tempPrice; Availability = tempAvail; } } //////////////////////////////////////////////////////////////// AddanItem(Input) // Adds another item in the array of Items // // Parameters: // Input - holds all the item info given // // Pre: An owner field is included with the item information // // Post: Another item will be added in the array of Items // // Returns: true // // Called by: Info::Info() // Calls: none // bool ItemInfo::AddanItem(stringstream &Input) { char category; //variable that holds the first letter to determine what category //the following information is supposed to be added to string tempcategory; //variable that holds the information to be added to each category Input >> category; while(category != 'E') { //These if else if statements add the information given to each of the variables in the items class if(category == 'I') { getline(Input, tempcategory, '!'); Item = tempcategory; } if(category == 'M') { getline(Input, tempcategory, '!'); Type = tempcategory; } if(category == 'A') { getline(Input, tempcategory, '!'); Artist = tempcategory; } if(category == 'O') { getline(Input, tempcategory, '!'); Owner = tempcategory; } if(category == 'P') { getline(Input, tempcategory, '!'); Price = tempcategory; } if(category == 'V') { getline(Input, tempcategory, '!'); Availability = tempcategory; } Input >> category; } return true; } //////////////////////////////////////////////////////////////// RemoveItem() // "removes" item information from current student entry // // Parameters: // none // // Pre: // // Post: fullorempty variable is false // // Returns: // // Called by: Info::Info() // Calls: none // void ItemInfo::RemoveItem() { Item = "none"; Type = "none"; Artist = "none"; Owner = "none"; Price = "none"; Availability = "none"; } //////////////////////////////////////////////////////////////// fulloremptytest() // Accessor for fullorempty variable // // Parameters: // none // // Pre: // // Post: // // Returns: true if fullorempty is true // false if fullorempty is false // // Called by: Info::Info() // Calls: none // bool ItemInfo::fulloremptytest() { if(Owner != "none") return true; else return false; } //////////////////////////////////////////////////////////////// Email() // tests if given email address is the same as the current item entry // // Parameters: // email - holds the email address to be tested // // Pre: // // Post: returns true if emails are the same, false if they're not // // Returns: see Post information // // Called by: Info::Info() // Calls: none // bool ItemInfo::Email(string email) { if(email == Owner) return true; else return false; } //////////////////////////////////////////////////////////////// PrintItem(oFile, All) // Prints current item information // // Parameters: // oFile - file stream used to output information // All - variable to determine whether or not the Owner field should be printed // // Pre: // // Post: item information is printed // // Returns: none // // Called by: Info::Info() // Calls: none // void ItemInfo::PrintItem(ofstream &oFile, bool All) { if(Item != "none") { oFile << "Item:\n"; oFile << "\t" << Item << endl; } if(Type != "none") { oFile << "Media Type:\n"; oFile << "\t" << Type << endl; } if(Artist != "none") { oFile << "by:\n"; oFile << "\t" << Artist << endl; } if(All == true) { oFile << "Owner:\n"; oFile << "\t" << Owner << endl; } if(Price != "none") { oFile << "Price:\n"; oFile << "\t" << Price << endl; } if(Availability != "none") { oFile << "Availability:\n"; oFile << "\t" << Availability << endl; } oFile << endl; }