(c++) Simple student performance management system (super simple)

Abstract: A simple student performance management system naturally includes adding, deleting, modifying and checking. Student performance management is an important part of the daily work of the school's educational affairs department, and it handles a large amount of information. This code is a simple simulation of student performance management, and the following functions are completed by menu selection: input student data; output student data; student data query; add student data; modify student data; delete student data.

        The data in this management system is a group of student achievement information. Each student achievement information is composed of student number, name and achievement. The achievement information of this group of students has the same characteristics and belongs to the same data object. It can be seen from this that these data have the properties of data elements in a linear table, so the data of this system is stored in a linear table.

        The sequential table is a sequential storage structure of the linear table, which means that a group of continuous memory units are used to store the data elements of the linear table in sequence. Under the sequential storage structure, two elements that are logically adjacent are also adjacent in physical position, which is a characteristic of the sequence table. This project can adopt the linear table sequential storage structure of the sequential table.

Use the simplest array of structures to do it:

Let me talk about a few more important modules:

Input information module:

    void Logging_data();//Enter student information
    

void List::Logging_data()//录入学生信息
{
	if(len==Listlen)
	{
		cout << "表已满 !"<<endl;
		return; 
	}
	cout <<"请输入学生学号 "<<endl; 
	cin>>Elem[len+1].id; 
	if(id_ifnd(Elem[len+1].id) >=0 )
	{
		cout << "该学号已存在!"<<endl; 
		return;
	}
	cout <<"请输入学生姓名 "<<endl; 
	cin>>Elem[len+1].name;

	cout <<"请输入学生成绩 "<<endl; 
	cin>>Elem[len+1].score;
	if(Elem[len+1].score <0 || Elem[len+1].score>100)
	{
		cout << "输入有误!" <<endl;
		return;
	}
	len++;	
}


    int id_ifnd(char *fin_id);//Search by student number and return the found position or not found; 
    
    void dele_stuinfo(); //Delete student information 
    delete information module:

void List::dele_stuinfo() //删除学生信息 
{
	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	char dele_id[15]={0};
	int i;
	cout << "请输入要删除的学号 :";
	cin >>dele_id;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(Elem[i].id,dele_id)==0)
		{
			if(i==len)
			{
				len--;
				cout << "删除成功" << endl;
				print_list();
				return;
			}
			else
			{
				for(i;i<len+1;i++)
				{
					Elem[i]=Elem[i+1];
				}
				len--;
				cout << "删除成功" << endl;
				print_list();
				return;
			}				
		}
	}
	cout << "没有此学号的学生!"<<endl;	
}


    int is_empty(); //The table is empty 
    
    int is_full(); //The table is full 
    
    void print_list(); //Ordinary printing 

print module:

void List::print_list()  //普通打印 
{
	int i;
	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	else
	{
		cout <<"学号		"<<"姓名		"<<"成绩 		"<<endl;
		cout <<"************************************************"<<endl;
		cout <<endl;
		for(i=0;i<len+1;i++)
		{
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
		}
		cout <<endl;
		cout <<"************************************************"<<endl;
		cout <<endl;
	}		
}


    
    void score_sort_low(); //Sort by grades (failure) 
    
    void score_sort_up(); //Sort by grades in ascending order (from low to high)   
    
    void id_sort(); //Sort by student number in ascending order   

Sort modules in ascending order by student number:

void List::id_sort() //按学号升序排序   ok 
{

	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	int i,j;
	
	STU	temp;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			if(strcmp(Elem[j].id,Elem[j+1].id)>0)
			{
				temp=Elem[j];
				Elem[j]=Elem[j+1];
				Elem[j+1]=temp;
			}
		}
	}
}


    
    void score_sort_donw(); //Sort in descending order (from high to low)   

Grade sorting module:

void List::score_sort_donw() //按成绩降序(从高到低)排序  ok  
{

	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	int i,j;
	
	STU	temp;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			if(Elem[j].score<Elem[j+1].score)
			{
				temp=Elem[j];
				Elem[j]=Elem[j+1];
				Elem[j+1]=temp;
			}
		}
	}	
}


    
    void id_find_info(); //find student information by student number; 

Find the student information module by student number:

void List::id_find_info() //按学号查找学生信息; 
{		
	cout << "请输入要查询的学生学号 : " ;
	char buf[15]={0};
	cin>>buf;
	
	int i,k;
	k=0;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(buf,Elem[i].id) == 0)
		{
			k++;
			cout <<"学号		"<<"姓名		"<<"成绩	 	"<<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
			cout <<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;	
		}
		else
		{
			continue;
		}
	}
	if(k==0)
	{
		cout <<"没有该学号的学生!"<<endl;
	}
}


    
    void name_find_info(); //Find student information by name; 
    
    void amend_info();//Modify student information 

To modify the student information module:

void List::amend_info()//修改学生信息
{
	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	char amend_id[15]={0};
	int i;
	char buf1[15]={0};
	char buf2[15]={0};
	float k;
	cout << "请输入需修改信息的学生学号 :";
	cin >>amend_id;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(Elem[i].id,amend_id)==0)
		{
			cout <<"学号		"<<"姓名		"<<"成绩	 	"<<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
			cout <<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;	
AAA:			cout <<"请输入学生新学号 "<<endl; 
			cin>>buf1; 
			if(strcmp(buf1,Elem[i].id) != 0 && id_ifnd(buf1) >=0 )
			{
				cout << "该学号已存在!请重新输入"<<endl;
				memset(buf1,0,sizeof(buf1)); 
				goto AAA;
			}
			strcpy(Elem[i].id,buf1);
			print_list();
			cout <<"请输入学生新姓名 "<<endl; 
			cin>>buf2;
			strcpy(Elem[i].name,buf2);
			print_list();
BBB:			cout <<"请输入学生新成绩 "<<endl; 
			cin>>k;
			if(k <0 || k>100)
			{
				cout << "输入有误!请重新输入:" <<endl;
				goto BBB;
			}
			Elem[i].score=k;
			print_list();
			cout << "已修改" << endl;
			id_sort();
			print_list();
			return;				
		}	
	}
	cout << "没有此学号的学生!"<<endl;
	return;	
}

Full code :

#include<iostream>
#include<string.h>
#define Listlen 100   //这里可以修改数组的大小,目前可以记录一百个学生成绩信息

using namespace std;

typedef struct ElemType{
	char id[15];		//学号
	char name[15]; 		//姓名
	float score;		//成绩
}STU;

class List{
public:
	List()
	{
		Elem[Listlen]={0}; 
		len=-1;
	}
	~List(){
	}
	void Logging_data();//录入学生信息
	
	int id_ifnd(char *fin_id);//按学号查找返回查找到的位置或者没查找到的; 
	
	void dele_stuinfo(); //删除学生信息 
	
	int is_empty();  //表为空 
	
	int is_full() ; //表为满 
	
	void print_list();  //普通打印 
	
	void score_sort_low(); //成绩排序 (不及格) 
	
	void score_sort_up(); //按成绩升序(从低到高)排序   
	
	void id_sort(); //按学号升序排序   
	
	void score_sort_donw(); //按成绩降序(从高到低)排序   
	
	void id_find_info(); //按学号查找学生信息; 
	
	void name_find_info(); //按姓名查找学生信息; 
	
	void amend_info();//修改学生信息 
		 
private:
	STU Elem[Listlen];  //定义结构体数组 
	int len;  

};

int main(void)
{
	List a;
	int k; 
	char quits[6]={0};
	strcpy(quits,"quit");
		cout<<endl;
		cout << "-------欢迎来到德玛西亚学校学生成绩信息管理系统-------"<<endl;
LIST:	cout << "----------------1-------录入学生信息----------------"<<endl;
		cout << "----------------2-------删除学生信息----------------"<<endl;
		cout << "----------------3-------修改学生信息----------------"<<endl;
		cout << "----------------4-------查询学生信息----------------"<<endl;
		cout << "----------------0-------退出管理系统----------------"<<endl;
		cout<<endl;
		cin>>k;
		char buf1[6]={0};
		char buf2[6]={0};
		char buf3[6]={0};
	switch(k)
	{
		case 1:
			
			for(k=0;k<100;k++)
			{
				a.Logging_data();
				cout <<"继续录入请按任意键,录入结束请输入quit:";
				cin>>buf1;
				if(strcmp(buf1,quits)==0)
				{
					cout<<"录入结束表为 :"<<endl;
					cout<<endl;
					a.id_sort();
					a.print_list();
					goto LIST;
				}
			}
		case 2:
			
			for(k=0;k<100;k++)
			{
				a.dele_stuinfo();
				cout <<"继续删除请按任意键,录入结束请输入quit:";
				cin>>buf2;
				if(strcmp(buf2,quits)==0)
				{
					cout<<"删除结束表为 :"<<endl;
					cout<<endl;
					a.id_sort();
					a.print_list();
					goto LIST;
				}
			}
		case 3:
			
			for(k=0;k<100;k++)
			{
				a.amend_info();
				cout <<"继续修改请按任意键,录入结束请输入quit:";
				cin>>buf3;
				if(strcmp(buf3,quits)==0)
				{
					cout<<"修改结束表为 :"<<endl;
					cout<<endl;
					a.id_sort();
					a.print_list();
					goto LIST;
				}
			}
		case 4:
			int m;
FIND:		cout<<endl; 
			cout << "----------------1-------按学号查找学生信息----------------"<<endl;
			cout << "----------------2-------按姓名查找学生信息----------------"<<endl;
			cout << "----------------3-------查找未及格的学生信息--------------"<<endl;
			cout << "----------------4-------成绩降序表查看--------------------"<<endl;
			cout << "----------------5-------成绩升序表查看--------------------"<<endl;
			cout << "----------------0-------退出查询--------------------------"<<endl;
			cout<<endl;
			cin>>m;
			switch(m) 
			{
				case 1:
					a.id_find_info();
					goto FIND;
				case 2:	
					a.name_find_info();
					goto FIND;
				case 3:
					a.score_sort_low();
					goto FIND;
				case 4:
					a.score_sort_donw();
					a.print_list();
					goto FIND;
				case 5:
					a.score_sort_up();
					a.print_list();
					goto FIND;
				case 0:	
					goto LIST;
				default:
					cout <<"输入有误 请重新输入!"<<endl;
					goto FIND;
			}	
		case 0:	
				break;
		default:
			cout <<"输入有误 请重新输入!"<<endl;
			goto LIST;
	}

	return 0;
}
void List::Logging_data()//录入学生信息
{
	if(len==Listlen)
	{
		cout << "表已满 !"<<endl;
		return; 
	}
	cout <<"请输入学生学号 "<<endl; 
	cin>>Elem[len+1].id; 
	if(id_ifnd(Elem[len+1].id) >=0 )
	{
		cout << "该学号已存在!"<<endl; 
		return;
	}
	cout <<"请输入学生姓名 "<<endl; 
	cin>>Elem[len+1].name;

	cout <<"请输入学生成绩 "<<endl; 
	cin>>Elem[len+1].score;
	if(Elem[len+1].score <0 || Elem[len+1].score>100)
	{
		cout << "输入有误!" <<endl;
		return;
	}
	len++;	
}
int List::id_ifnd(char *fin_id) //按学号查找返回查找到的位置或者没查找到的; 
{
	
	int i;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(fin_id,Elem[i].id) == 0)
		{
			return i;	
		}
		else
		{
			continue;
		}
	}
	if(i==len+1)
	{
		return -1;
	}
}
void List::dele_stuinfo() //删除学生信息 
{
	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	char dele_id[15]={0};
	int i;
	cout << "请输入要删除的学号 :";
	cin >>dele_id;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(Elem[i].id,dele_id)==0)
		{
			if(i==len)
			{
				len--;
				cout << "删除成功" << endl;
				print_list();
				return;
			}
			else
			{
				for(i;i<len+1;i++)
				{
					Elem[i]=Elem[i+1];
				}
				len--;
				cout << "删除成功" << endl;
				print_list();
				return;
			}				
		}
	}
	cout << "没有此学号的学生!"<<endl;	
}
int List::is_empty()  //表为空 
{
	if(len==-1)
	{
		return 1;
	}
	else{
		return 0;
	}
}
int List::is_full()  //表为满 
{
	if(len+1==Listlen)
	{
		return 1;
	}
	else{
		return 0;
	}
}
void List::print_list()  //普通打印 
{
	int i;
	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	else
	{
		cout <<"学号		"<<"姓名		"<<"成绩 		"<<endl;
		cout <<"************************************************"<<endl;
		cout <<endl;
		for(i=0;i<len+1;i++)
		{
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
		}
		cout <<endl;
		cout <<"************************************************"<<endl;
		cout <<endl;
	}		
}
void List::score_sort_low() //成绩排序 (不及格) 
{

	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	int i,j;
	
	STU	temp;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			if(Elem[j].score<Elem[j+1].score)
			{
				temp=Elem[j];
				Elem[j]=Elem[j+1];
				Elem[j+1]=temp;
			}
		}
	}
	int k=0;
	for(i=0;i<len+1;i++)
	{
		if(Elem[i].score<60.0000)
		{
			break;
		}
	}
	if(i==len+1)
	{
		cout << "没有不及格的学生!"<<endl;
		return;
	}
	
	cout <<"学号		"<<"姓名		"<<"成绩(不及格) 	"<<endl;
	cout <<"************************************************"<<endl;
	cout <<endl;
	for(i;i<len+1;i++)
	{
		cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
	}
	cout <<endl;
	cout <<"************************************************"<<endl;
	cout <<endl;
} 
void List::score_sort_up() //按成绩升序(从低到高)排序   ok
{

	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	int i,j;
	
	STU	temp;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			if(Elem[j].score>Elem[j+1].score)
			{
				temp=Elem[j];
				Elem[j]=Elem[j+1];
				Elem[j+1]=temp;
			}
		}
	}
} 
void List::id_sort() //按学号升序排序   ok 
{

	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	int i,j;
	
	STU	temp;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			if(strcmp(Elem[j].id,Elem[j+1].id)>0)
			{
				temp=Elem[j];
				Elem[j]=Elem[j+1];
				Elem[j+1]=temp;
			}
		}
	}
}
void List::score_sort_donw() //按成绩降序(从高到低)排序  ok  
{

	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	int i,j;
	
	STU	temp;
	for(i=0;i<len;i++)
	{
		for(j=0;j<len-i;j++)
		{
			if(Elem[j].score<Elem[j+1].score)
			{
				temp=Elem[j];
				Elem[j]=Elem[j+1];
				Elem[j+1]=temp;
			}
		}
	}	
}
void List::id_find_info() //按学号查找学生信息; 
{		
	cout << "请输入要查询的学生学号 : " ;
	char buf[15]={0};
	cin>>buf;
	
	int i,k;
	k=0;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(buf,Elem[i].id) == 0)
		{
			k++;
			cout <<"学号		"<<"姓名		"<<"成绩	 	"<<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
			cout <<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;	
		}
		else
		{
			continue;
		}
	}
	if(k==0)
	{
		cout <<"没有该学号的学生!"<<endl;
	}
}
void List::name_find_info() //按姓名查找学生信息; 
{		
	cout << "请输入要查询的学生姓名 : " ;
	char buf[10]={0};
	cin>>buf;
	
	int i,k;
	k=0;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(buf,Elem[i].name) == 0)
		{
			k++;
			cout <<"学号		"<<"姓名		"<<"成绩	 	"<<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
			cout <<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;	
		}
		else
		{
			continue;
		}
	}
	if(k==0)
	{
		cout <<"没有该姓名的学生!"<<endl;
	}
}
void List::amend_info()//修改学生信息
{
	if(is_empty())
	{
		cout << "表为空 !"<<endl;
		return; 
	}
	char amend_id[15]={0};
	int i;
	char buf1[15]={0};
	char buf2[15]={0};
	float k;
	cout << "请输入需修改信息的学生学号 :";
	cin >>amend_id;
	for(i=0;i<len+1;i++)
	{
		if(strcmp(Elem[i].id,amend_id)==0)
		{
			cout <<"学号		"<<"姓名		"<<"成绩	 	"<<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;
			cout<<Elem[i].id<<"		"<<Elem[i].name<<"	    "<<Elem[i].score<<endl;
			cout <<endl;
			cout <<"************************************************"<<endl;
			cout <<endl;	
AAA:			cout <<"请输入学生新学号 "<<endl; 
			cin>>buf1; 
			if(strcmp(buf1,Elem[i].id) != 0 && id_ifnd(buf1) >=0 )
			{
				cout << "该学号已存在!请重新输入"<<endl;
				memset(buf1,0,sizeof(buf1)); 
				goto AAA;
			}
			strcpy(Elem[i].id,buf1);
			print_list();
			cout <<"请输入学生新姓名 "<<endl; 
			cin>>buf2;
			strcpy(Elem[i].name,buf2);
			print_list();
BBB:			cout <<"请输入学生新成绩 "<<endl; 
			cin>>k;
			if(k <0 || k>100)
			{
				cout << "输入有误!请重新输入:" <<endl;
				goto BBB;
			}
			Elem[i].score=k;
			print_list();
			cout << "已修改" << endl;
			id_sort();
			print_list();
			return;				
		}	
	}
	cout << "没有此学号的学生!"<<endl;
	return;	
}

Running result: Just enter a point and see

 

 Interested little torches can be used for fun! This is the end of today's sharing, thank you readers, grandpa, for watching, see you next time! ! Wuhu! !

Guess you like

Origin blog.csdn.net/weixin_56187542/article/details/126678718