Question

In: Computer Science

CODE IN C++ PLEASE Create a structure (object) named Person that has the following characteristics: •...

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

Solutions

Expert Solution

#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;
}


Related Solutions

Using C++. Please number the answers for clarity 1. Create an Account object named as myAccount...
Using C++. Please number the answers for clarity 1. Create an Account object named as myAccount and initialize it with appropriate data. 2. Change myAccount’s interest rate to 1% 3. display the balance on myAccount. 4. Declare a pointer variable ptr and initialize it with the address of myAccount. Display the interest earned on myAccount by using pointer ptr. 5. Dynamically allocate an array of five Account objects. 6. Suppose  getAcctNum() returns the account number of a given Account variable.  Write a...
Create a structure In C program named Student with the following components and appropriate data types:...
Create a structure In C program named Student with the following components and appropriate data types: Name, ID, CGPA i. Create an Array of Students of size three and take user input to fill the array. ii. Now find the student with the least CGPA and display his or hers Name, ID and CGPA.
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount...
using C++ Please create the class named BankAccount with the following properties below: // The BankAccount class sets up a clients account (using name & id), and - keeps track of a user's available balance. - how many transactions (deposits and/or withdrawals) are made. public class BankAccount { private int id; private String name private double balance; private int numTransactions; // ** Please define method definitions for Accessors and Mutators functions below for the class private member variables string getName();...
C++ Please complete based on the code below. Declare another stack object to the code in...
C++ Please complete based on the code below. Declare another stack object to the code in main(). Add a stack operator called CopyStack to the Stack class which, when executed, copies the contents of the first stack into the second stack. Modify your menu so that this option is available. The menu should also allow the second stack to be printed, pushed, popped, and so forth, just like with the first stack. #include using namespace std; #define MAXSize 10 class...
please submit the C code( no third party library). the C code will create output to...
please submit the C code( no third party library). the C code will create output to a file, and iterate in a loop 60 times and each iteration is 1 second, and if any key from your keyboard is pressed will write a 1 in the file, for every second no key is pressed, will write a 0 into the output file.
Written in C code: Using a structure called person, write a C function called compare_age that...
Written in C code: Using a structure called person, write a C function called compare_age that takes two person structure pointers as input and returns 1 if the first person is older, -1 if the second person is older, or 0 if they have exactly the same birthday. Hint: Compare the years first, then if equal compare months, if they are equal compare days. The structure called person should contain the following; has fields for name (50 char array), dateOfBirth...
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding...
~~~USING C# ONLY~~~ Create a console application Design a class named Person with properties for holding a person’s name, address, and telephone number. Design a class named Customer, which is derived from the Person class. The Customer class should have the variables and properties for the customer number, customer email, a spentAmount of the customer’s purchases, and a Boolean variable indicating whether the customer wishes to be on a mailing list. It also includes a function named calcAmount that calculates...
Question: In a package named "oop" create a Scala class named "Team" and a Scala object...
Question: In a package named "oop" create a Scala class named "Team" and a Scala object named "Referee". Team will have: • State values of type Int representing the strength of the team's offense and defense with a constructor to set these values. The parameters for the constructor should be offense then defense • A third state variable named "score" of type Int that is not in the constructor, is declared as a var, and is initialized to 0 Referee...
A person has to create a code. The code must contain exactly 6 letters. The first...
A person has to create a code. The code must contain exactly 6 letters. The first letter must be a vowel that is not an E or I. The second letter must be either a J, K, or L. The third letter must be a consonant that is not a G or R. The fourth letter must be a vowel that is not an I. The fifth letter must be a consonant. If repetition of letters are not allowed, how...
A person has to create a code. The code must contain exactly 7 letters. The first...
A person has to create a code. The code must contain exactly 7 letters. The first letter must either a N, P, R, or T. The second letter must be a vowel that is not I, O, or U. The third letter must be a consonant that is not a D, F, H, or J. The fourth letter must be a vowel that is not an O or U. The fifth letter must be a consonant that is not a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT