本文整理汇总了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.
}
示例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;
}