A local university would like to hire you to write a C++ program that stores the
ID: 3714314 • Letter: A
Question
A local university would like to hire you to write a C++ program that stores the home address and current college address for their students and displays this information in a report.
Address: Specify a structure named Address to store the street address, the city/state, and the zip code. You will use this structure as the data type for the required addresses in the StudentAddress structure.
Specify a structure named StudentAddress to store the following data for each student:
Name
Home Address. (Use the structure data type Address. Refer to Nested Structures.)
College Address. (Use the structure data type Address. Refer to Nested Structures.)
Specify a one-dimensional array to store the student address records. Set the maximum number of student records to 50 (the school can only accommodate 50 students each school year), but let the user specify how many student records need to be entered.
Use main( ) as your driver function. The program does not need to be repeatable.
Write appropriate functions that main( ) calls to accomplish the following tasks:
Read the number of students in the school.
Read and store the name and required addresses for each student.
Display each student’s name and both addresses.
Sample Input:
Number of students (must be a positive number less than or equal to 50) = ? 3
Please enter the information for student 1.
Name: Mary Jones
Home Address:
Street Address: 45 Ash
City, State: Morrilton, AR
Zip Code: 72110
College Address:
Street Address: 32 Elm
City, State: Conway, AR
Zip Code: 72034
Please enter the information for student 2.
Name: Lisa Mills
Home Address:
Street Address: 34 Spruce
City, State: Vilonia, AR
Zip Code: 72173
College Address:
Street Address: 56 Pine
City, State: Conway, AR
Zip Code: 72032
Please enter the information for student 3.
Name: Mike Hester
Home Address:
Street Address: 3 Oak
City, State: Greenbrier, AR
Zip Code: 72058
College Address:
Street Address: 5 Cedar
City, State: Conway, AR
Zip Code: 72034
Sample Output:
The Student Address report is:
Mary Jones
Home: 45 Ash
Morrilton, AR 72110
College: 32 Elm
Conway, AR 72034
Lisa Mills
Home: 34 Spruce
Vilonia, AR 72173
College: 56 Pine
Conway, AR 72032
Mike Hester
Home: 3 Oak
Greenbrier, AR 72058
College: 5 Cedar
Conway, AR 72034
Explanation / Answer
editable code:
#include <iostream>
using namespace std;
struct Home_Address
{
string St_Address;
string City;
string State;
string Zip_Code;
};
struct Collage_Address
{
string St_Address;
string City;
string State;
string Zip_Code;
};
struct Student_Address
{
string Name;
struct Home_Address Home_add;
struct Collage_Address Colge_add;
};
void get_Info(struct Student_Address *stud,int i)
{
cout<<"Please enter information of student "<<i+1<<" ";
cout << "Name: ";
cin.ignore();
getline(cin,stud->Name);
cout<<" Home Address: ";
cout<<" Street Address: ";
getline(cin,stud->Home_add.St_Address);
cout<<" City, State: ";
cin>>stud->Home_add.City;
cin>>stud->Home_add.State;
cout<<" ZipCode: ";
cin>>stud->Home_add.Zip_Code;
cout<<" Collage Address: ";
cin.ignore();
cout<<" Street Address: ";
getline(cin,stud->Colge_add.St_Address);
cout<<" City, State: ";
cin>>stud->Colge_add.City;
cin>>stud->Colge_add.State;
cout<<" ZipCode: ";
cin>>stud->Colge_add.Zip_Code;
cout<<" ";
}
void disp_Info(struct Student_Address *stud)
{
cout<<stud->Name;
cout<<" Home: "<<stud->Home_add.St_Address<<" ";
cout<<" "<<stud->Home_add.City<<stud->Home_add.State<<" "<<stud->Home_add.Zip_Code;
cout<<" ";
cout<<" Collage: "<<stud->Colge_add.St_Address<<" ";
cout<<" "<<stud->Colge_add.City<<stud->Colge_add.State<<" "<<stud->Colge_add.Zip_Code;
cout<<" ";
}
int main()
{
int n=0;
cout<<"Number of students(must be a positive no less than or equal to 50)=? ";
cin>>n;
struct Student_Address stud[50];
for(int i=0;i<n;i++)
{
get_Info(&stud[i],i);
}
cout<<"student address report is: ";
for(int i=0;i<n;i++){
disp_Info(&stud[i]);
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.