#include<iostream>
using namespace std;
struct address
{
char street[ 30 ] ;
char city[ 30 ] ; // added city member
char state[ 2 ] ;
int zip; // no need for array
} ;
struct student
{
address home;
char first[ 15 ] ;
char last[ 20 ] ;
int year; //no need for an array
} ;
int main( )
{
student s[ 2 ] ; // array of two student structures
int i, j;
for ( i = 0 ; i < 2 ; i++ )
{
cout << "Enter Student First Name: " ;
cin >> s[ i] .first ; // input into the ith student's first name field
cout << "Enter Student Last Name: " ;
cin .ignore ( 1 , '\n ' ) ; // clear enter
cin >> s[ i] .last ;
cout << "Enter Street Address: " ;
cin .ignore ( 1 , '\n ' ) ;
cin .getline ( s[ i] .home .street , sizeof ( s[ i] .home .street ) , '\n ' ) ; /* whole line for street*/
cout << "Enter City: " ;
cin .getline ( s[ i] .home .city , sizeof ( s[ i] .home .city ) , '\n ' ) ;
cout << "Enter State (ex. NY): " ;
cin >> s[ i] .home .state ;
cout << "Enter Zip Code: " ;
cin .ignore ( 1 , '\n ' ) ;
cin >> s[ i] .home .zip ;
cout << "Enter Class Year: " ;
cin >> s[ i] .year ;
cout << endl;
}
// pass student array to separate function - student pointer
for ( j = 0 ; j < 2 ; j++ ) // change to while pointer comparison loop
{
cout << "\n \n " ; // change to print fields using pointer and arrow operator
cout << s[ j] .first << " " << s[ j] .last << " " << s[ j] .year << endl;
cout << s[ j] .home .street << endl;
cout << s[ j] .home .city << ", " << s[ j] .home .state << " " << s[ j] .home .zip << endl;
}
}
I2luY2x1ZGU8aW9zdHJlYW0+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgpzdHJ1Y3QgYWRkcmVzcwp7CgljaGFyIHN0cmVldFszMF07CgljaGFyIGNpdHlbMzBdOy8vIGFkZGVkIGNpdHkgbWVtYmVyCgljaGFyIHN0YXRlWzJdOwoJaW50IHppcDsvLyBubyBuZWVkIGZvciBhcnJheQp9OwoKc3RydWN0IHN0dWRlbnQKewoJYWRkcmVzcyBob21lOwoJY2hhciBmaXJzdFsxNV07CgljaGFyIGxhc3Rb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