In: Computer Science
CODE IN C++ PLEASE
Create a structure (object) named Person that has the following characteristics: • full name • age • family members full names represent by an array of size 10.
Write a program that creates an array of Person of size 5. Populate the array of objects with the information given by user input according to the following specifications:
• With input from the user
i) Populate only 3 positions of the array of Person object.
ii) Populate only 2 positions of the family members' names array for each object.
iii) Output only the contents of the Person object that contains user-inputted information.
Example output that was entered by the user:
Name: John Doe Age: 23 Family Member 1: Ollie Doe Family Member 2: Mike Doe Name: Jane Doe Age: 32 Family Member 1: Chris Doe Family Member 2: Samuel Doe … |
#include <iostream>
using namespace std;
//structure as given
struct Person{
string name;
int age;
string familyName[10];
};
int main()
{
//Array of structure
struct Person person[5];
int user=0;
//enetring input of three user
for(user=0;user<3;user++)
{
cout<<"===================================="<<endl;
cout<<"Enter information of user
"<<user+1<<endl;
cout<<"Enter name"<<endl;;
getline(cin,person[user].name);
cout<<"Enter Age"<<endl;
cin>>person[user].age;
cin.ignore();
cout<<"Enter 1st family member name"<<endl;
getline(cin,person[user].familyName[0]);
cout<<"Enter 2nd family member name"<<endl;
getline(cin,person[user].familyName[1]);
cout<<"===================================="<<endl;
}
//Displaying input user
for(int i=1;i<=user;i++)
{
cout<<"===================================="<<endl;
cout<<"User"<<i<<endl;
cout<<"Name: "<<person[i-1].name<<endl;
cout<<"Age: "<<person[i-1].age<<endl;
cout<<"Family Member 1:
"<<person[i-1].familyName[0]<<endl;
cout<<"family Member 2:
"<<person[i-1].familyName[1]<<endl;
cout<<"===================================="<<endl;
}
return 0;
}