Question: A structure person is defined in a program CA2-template.cpp. An array of pointer to person, p is created for you to store up to 10

A structure person is defined in a program CA2-template.cpp. An array of pointer to person, p is created for you to store up to 10 persons using dynamic memory.

CA2-template.cpp

#include #include #include

using namespace std;

struct person { char name[30]; char phone[15]; double money; person *spouse; };

int main() { person *p[10];

system("pause"); return 0; }

  1. Read person information in file person.txt and store to array p. Set the spouse pointer for each person to NULL value first.
  2. Perform marry operation for Mary and Tom. You can marry two person by setting their spouse pointer to point to each other (store address of one another).
  3. Print out the content in array p where you need to print every person variable pointed by array p. If a person spouse pointer is NULL value, then print Not Married, else print the spouse name. Output of the program is shown below. Make sure your output is the same

person.txt

Mary 012-35678905 20000 John 010-87630221 16000 Alice 012-90028765 9000 Tom 019-76239028 30000 Pam 017-32237609 32000

Output

A structure person is defined in a program CA2-template.cpp. An array of

Dluccd1024\may2018\Assignment1\test-roject-jan20191Debug\test-roject-jan2019.exe lame: Mar Phone: 012-35678905 Money: 20000 Spouse Name: Tom lame: John Phone: 010-87630221 Money: 16000 Spouse Name: Not Married ame: Alice Phone: 012-90028765 oney: 9000 Spouse Name: Not Married lame: Tom Phone: 019-76239028 oney: 30000 Spouse Name: Mary Name: Pam Phone: 017-32237609 oney: 32000 Spouse Name: Not Married Press any key to continue

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!