⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 liststudent.cpp

📁 增加学生信息、删除学生信息、修改学生信息 查询时可实现按姓名查询、按学号查询; 能对用户指定的任意课程名
💻 CPP
字号:
#include <iostream>
#include "liststudent.h"

Linkstudent * Liststudent :: get_first()
{
 return first;
}

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 << "snumber\tname\tage\tsex\tchinese\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;

}

void Liststudent::find_chinese(int score)
{   

	Linkstudent *temp = first->next;
	while(temp != NULL)
	{
		  if(score==temp->stu.get_chinese())
		  {temp->stu.showall();break;}	
		/*if(chinese   temp->stu.get_chinese() ))
			return temp;*/
		temp = temp->next;
	}
	
}

void Liststudent::find_math(int score)
{   

	Linkstudent *temp = first->next;
	while(temp != NULL)
	{
		  if(score==temp->stu.get_math())
		  {temp->stu.showall();break;}	
		/*if(chinese   temp->stu.get_chinese() ))
			return temp;*/
		temp = temp->next;
	}
	
}

void Liststudent::find_english(int score)
{   

	Linkstudent *temp = first->next;
	while(temp != NULL)
	{
		  if(score==temp->stu.get_english())
		  {temp->stu.showall();break;}	
		/*if(chinese   temp->stu.get_chinese() ))
			return temp;*/
		temp = temp->next;
	}
	
}

void Liststudent::sort_ascending(int choice)
{
	Linkstudent *temp,*front,*p,*q;
	for(int i=0;i<size-1;i++)
	{
		front=first;
		p=front->next;
		q=p->next;
		for(int j=0;j<size-i-1;j++)
		{
			if(p->stu.get_key(choice)>q->stu.get_key(choice))
			{
				front->next=q;
				temp=q->next;
				q->next=p;
				p->next=temp;
				q=p->next;
				front=front->next;
			}
			else
			{
				front=front->next;
				p=p->next;
				q=q->next;
			}
		}
	}
}

int Liststudent::get_size()
{
	return size;
}



void Liststudent::sort_descending(int choice)
{
	Linkstudent *temp,*front,*p,*q;
	for(int i=0;i<size-1;i++)
	{
		front=first;
		p=front->next;
		q=p->next;
		for(int j=0;j<size-i-1;j++)
		{
			if(p->stu.get_key(choice)<q->stu.get_key(choice))
			{
				front->next=q;
				temp=q->next;
				q->next=p;
				p->next=temp;
				q=p->next;
				front=front->next;
			}
			else
			{
				front=front->next;
				p=p->next;
				q=q->next;
			}
		}
	}
}

void Liststudent::save_stuInfo()
{
	ofstream of("studentInfo.txt",ios_base::out);         
	Linkstudent *p=first->next;                      
	while(p->next)
	{
		p->stu.outfilestream(of);                       
		p=p->next;                      
	}
	of<<p->stu.get_age()<<"\t"<<p->stu.get_ava()<<"\t"<<p->stu.get_chinese()<<"\t"<<p->stu.get_english()<<"\t"<<p->stu.get_math()<<"\t"<<p->stu.get_n()<<"\t"<<p->stu.get_sex()<<"\t"<<p->stu.get_sn()<<"\t"<<p->stu.get_tot();

	of.close();
}

void Liststudent::read_stuInfo()
{
	ifstream is("studentInfo.txt",ios::in);
	Student *student;
	if(!is)                               
	{
		ofstream os("studentInfo.txt",ios::out);     
        os.close();                         
        return;
	}

  while(!is.eof())
	{
		student=new Student();
		student->infilestream(is);
		first->next = new Linkstudent(*student,first->next); 
		size++;  //链表大小加1
	}
}

⌨️ 快捷键说明

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