home *** CD-ROM | disk | FTP | other *** search
- //---------------------------------------------------------------------------
- #include <iostream.h>
- #include <conio.h>
- #include <stdlib.h>
- #pragma hdrstop
-
- #include "structur.h"
-
- void displayRecord(int, mailingListRecord mlRec);
-
- int main(int, char**)
- {
- cout << endl;
- //
- // create an array of mailingListRecord structures
- //
- mailingListRecord* listArray[3];
- //
- // create objects for each record
- //
- for (int i=0;i<3;i++)
- listArray[i] = new mailingListRecord;
- int index = 0;
- //
- // get three records
- //
- do {
- // create a reference to the current record
- mailingListRecord& rec = *listArray[index];
- cout << "First Name: ";
- cin.getline(rec.firstName, sizeof(rec.firstName) - 1);
- cout << "Last Name: ";
- cin.getline(rec.lastName, sizeof(rec.lastName) - 1);
- cout << "Address: ";
- cin.getline(rec.address, sizeof(rec.address) - 1);
- cout << "City: ";
- cin.getline(rec.city, sizeof(rec.city) - 1);
- cout << "State: ";
- cin.getline(rec.state, sizeof(rec.state) - 1);
- char buff[10];
- cout << "Zip: ";
- cin.getline(buff, sizeof(buff) - 1);
- rec.zip = atoi(buff);
- index++;
- cout << endl;
- }
- while (index < 3);
- //
- // display the three records
- //
- clrscr();
- //
- // must dereference the pointer to pass an object
- // to the displayRecord function.
- //
- for (int i=0;i<3;i++) {
- displayRecord(i, *listArray[i]);
- }
- //
- // ask the user to choose a record
- //
- cout << "Choose a record: ";
- int rec;
- do {
- rec = getch();
- rec -= 49;
- } while (rec < 0 || rec > 2);
- //
- // assign the selected record to a temporary variable
- // must dereference here, too
- //
- mailingListRecord temp = *listArray[rec];
- clrscr();
- cout << endl;
- //
- // display the selected recrord
- //
- displayRecord(rec, temp);
- getch();
- return 0;
- }
- void displayRecord(int num, mailingListRecord mlRec)
- {
- cout << "Record " << (num + 1) << ":" << endl;
- cout << "Name: " << mlRec.firstName << " ";
- cout << mlRec.lastName;
- cout << endl;
- cout << "Address: " << mlRec.address;
- cout << endl << " ";
- cout << mlRec.city << ", ";
- cout << mlRec.state << " ";
- cout << mlRec.zip;
- cout << endl << endl;
- }
-
-