Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. void Family::RemoveAChild(long FatherSSN, long childSSN)
  2. {
  3. husbandPtr husb = top;
  4. if(!searchHusband(FatherSSN))
  5. {
  6. cout << "\nChild cannot be added becasue father does not exist" << endl;
  7. return;
  8. }
  9.  
  10. while(husb != NULL)
  11. {
  12. if(husb -> SSN == FatherSSN)
  13. break;
  14. husb = husb -> nextFamily;
  15. }
  16.  
  17. if(husb -> myWife == NULL)
  18. {
  19. cout << "The child was not removed. The mother does not exist." << endl;
  20. return;
  21. }
  22.  
  23. wifePtr wif = husb ->myWife;
  24. if(wif -> myChildren == NULL)
  25. {
  26. cout << "The child was not removed. This couple has no children" << endl;
  27. return;
  28. }
  29.  
  30. childPtr curr = wif -> myChildren;
  31. if(curr ->SSN == childSSN)
  32. {
  33. childPtr delChild = wif -> myChildren;
  34. wif -> myChildren = curr -> mySibling;
  35. cout << "deleting child: " << delChild -> fname << endl;
  36. delete delChild;
  37. return;
  38. }
  39. curr = curr -> mySibling;
  40. while(curr != NULL)
  41. {
  42. if(curr ->SSN == childSSN)
  43. {
  44. childPtr delChild = curr;
  45. curr = curr ->mySibling;
  46. delete delChild;
  47. return;
  48. }
  49. curr = curr -> mySibling;
  50. }
  51. cout << "The child does not exist." << endl;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement