当前位置: 首页>>代码示例>>C++>>正文


C++ Country::setContinent方法代码示例

本文整理汇总了C++中Country::setContinent方法的典型用法代码示例。如果您正苦于以下问题:C++ Country::setContinent方法的具体用法?C++ Country::setContinent怎么用?C++ Country::setContinent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Country的用法示例。


在下文中一共展示了Country::setContinent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: addCountry

bool World::addCountry(const char* _name, const char* _continent)
{
	lastOperationSuccess = true;
	//We cannot allow 2 times the same name.
	if (getCountryFromName(_name) != NULL)
	{
		lastOperationSuccess = false;
		lastErrorMessage = "The country already exists.";
		return false;
	}

	Continent* continent = getContinentFromName(_continent);

	if (continent == NULL)
	{
		lastOperationSuccess = false;
		lastErrorMessage = "The continent does not exists.";
		return false;
	}

	//Create the object.
	Country* countryObject = new Country(_name, (int)countriesVector->size());
	countryObject->setContinent(continent);

	//Once we have the infos of one, we add it to our vector.
	countriesVector->push_back(countryObject);
	return true;
}
开发者ID:Netopya,项目名称:COMP-345-Project,代码行数:28,代码来源:World.cpp

示例2: loadMap

	Map loadMap(string mapLocation){
		
		Map mapObject;
		//TO BE STORED

		Map mapObject;
		string mapName = mapLocation.substr(0, mapLocation.find('.'));
		int numContinents = 0;
		int numCountries = 0;

		fstream mapFile;
		mapFile.open(mapLocation, ios::in);
		int count = 0;

		string line;
		string value;
		string name;
		string section;

		/*BEGINNING OF FILE EXTRACTION*/
		while (!mapFile.eof()){

			getline(mapFile, line, '\n');
			
			if (line.empty()) continue;

			if (line[0] == '[') {
				section = line.substr(1, line.length() - 2);
				cout << section << endl;
				continue;
			}
			
			/*MAP FILE SETTINGS EXTRACTION*/ 
			if (section.compare("Map") == 0) {				//DONE:: NOTHING TO EXTRACT
				int equalSign = line.find('=');
				name = line.substr(0, equalSign);
				value = line.substr(equalSign + 1, line.length() - 1);
				continue;
			}
			/*END OF MAP FILE SETTING*/

			/*CONTINENT SECTION EXTRACTION*/				//DONE:: ADDED CONTINENT TO MAP OBJECT
			if (section.compare("Continents") == 0) {
				int equalSign = line.find('=');
				name = line.substr(0, equalSign);
				value = line.substr(equalSign + 1, line.length() - 1);

				Continent temp(name, std::stoi(value, 0, 10));
				mapObject.addContinentsToMap(temp);
				numContinents++;
				continue;
			}
			/*END OF CONTINENT SECTION EXTRACTION*/

			/*TERRITORY SECTION EXTRACTION*/
			if (section.compare("Territories") == 0) {				//NOT DONE:: NEEDS EXTRACTION CONTINENT FROM MAP, MORE METHODS FROM MAP
				Country temp;

				/*WHILE LOOP EXTRACTS THE VALUES IN EACH COUNTRY LINE*/
				bool end = false;
				int TYPE = 0;
				while (!end) {
					/*GET VALUE OF EACH ELEMENT IN THE LINE*/
					int commas = line.find(',');
					if (commas == -1) {
						commas = line.length();
						end = true;
					}
					value = line.substr(0, commas);
					if (!end) line = line.substr(commas + 1, line.length());
					/*END OF GET VALUE*/

					/*INSERTION OF VALUES TO TEMPORARY COUNTRY DEPENDING ON POSITION OF TYPE*/
					switch (TYPE) {
						case 0:										//NOT DONE
							temp.setCountryName(value);
							break; //NAME
						case 1:										//NOT DONE 
							temp.setXCordinate(stoi(value, 0, 10));
							break; //X CORDINATE
						case 2:										//NOT DONE
							temp.setYCordinate(stoi(value, 0, 10));
							break; //Y CORDINATE
						case 3:										//NOT DONE FIND CONTINENT IN MAP OBJECT WITH THE USE OF STRING
							temp.setContinent();
							//ONCE FINDING THE CONTINUENT ADD COUNTRY TO CONTINENT;
							break; //CONTINENTS 
						default: //ADJACENT COUNTRIES				//DONE
							temp.addAdjacentCountryString(value);
					}
					/*END OF INSERTION*/

					TYPE++;
				}
				cout << endl;
				numCountries++;
				continue;
			}
			/*END OF TERRITORY SECTION EXTRACTION*/
			
//.........这里部分代码省略.........
开发者ID:compski,项目名称:Comp345,代码行数:101,代码来源:SaveLoad.cpp


注:本文中的Country::setContinent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。