// copyright 1999 Brian J. Reithel, Ph.D. #include #include #include #include #define MAXBUILDINGS 20 class CBuilding { char BuildingName[151]; int SquareFeet; public: void info_in(void); void info_out(void); void line_out(void); char* getname(void); int getsquarefeet(void); void setname(char*); void setsquarefeet(int); CBuilding(void); }; CBuilding::CBuilding(){ strcpy(BuildingName,"< empty >"); SquareFeet=0; } void CBuilding::setname(char* tmpname){ strcpy(BuildingName,tmpname); } void CBuilding::setsquarefeet(int tmpsqfeet){ SquareFeet=tmpsqfeet; } char* CBuilding::getname(){ return(BuildingName); } int CBuilding::getsquarefeet(){ return(SquareFeet); } void CBuilding::line_out(){ cout << setiosflags(ios::left) << setw(30) << BuildingName << " "; cout << setiosflags(ios::right) << setw(10) << SquareFeet << endl; } void CBuilding::info_out(){ cout << "Building name: " << BuildingName << endl; cout << "Square Feet: " << SquareFeet << endl; cout << endl; } void CBuilding::info_in(){ char nl; cout << "Enter building name: "; cin.get(BuildingName,150,'\n'); cin.get(nl); cout << "Enter square feet: (whole numbers only) "; cin >> SquareFeet; cin.get(nl); } int main() { CBuilding buildings[MAXBUILDINGS]; int choice=0; int b; char nl; char tempname[151]; int tempsquarefeet; int bldgnum; fstream buildingfile; int cls; while(choice<9){ for(cls=0;cls<26;cls++ ) cout << endl; cout << endl << endl << endl; cout << "1. Enter Building Information." << endl; cout << "2. Display Building Information" << endl; cout << "3. Save Building Database to Disk." << endl; cout << "4. Retrive Building Database from Disk." << endl; cout << "5. Display Line by Line Building Report." << endl; cout << "6. Enter information for a particular building." << endl; cout << "9. Exit Building Manager." << endl; cout << "Please enter your choice (1-9): "; cin >> choice; cin.get(nl); cout << endl << endl; switch(choice) { case 1: for(b=0;b> tempsquarefeet; buildingfile.get(nl); buildings[b].setsquarefeet(tempsquarefeet); } buildingfile.close(); cout << "File successfully loaded from disk." << endl; cout << "Press to continue..." << endl; cin.get(nl); break; case 5: for(b=0;b to continue..." << endl; cin.get(nl); break; case 6: cout << "Which building? (1-20): "; cin >> bldgnum; cin.get(nl); buildings[bldgnum-1].info_in(); break; } } return(0); }