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

📄 学生管理系统.txt

📁 一个学生管理系统
💻 TXT
字号:
//学生类.h
#include <string>
#include <iostream>
using namespace std;
class student
{
private:
	int num;
	string name;
	float score1;
	float score2;
	float score3;
	float average;
public:
	student();
    void output();
	int numm();
	float aver(){return average;}
	student *next;
	friend student* array(student * head);//排序
    student& operator=(student &b);//没有准备
    

};




//存于构造函数.cpp文件

#include <iostream>
#include <string>
#include "学生类.h"
using namespace std;
student::student()//构造中
{
	cout<<"请输入该名学生的信息"<<endl;
	cin>>num;cin>>name;
	cin>>score1>>score2>>score3;
	average=(score1+score2+score3)/3;
}
//输出函数
void student::output()
{
	cout<<num<<"  "<<name<<"  "<<score1<<"  "<<score2<<"  "<<score3<<"  "<<average<<endl;
}
//判断接口函数
int student::numm()
{return num;
}
student& student::operator=(student& b)
{
	num=b.num;

		name=b.name;
		score1=b.score1;
		score2=b.score2;
		score3=b.score3;
		average=b.average;
		return *this;
}
//存于有关链表操作.cpp

//有关链表的操作
//建立链表
#include <iostream>
#include <string>
#include "学生类.h"
using namespace std;
template <typename T>
void exchange(T &a,T &b)
{
	T c;
	c=a;
	a=b;
	b=c;
}
student* creat()
{
	student *p1,*p2,*head;
	head=p2=p1=new student;
    while(p1->numm())
	{
		p2->next=p1;
		p2=p1;
		p1=new student;
	}	cout<<'\n';	cout<<'\n';	cout<<'\n';
	cout<<"现在学生信息建立完毕,返回上一层"<<endl;
	cout<<'\n';
		cout<<"***********************************************************"<<endl;
	p2->next=NULL;
	return head;

}	
//链表的数据增加
student *add(student * head)
{
	student *p1=head,*p3; cout<<'\n';	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;
	cout<<"现在操作您的插入数据"<<endl;
	p3=new student;
	while(p1->next!=NULL)
	
		p1=p1->next;
		p1->next=p3;
		p3->next=NULL;
 cout<<'\n';	cout<<'\n';	cout<<'\n';
 cout<<"插入数据成功,返回上一层"<<endl;
cout<<"*****************************************"<<endl;
cout<<'\n';	cout<<'\n';	cout<<'\n';
		return head;
	
}
//链表数据删除
student *del(student* head)
{
	student* p1,* p2;int num;
	p1=p2=head;cout<<'\n';	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;
	cout<<"请输入您想要删除学生的学号"<<endl;
	cin>>num;
	while(p1->numm()!=num&&p1->next!=NULL)
	{if(p1!=head)
        p2->next=p1;
		p2=p1;
		p1=p1->next;
	}
	if(p1==head)
	{head=p1->next;cout<<"删除成功"<<endl;cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;}
	else if( p1->next==NULL&&p1->numm()!=num)
	{cout<<'\n';	cout<<"您想删除的学生不存在,返回上一层"<<endl;	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;}
	else
	{p2->next=p1->next;cout<<"删除成功"<<endl;cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;}
	return  head;
	
}
//链表数据排序
student* array(student* head)
{
	student *p1;

	int n;
	p1=head;
    for( n=1;p1->next!=NULL;p1=p1->next)
		n++;
	p1=head;
	for(int i=0;i<n-1;i++)
	{	for(int j=0;j<n-1-i;j++)
		{
			if(p1->aver()<p1->next->aver())
			{exchange(p1->average,p1->next->average);
		exchange(p1->name,p1->next->name);
		exchange(p1->num,p1->next->num);
			exchange(p1->score1,p1->next->score1);	exchange(p1->score2,p1->next->score2);	exchange(p1->score3,p1->next->score3);
			}
			p1=p1->next;
		}
		p1=head;
	}
	return head;


}
//存于其他函数.cpp
#include <iostream>
#include <string>
#include "学生类.h"
using namespace std;
//有关的输出函数
void display(student* head)
{ cout<<'\n';	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;
cout<<"学号 姓名 语文 数学 外语"<<endl; 
	head=array(head);
    student* p1=head;
	while(p1!=NULL)
	{
		p1->output();
		p1=p1->next;
	}

 cout<<'\n';	cout<<'\n';	cout<<'\n';cout<<"现在输出完成,返回上一层"<<endl;
cout<<"*****************************************"<<endl;
}
//学生查找
void search(student* head)
{
	student* p=head;cout<<'\n';	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;
	cout<<"请输入您要查找学生的学号"<<endl;
	int n;
	cin>>n;
	while(p->numm()!=n&&p->next!=NULL)
	p=p->next;
	if(p->numm()!=n&&p->next==NULL)
	{cout<<'\n';	cout<<"您要找的学生不存在,返回上一层"<<endl;	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;}
	else
	{	cout<<"您要找的学生的信息为:"<<endl;
	p->output();cout<<'\n';	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;}

}
//主函数.cpp


#include <iostream>
#include <string>
#include "学生类.h"
using namespace std;
int main()
{
	void display(student* head);
	void search(student* head);
     student* creat();
student *add(student * head);
student *del(student* head);
student* array(student* head);
	
	cout<<"*******************************欢迎使用学生管理系统*****************************"<<endl;
student* head;
loop:

cout<<"1.学生信息建立"<<endl;
cout<<"2.学生信息增加"<<endl;
cout<<"3.学生信息删除"<<endl;
cout<<"4.学生信息综合输出"<<endl;
cout<<"5.单个学生信息查询"<<endl;
cout<<"6.退出"<<endl;
int n;
cin>>n;
if(n==1)
{ cout<<'\n';	cout<<'\n';	cout<<'\n';
cout<<"*****************************************"<<endl;
	cout<<"请按照以下方式输入成绩:"<<endl;
cout<<"请按照 学号 姓名 语文 数学 外语 的顺序输入"<<endl;
cout<<"当输入0 0 0 0 0时结束输入"<<endl;
cout<<"其中由于系统不够完善姓名只能为英文且中间不能有空格请见谅"<<endl;
head=creat();}
if(n==2)
head=add(head);
if(n==3)
head=del(head);
if(n==4)
display(head);
if(n==5)
search(head);
if(n!=6)
goto loop;
delete head;
return 0;
}

⌨️ 快捷键说明

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