// Load MAXCOUNT Magazine Subscriptions to Disk Example using Serialization // Copyright 2000 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); void info_out(void); char* getname(void); char* getaddress(void); char* getcity(void); char* getstate(void); int getzip(void); void SerializeToDisk(fstream*); void SerializeFromDisk(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_out(){ cout << "Subscriber Information:" << endl; cout << " " << "Name: " << name << endl; cout << " " << "Address: " << address << endl; cout << " " << "City: " << city << endl; cout << " " << "State: " << state << endl; cout << " " << "Zip: " << zip << endl; cout << endl; } 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); } void magazinesub::SerializeToDisk(fstream* outfile){ *outfile << name << endl; *outfile << address << endl; *outfile << city << endl; *outfile << state << endl; *outfile << zip << endl; } void magazinesub::SerializeFromDisk(fstream* infile){ char nl; infile->get(name,151,'\n'); infile->get(nl); infile->get(address,151,'\n'); infile->get(nl); infile->get(city,151,'\n'); infile->get(nl); infile->get(state,3,'\n'); infile->get(nl); *infile >> zip; infile->get(nl); } int main() { magazinesub subs[MAXCOUNT]; int s; fstream inputfile; inputfile.open("subs.dat",ios::in); for(s=0;s