// copyright 1999 Brian J. Reithel, Ph.D. #include class building { char BuildingName[40]; float BuildingSqfeet; building* NextBuilding; public: void info_in(void); void info_out(void); void setnext(building*); building* getnext(void); }; void building::info_in(){ char nl; cout << "Enter Building Name: "; cin.get(BuildingName,40,'\n'); cin.get(nl); cout << "Enter Building Square Feet: "; cin >> BuildingSqfeet; cin.get(nl); } void building::info_out(){ cout << "Building Name: " << BuildingName << endl; cout << "Square Feet: " << BuildingSqfeet << endl; } void building::setnext(building* nextbldg){ NextBuilding=nextbldg; } building* building::getnext(){ return(NextBuilding); } int main(){ building* first=NULL; building* temp=NULL; building* prev=NULL; char nl; char another; cout << "Do you want to enter a building? (Y/N) "; cin.get(another); cin.get(nl); while(another=='y'||another=='Y'){ temp=new building; cout << endl; // on-screen spacing temp->info_in(); if(first==NULL){ // if this is the first instance, store its address first=temp; prev=first; } else { // otherwise make the next link in the list prev->setnext(temp); prev=temp; } cout << "Do you want to enter a building? (Y/N) "; cin.get(another); cin.get(nl); } if(first!=NULL) prev->setnext(NULL); // mark the end of the list temp=first; while(temp!=NULL){ cout << endl; // spacing temp->info_out(); temp=temp->getnext(); } return(0); }