// Save MAXCOUNT Magazine Subscriptions to Disk Example using Serialization // Copyright 1998,2001 Brian J. Reithel, Ph.D. #include #include #define MAXCOUNT 3 class magazinesub { char name[151]; char address[151]; char city[151]; char state[3]; int zip; public: void info_in(void); char* getname(void); char* getaddress(void); char* getcity(void); char* getstate(void); int getzip(void); void SerializeToDisk(fstream*); }; char* magazinesub::getname(){ return(name); } char* magazinesub::getaddress(){ return(address); } char* magazinesub::getcity(){ return(city); } char* magazinesub::getstate(){ return(state); } int magazinesub::getzip(){ return(zip); } void magazinesub::info_in(){ char nl; cout << "Enter the customer's name: "; cin.get(name,150,'\n'); cin.get(nl); cout << "Enter the customer's address: "; cin.get(address,150,'\n'); cin.get(nl); cout << "Enter the customer's city: "; cin.get(city,150,'\n'); cin.get(nl); cout << "Enter the customer's state: "; cin.get(state,3,'\n'); cin.get(nl); cout << "Enter the customer's zip code: "; cin >> zip; cin.get(nl); } // the purpose of this member function is to output the member variables // to a disk file that has already been opened elsewhere, whose fstream address // is passed to this function void magazinesub::SerializeToDisk(fstream* outfile){ *outfile << name << endl; // write to the fstream that outfile points to *outfile << address << endl; *outfile << city << endl; *outfile << state << endl; *outfile << zip << endl; } int main() { magazinesub subs[MAXCOUNT]; int s; for(s=0;s