Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
using namespace std;
struct person { char name[30]; char phone[15]; double money; person *spouse; };
int main() { person *p[10];
system("pause"); return 0; }
- Read person information in file person.txt and store to array p. Set the spouse pointer for each person to NULL value first.
- 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).
- 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
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 continueStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started