本文整理汇总了C++中Country::getId方法的典型用法代码示例。如果您正苦于以下问题:C++ Country::getId方法的具体用法?C++ Country::getId怎么用?C++ Country::getId使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::getId方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setContinentCountries
//assigning the countries to continents, one country at a time
//PRECONDITION: The countries and continents must be named already or this function will ask the user to assign
//each unamed country to a continent by name
//POSTCONDITION: The countries will all be assigned to continents and there will be no empty continents
void Map::setContinentCountries() {
//creating a new vector of countries-to-be-assigned so that we don't ruin the actual Map countries vector
list<Country*> *toBeAssigned = new list<Country*>;
for (vector<Country*>::iterator i = countries->begin(); i != countries->end(); ++i) {
toBeAssigned->push_back(*i);
}
string n = "";
//assigning one country to each continent to avoid having empty continents
cout << "First, please assign one country to each continent." << endl;
for (int i = 0; i < numContinents; i++) {
cout<<"Which country would you like to assign to Continent"<<(i+1)<< " (" << ((*continents)[i])->getName() << ")?:";
cin >> n;
Country* target = getCountryByName(n);//note: getCountryByName would return null if the user's name choice is invalid
//checking if the target is in the list of countries to be assigned
bool inToBeAssignedList = false;
if (target != NULL) {
for (list<Country*>::iterator j = toBeAssigned->begin(); j != toBeAssigned->end(); ++j) {
if (target->getId() == (*j)->getId())
inToBeAssignedList = true;
}
}
while (target == NULL || !inToBeAssignedList) {//checking to see if the user's name choice is valid
cout << "\nThis is not a valid country name. Please input a valid country name.:";
cin >> n;
target = getCountryByName(n);
//checking if the target is in the list of countries to be assigned
if (target != NULL) {
for (list<Country*>::iterator j = toBeAssigned->begin(); j != toBeAssigned->end(); ++j) {
if (target->getId() == (*j)->getId())
inToBeAssignedList = true;
}
}
}//should only exit this loop once we have a valid country
((*continents)[i])->addCountry(target);//adding target country to the ith continent
toBeAssigned->remove(target);//removing target country from countries-to-be-assigned
}//each continent should now have at least one country
//assigning the rest of the countries
cout << "Now please assign the rest of the countries to a continent." << endl;
for (list<Country*>::iterator i = toBeAssigned->begin(); i != toBeAssigned->end(); ++i) {//iterating through the conutries left to be assigned
cout << "Which continent does " << (*i)->getName() << " belong to?:";
cin >> n;
Continent* target = getContinentByName(n);//note: getContinentByName would return null if the user's name choice is invalid
while (target == NULL ) {//checking to see if the user's choice is valid
cout << "Not a valid continent name. Which continent does " << (*i)->getName() << " belong to?:";
cin >> n;
target = getContinentByName(n);
}//should only exit this loop once we have a valid continent
target->addCountry(*i);//adding the ith country to the target continent
*i=NULL;
}//all countries assigned now
delete toBeAssigned;
}