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


C++ Students::deleteStudent方法代码示例

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


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

示例1: ParseCommand

//this function takes the command from the cmd into commands that the program knows
void ParseCommand(Command cmd, std::vector<std::string> payload)
{
	if (cmd == Invalid)
	{
		printMessage("Invalid command.");
	}

	//adds a student
	else if (cmd == Add)
	{
		//Add a student
		if (payload.size() != 6)
		{
			//bad news throw the user an error.
			printMessage("Command add recieved incorrect # of arguments.");
		}
		else
		{
			//constuct the student
			Student toAdd = Student(payload[0], payload[1], payload[2],
				std::stoi(payload[3]), std::stoi(payload[4]), std::stoi(payload[5]));

			//make sure that id dosent exsist
			std::vector<Student> toCheck = students.searchStudents(students.ID, toAdd.getUID());

			//if to check == 0 then student doesnt exsist
			if (toCheck.size() < 100)
			{
				//make sure the student is valid
				if (!toAdd.isValidStudent())
				{
					printMessage("Invalid student attribute.");
					return;
				}

				//add
				students.addStudent(toAdd);
				students.saveStudent();
				std::cout << toAdd.getName() + " successfully added" << std::endl;
			}
			else
			{
				std::cout << "Student already exists" << std::endl;
			}
		}
	}

	//remove a student
	else if (cmd == Remove)
	{
		//see if student exsists
		std::vector<Student> toCheck = students.searchStudents(students.ID, payload[0]);

		//see if student exsist
		if (toCheck.size() != 0)
		{
			std::cout << "Student does not exist." << std::endl;
		}
		else
		{
			//delete student
			students.deleteStudent(toCheck[0]);
			students.saveStudent();
			std::cout << "Student deleted successfully" << std::endl;
		}
	}

	//search for student
	else if (cmd == Search)
	{
		//make sure there are arguments 
		if (payload.size() == 0)
		{
			std::cout << "Printing all students:" << std::endl;
			students.printAllStudents();
			return;
		}
		else
		{
			//slit the payload
			std::vector<std::string> commands = fileIO::split(payload[0], '=');

			//make sure the format  is correct
			if (commands.size() < 2)
			{
				printMessage("Search argument recieved invalid. Format should be [email protected]");
			}
			else
			{
				Students queryList = Students(students.searchStudents(commands[0],commands[1]));

				//iterate through rest of the arguments
				for (int i = 1; i < payload.size(); i++)
				{
					std::vector<std::string> commands = fileIO::split(payload[i], '=');

					if (commands.size() != 2)
					{
						printMessage("Search argument recieved invalid. Format should be [email protected]");
//.........这里部分代码省略.........
开发者ID:darkensoul,项目名称:SW-Testing,代码行数:101,代码来源:SoftwareTesting.cpp


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