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


C++ Course::remove_student方法代码示例

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


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

示例1:

void 
remove_student()
{
	int indexValue;  // Index location of student to be removed.
	bool test;		 // Test variable for removal of students from course lists.
	
	Student *tempStudent;  // Points to any student object
	Course *tempCourse;	   // Points to any course object
	LinkedList &sList = master_student_list();  // reference to master student list.
	LinkedList &cList = master_course_list();   // reference to master course list. 

	if (sList.size() <= 0)  // Attempts to acces an empty list may cause crashes.
	{
		cerr << "\n*** The List is Empty ***" << endl;
		return;
	}

	// Ask the user for a student number and search for that student.
	indexValue = find_student(sList);

	if (indexValue == -1)  // ie. if the student was not found!
	{
		cerr << "\n*** No Student of that Number in the List ***" << endl;
		return;
	}

	// If the student WAS found then do the following.
	
	// Remove student from the list and get a pointer to the student object.
	tempStudent = (Student*)sList.remove(indexValue);
	
	// Remove this student from all course lists.
	for (int i = 0; i < cList.size(); i++)
	{
		tempCourse = (Course*)cList[i];

		// Remove the Student from the Course's List of Students
		// Note that remove_student checks if the student is in a particular
		// course before doing anything.
		test = tempCourse->remove_student(tempStudent);
	}

	// Now that the course lists have been cleaned up we can delete the student.
	delete tempStudent;
		
	//  NO NEED to fill in the empty space created by shifting values "up".
	//  Since this is a linked list the objects are not placed sequentially
	//  in memory.  The remove function just rearranges the links so that the 
	//  object removed is no longer part of the link.
}
开发者ID:malachig,项目名称:archive,代码行数:50,代码来源:main.cpp

示例2: remove

void 
remove_course(LinkedList &sList)
{
	int sIndex;			  // Index location of target student.
	int cIndex;			  // Index location of target course.
	Student *tempStudent; // Pointer to target student object.
	Course *tempCourse;	  // Pointer to target course object.
	bool test;			  // Bool variable, for testing whether student was 
						  // successfully removed from a Course's List.
	
	// Get the student of interest from the user.
	sIndex = find_student(sList);
	
	// If the student was not found display error message and return.
	if (sIndex == -1)
	{
		cerr << "\n*** No Student of that Number in the List ***" << endl;
		return;
	}

	tempStudent = (Student*)sList[sIndex];

	// Get a local copy of the student's course list
	LinkedList &cList = tempStudent->get_course_list();

	// Check for course list is empty for this student, if so, return.
	if (cList.size() == 0)
	{
		cerr << "\n*** Student is not enrolled in any courses ***" << endl;
		return;
	}

	// Display this student's courses.
	tempStudent->print_courses();

	// Ask user which course to remove
	cout << "Which course would you like to remove (enter number) > ";
	cin >> cIndex;

	// Check that the user's entry is valid
	if (cIndex > cList.size() || cIndex <= 0)
	{
		cerr << "\n*** Not a Valid Course Entry ***" << endl;
		return;
	}

	tempCourse = (Course*)cList[cIndex-1];  // Must adjust index value.

	// Now that everything has been checked, actually remove the course.
	// Do not delete memory for that course because student does not OWN 
	// the course objects.
	tempStudent->remove_course(tempCourse);

	// Remove the Student from the Course's List of Students
	test = tempCourse->remove_student(tempStudent);

	// Error checking.
	if (test)
		cout << "\nEnrollment for this Course updated successfully" << endl;
	else
		cerr << "\n*** Update of Enrollment for this course failed ***" << endl;
}
开发者ID:malachig,项目名称:archive,代码行数:62,代码来源:main.cpp


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