The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 327 Weeks Ago, 4 Days Ago |
| Questions Answered: | 12843 |
| Tutorials Posted: | 12834 |
MBA, Ph.D in Management
Harvard university
Feb-1997 - Aug-2003
Professor
Strayer University
Jan-2007 - Present
CS211 – Assignment 4
Write a program that creates a linked list of families. Each family contains a husband, his wife
and a set of children. Each family is linked to another by a pointer called nextFamily. Husband is
linked to his wife by a pointer called myWife. The children are linked to their mother through a
pointer called myChildren. Children are linked by a pointer called mySibling.
Therefore, there are three types of nodes. The Husband node (class) contains the following
information:
SSN of type long
firstName of type string
lastName of type string
nextFamily of Husband*
myWife of type Wife*
The Wife class contains the following information:
SSN of type long
firstName of type string
lastName of type string
myChildren of Child*
The Child class contains the following information:
SSN of type long
firstName of type string
lastName of type string
mySibling of Child*
Your program reads a set of commands from the transaction file and acts accordingly. The
commands in the transaction file include
AddHusband
RemoveHusband
AddWife
RemoveWife
AddAChild
RemoveAChild
PrintAFamily
PrintAllFamilies AddHusbad comes with three more information: his SSN, his first name and his last name. When
you get this command, you need to create a node of type Husband and insert it to the top of the
Link list of the families if this person is not in the linked list already. Print appropriate report if
this transaction fails or if the transaction succeeds.
- If this husband exist print appropriate message and return false
- If this husband is successfully inserted just report appropriate message and return true RemveHusband comes with one more information: the SSN. This node should be deleted. In
order to delete this node, first you need to remove the children (if any), then remove the wife (if
he is married) and then remove the node itself. Print appropriate report if this transaction fails or
if the transaction succeeds.
- If this husband does not exist print appropriate message and return false
- Otherwise, remove the entire family and report appropriate message and return true
AddWife comes with 4 more information, the SSN of the wife, her first name, her last name and
finally the SSN of her husband. Based on the SSN of her husband, her husband must be found in
the linked list and the wife node should be linked to it.
- Report appropriate error message if either the husband does not exists or husband already
has a wife
- Otherwise add the wife, report succeeding message and return true
RemoveWife, comes with the SSN of her husband. In this case, the husband should be searched
and his wife node should be deleted. If the wife node is attached to the children, first remove all
the children and then remove the wide node
- Report appropriate error message if either the husband does not exists or husband does
not have a wife
- Otherwise remove the wife (and possible children), report appropriate message, and
return true
AddAchild comes with 4 more information, the SSN of the child, child first name, child last name
and finally the SSN of the father. Based on the SSN of the father, the father must be found in the
linked list and the child should be attached to the mother.
- If the father does not exist, report appropriate message and return false
- If father exists but has no wife, report appropriate message and return false
- Otherwise, if the child is already there, report appropriate message and return false
- Otherwise, add the child, report appropriate succeeding message and return true
RemoveAchild, comes with the SSN of the father and SSN of the child. In this case, the father
should be searched and his wife node should be followed to find the child that should be deleted.
If you find the child, you need to remove it from the family
- If the father does not exist, report appropriate message and return false
- If father exists but has no wife, report appropriate message and return false
- Otherwise, if the child is not already there, report appropriate message and return false
- Otherwise, remove the child, report appropriate succeeding message and return true
PrintAFamily comes with the SSN of the father. You need to search that family in the linked list
and print the information of the father. The mother (if any) and the children (if any) on the screen
- If the father in the family does not exist, report appropriate message and return false
- Otherwise, print the family and report appropriate succeeding message and return true
PrintAllFamilies, goes through the entire linked list of the family and prints the information of
each family one by one. Report a failing message if the linked list is empty.
Test your program with the following transaction file
AddHusband 100100100 Jim Smith AddHusband
AddHusband
AddHusband
AddHusband 200200200
300300300
400400400
500500500 Joe
Kevin
Richard
Ken Brown
Tarr
Anderson
Baker PrintAllFamilies
AddWife
AddWife
AddWife
AddWife 210210210
410410410
510510510
310310310 Linda
Mary
Beth
Ana Brown
Anderson
Baker
Tarr AddAchild
AddAchild
AddAchild 211211211
212212212
211211211 Tina
Rick
Nina Brown
Brown
Brown AddAchild
AddAchild 511511511
512512512 Sam
Serge Baker
Baker RemoveAchild
RemoveAchild 200200200
200200200 211211211
311311311 PrintAFamily
PrintAFamily
PrintAFamily 333333333
400400400
200200200 200200200
400400400
500500500
333333333 PrintAllFamilies
200200200
200200200
200200200
500500500
500500500 PrintAllFamilies
You can create a class called Family with the following properties
class Family
{
protected:
top
Husband*;
public:
void AddHusband(long SSN, string Fname, string Lname);
void RemoveHusband(long SSN);
void AddWife(long SSN, string Fname, string Lname, long husbandSSN);
void RemoveWife(long husbandSSN);
void AddAChild(long SSN, string Fname, string Lname, long fatherSSN);
void RemoveAChild(long FatherSSN, long childSSN);
void PrintAFamily(long fatherSSN);
void PrintAllFamilies();
void ReadTransactionFile();
}
You can write the following in your main program int main()
{
Family
USAFamilies;
USAFamilies. ReadTransactionFile( );
return 0;
}
You must create a class called Person and make the Husband, Wife and Child classes to inherit
from it. The class Person can include SSN, first name and last name which arte common to all
three classes. What to hand in:
1 A hard copy of your source code
2 A hard copy of all output file that is the results of running your transaction file
Also place the source code (all .h and .cpp files) into a folder, call the folder based on your first
name and your last name (ex: JohnSmith-A4), zip the folder and submit it electronically through
your cougar account.
Â
-----------