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();...
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.
~~~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...
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...
In an eclipse or blues compatible code, please create a class named Items including the described...
In an eclipse or blues compatible code, please create a class named Items including the described methods (replace and delete0 Write the following static method: /** Replaces each occurrence of an oldItem in aList with newItem */ public static void replace(ArrayList<String>aList, String oldItem, String newItem) Write the following static method: /**Deletes the first occurrence of target in aList*/ public static void delete(ArrayList<String>aList, String target)
In C# thanks please, Design a class named Person with properties for holding a person’s name,...
In C# thanks please, 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 the spentAmount. All...
Code in C++ Must show: unit testing ------------------------------------ UsedFurnitureItem Create a class named UsedFurnitureItem to represent...
Code in C++ Must show: unit testing ------------------------------------ UsedFurnitureItem Create a class named UsedFurnitureItem to represent a used furniture item that the store sells. Private data members of a UsedFurnitureItem are: age (double) // age in years – default value for brandNewPrice (double) // the original price of the item when it was brand new description (string) // a string description of the item condition (char) // condition of the item could be A, B, or C. size (double) //...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT