// 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 StudInfo class #include "StudInfo.h" #include #include #include #include using namespace std; //////////////////////////////////////////////////////////////// StudInfo() // Constructs default Student 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 // StudInfo::StudInfo() { Name = "none"; Phone = "none"; Email = "none"; Address1 = "none"; Address2 = "none"; City = "none"; State = "none"; Zip = 0; Other = "none"; } //////////////////////////////////////////////////////////////// AddStudent(Input) // Adds another Student in the array of Students // // Parameters: // Input - holds all the item info given // // Pre: An owner field is included with the item information // // Post: Another Student will be added in the array of Students // // Returns: true // // Called by: Info::Info() // Calls: none // bool StudInfo::AddStudent(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 stringstream tempPhone(stringstream::in|stringstream::out); //variable to hold phone number Input >> category; while(category != '@') { //These if else if statements add the information given to each of the variables in the items class if(category == 'N') { getline(Input, tempcategory, '!'); Name = tempcategory; } if(category == 'P') { getline(Input, tempcategory, '!'); tempPhone << tempcategory; char test; int newPhone; stringstream Phonenew(stringstream::in|stringstream::out); tempPhone >> test; if(test == '(') { tempPhone >> newPhone; Phonenew << "(" << setfill('0') << setw(3) << newPhone; tempPhone >> test; if(test == ')') { tempPhone >> newPhone; Phonenew << ") " << setfill('0') << setw(3) << newPhone; tempPhone >> test; if(test == '-') { tempPhone >> newPhone; Phonenew << "-" << setfill('0') << setw(4) << newPhone << "!"; getline(Phonenew, Phone, '!'); } } } } if(category == 'E') { getline(Input, tempcategory, '!'); Email = tempcategory; } if(category == 'A') { getline(Input, tempcategory, '!'); Address1 = tempcategory; } if(category == 'D') { getline(Input, tempcategory, '!'); Address2 = tempcategory; } if(category == 'C') { getline(Input, tempcategory, '!'); City = tempcategory; } if(category == 'S') { getline(Input, tempcategory, '!'); State = tempcategory; } if(category == 'Z') { Input >> Zip; } if(category == 'O') { getline(Input, tempcategory, '!'); Other = tempcategory; } Input >> category; } return true; } //////////////////////////////////////////////////////////////// PrintStudent(oFile) // Prints current Student information // // Parameters: // oFile - file stream used to output information // // Pre: // // Post: Student information is printed // // Returns: none // // Called by: Info::Info() // Calls: none // void StudInfo::PrintStudent(ofstream &oFile) { bool printAddress2 = false; if(Name != "none") { oFile << "Name:\n"; oFile << "\t" << Name << endl; } if(Phone != "none") { oFile << "Phone Number:\n"; oFile << "\t" << Phone << endl; } if(Email != "none") { oFile << "Email:\n"; oFile << "\t" << Email << endl; } if(Address1 != "none") { oFile << "Address:\n"; oFile << "\t" << Address1 << endl; printAddress2 = true; } if(Address2 != "none" && Address1 == "none") { oFile << "Address:\n"; oFile << "\t" << Address2 << endl; } if(Address2 != "none" && printAddress2 == true) { oFile << "\t" << Address2 << endl; } if(Address1 == "none" && Address2 == "none" && (City != "none" || State != "none" || Zip != 0)) { oFile << "Address:\n"; } if(City != "none") { oFile << "\t" << City; } if(City != "none" && State != "none") { oFile << ", "; } if(State != "none") { if(City == "none") { oFile << "\t"; } oFile << State; } if(State != "none" && Zip != 0) { oFile << " "; } if(City != "none" && Zip != 0 && State == "none") { oFile << ", "; } if(Zip != 0) { if(State == "none" || City == "none") { oFile << "\t"; } oFile << setfill('0') << setw(5) << Zip; } if(City != "none" || State != "none" || Zip != 0) { oFile << endl; } if(Other != "none") { oFile << "Other:\n"; oFile << "\t" << Other << endl; } oFile << endl; } //////////////////////////////////////////////////////////////// StudInfoSet(iFile, category) // Constructs Student 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 StudInfo::StudInfoSet(ifstream &iFile, string category) { string tempcategory; //variable that holds the information to be added to each category stringstream tempPhone(stringstream::in|stringstream::out); //variable to hold phone number while(category != "@@") { //These if else if statements add the information given to each of the variables in the items class if(category == "@Name:") { getline(iFile, Name, '\n'); } else if(category == "@Phone Number:") { getline(iFile, tempcategory, '\n'); tempPhone << tempcategory; char test; stringstream newPhone; tempPhone >> test; if(test == '(') { tempPhone >> "(" << newPhone; tempPhone >> test; if(test == ')') { tempPhone >> ")" << newPhone; tempPhone >> test; if(test == '-') { tempPhone >> newPhone; Phone << newPhone; } else { Phone << "none"; } } else { Phone = 0; } } else { Phone = 0; } } else if(category == "@E-mail:") { getline(iFile, Email, '\n'); } else if(category == "@Address Line 1:") { getline(iFile, Address1, '\n'); } else if(category == "@Address Line 2:") { getline(iFile, Address2, '\n'); } else if(category == "@City:") { getline(iFile, City, '\n'); } else if(category == "@State:") { getline(iFile, State, '\n'); } else if(category == "@Zipcode:") { iFile >> Zip; } else if(category == "@Other:") { getline(iFile, Other, '\n'); } } fullorempty = true; }*/ //////////////////////////////////////////////////////////////// Email() // tests if given email address is the same as the current student 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 StudInfo::Emailtest(string email) { if(email == Email) return true; else return false; } //////////////////////////////////////////////////////////////// RemoveStudent() // "removes" student information from current student entry // // Parameters: // none // // Pre: // // Post: fullorempty variable is false // // Returns: // // Called by: Info::Info() // Calls: none // void StudInfo::RemoveStudent() { Name = "none"; Phone = "none"; Email = "none"; Address1 = "none"; Address2 = "none"; City = "none"; State = "none"; Zip = 0; Other = "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 StudInfo::fulloremptytest() { if(Email != "none") return true; else return false; }