liststudent.cpp

来自「用C++编的很好的学生管理系统的程序」· C++ 代码 · 共 105 行

CPP
105
字号
#include <iostream>
#include "liststudent.h"

bool Liststudent::insert(const Student & stu)
{
	
	first->next = new Linkstudent(stu, first->next);
	if(tail == first)
		tail = first->next;
	
	size++;
	return true;
}
bool Liststudent::append(const Student &stu)
{
	tail->next = new Linkstudent(stu,NULL);
	tail = tail->next;
	tail->next = NULL;
	size++;
	return true;
}
void Liststudent::show_all()const
{
	cout << "name\tsnumber\tage\tsex\tyuwen\tmath\tenglish\ttotal\taverage"<<endl;
	Linkstudent *temp = first->next;
	while(temp != NULL)
	{
		temp->stu.showall();

		temp = temp->next;
	}
	
}

bool Liststudent::remove_n(char *n)
{
	if(empty()) return false;

	Linkstudent *temp = first;
	Linkstudent *dele;

	while(temp->next != NULL)
	{
		if(!strcmp(n , temp->next->stu.get_n() ))
		{
			dele = temp->next;
			temp->next = dele->next;
			delete dele;
			size--;
			return true;
		}
		temp = temp->next;
	}
	return false;
}

bool Liststudent::remvoe_sn(char *sn)
{
	Linkstudent *temp = first;
	Linkstudent *dele;

	while(temp->next != NULL)
	{
		if(!strcmp(sn , temp->next->stu.get_sn() ))
		{
			dele = temp->next;
			temp->next = dele->next;
			delete dele;
			size--;
			return true;
		}
		temp = temp->next;
	}
	return false;
}

Linkstudent * Liststudent::find_n(char *n)
{
	if(empty())
		return NULL;
	Linkstudent *temp = first->next;
	while(temp != NULL)
	{
		if(!strcmp(n , temp->stu.get_n() ))
			return temp;
		temp = temp->next;
	}
	return NULL;
	
}

Linkstudent * Liststudent::find_sn(char *sn)
{
	if(empty())
		return NULL;
	Linkstudent *temp = first->next;
	while(temp != NULL)
	{
		if(!strcmp(sn , temp->stu.get_sn() ))
			return temp;
		temp = temp->next;
	}
	return NULL;

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?