本文整理汇总了C++中Person::addCousin方法的典型用法代码示例。如果您正苦于以下问题:C++ Person::addCousin方法的具体用法?C++ Person::addCousin怎么用?C++ Person::addCousin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Person
的用法示例。
在下文中一共展示了Person::addCousin方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char** argv)
{
/**** people (unrelated) ****/
Person adam("Adam", male);
Person eve("Eve", female);
Person joan("Joan", female);
Person george("George", male);
Person joseph("Joseph", male);
Person hillary("Hillary", female);
/***** 2nd generation *****/
// Adam and Eve are parents of Abel, Martha, Mary, and Bill
Person *pAbel = eve.addChild(new Person("Abel", male));
adam.addChild(pAbel);
Person *pMartha = eve.addChild(new Person("Martha", female));
adam.addChild(pMartha);
Person *pMary = eve.addChild(new Person("Mary", female));
adam.addChild(pMary);
Person *pBill = eve.addChild(new Person("Bill", male));
adam.addChild(pBill);
/***** 3nd generation *****/
// Joan Abel are parents of Missy
Person *pMissy = joan.addChild("Missy", female);
pAbel->addChild(pMissy);
// George and Martha are parents of Jacky and Patsy
Person *pJacky = george.addChild("Jacky", female);
pMartha->addChild(pJacky);
Person *pPatsy = george.addChild("Patsy", female);
pMartha->addChild(pPatsy);
// Mary and Joseph are parents of James
Person *pJames = pMary->addChild("James", male);
joseph.addChild(pJames);
// Bill and Hillary are parents of Chelsea
Person *pChelsea = pBill->addChild("Chelsea", female);
hillary.addChild(pChelsea);
/***** Cousins *****/
pMissy->addCousin(pJacky);
pMissy->addCousin(pPatsy);
pMissy->addCousin(pJames);
pMissy->addCousin(pChelsea);
pJacky->addCousin(pMissy);
pJacky->addCousin(pJames);
pJacky->addCousin(pChelsea);
pPatsy->addCousin(pMissy);
pPatsy->addCousin(pJames);
pPatsy->addCousin(pChelsea);
pJames->addCousin(pMissy);
pJames->addCousin(pJacky);
pJames->addCousin(pPatsy);
pJames->addCousin(pChelsea);
pChelsea->addCousin(pMissy);
pChelsea->addCousin(pJacky);
pChelsea->addCousin(pPatsy);
pChelsea->addCousin(pJames);
// output all the people in the tree
/*
std::cout << "\nAll the people in the tree:\n\n";
std::cout << adam << eve;
std::cout << *pAbel << joan << george << *pMartha << *pMary << joseph << *pBill << hillary;
std::cout << *pMissy << *pJacky << *pPatsy << *pJames << *pChelsea << "\n";
*/
std::cout << "\n\t******** Cousins ********\n";
// std::cout << "\n\t**** Parents and Cousins ****\n";
// pMissy->showParents(pMissy);
pMissy->getCousins(pMissy);
// pJacky->showParents(pJacky);
pJacky->getCousins(pJacky);
// pPatsy->showParents(pPatsy);
pPatsy->getCousins(pPatsy);
// pJames->showParents(pJames);
pJames->getCousins(pJames);
// pChelsea->showParents(pChelsea);
pChelsea->getCousins(pChelsea);
std::cout << "\n\n";
return 0;
}