// Widdows, Stephen // Assignment: hw3 // Filename: address.cc #include //This program produces the #include //addresses of people at the //users request. const int max = 21; struct address { char street[max]; char city[max]; char state[max]; char zipcode[6]; }; struct employee { char lastname[max]; char firstname[max]; }; struct new_employee { employee name; address home; }; new_employee array[3]; void read(int b, char lastname[], //This function denotes the char firstname[], char street[], //information available to the char city[], char state[], //user. char zipcode[]) { strcpy (array[b].name.lastname, lastname); strcpy (array[b].name.firstname, firstname); strcpy (array[b].home.street, street); strcpy (array[b].home.city, city); strcpy (array[b].home.state, state); strcpy (array[b].home.zipcode, zipcode); } void address(new_employee array[], //This function finds the char last_name[], char first_name[]) //address for the requested { //person and prints it out. int fail = 0; for (int b = 0; b < 3; b++) { if ((strcmp (last_name, array[b].name.lastname) == 0) && (strcmp (first_name, array[b].name.firstname) == 0)) { cout << endl << "Last name: " << last_name << endl << "First name: " << first_name << endl << "Address: " << array[b].home.street << " " << array[b].home.city << ", " << array[b].home.state << " " << array[b].home.zipcode << endl << endl; fail = 1; } } if (fail == 0) cout << "Employee not listed." << endl; } main() { int y = 0; read(0, "Arnold", "Arthur", "1st_Street", //Here, the information about "Barstow", "CA", "92311"); //each person is encoded. read(1, "Arnold", "Alice", "Ave_A", "Barstow", "CA", "92311"); read(2, "Barker", "Bob", "Bali_court", "Beverly_Hills", "CA", "90210"); cout << "How many addresses do you need?" << endl; cin >> y; for (int z = 0; z < y; z++) //This part requests the number { //of addresses to find as well char last_name[max]; //as which ones. char first_name[max]; cout << "What is the last name of the" << " person?" << endl; cin >> last_name; cout << endl << "What is the first" << "name of the person?" << endl; cin >> first_name; address(array, last_name, first_name); } }