C++学生管理系统课程设计

在学习C++时做的一个简单的学生成绩管理系统的课程设计,功能较为全面,在这里分享给大家:
运行截图及完整代码如下
在这里插入图片描述

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;                         //类声明 

class student{
	public:
	char number[10];
	 char name[20];
		double chinese;
		double math;
		double english;
		double total;
		double average;
		int rank;
		student(char n[],char *na,double c,double m,double e)
		{
			strcpy(number,n);
			strcpy(name,na);
			chinese=c;
			math=m;
			english=e;
			int rank;
			total=chinese+math+english;
	average=total/3;
			}student(){}

void setdata(student s[]);
void printf(student s[]);
int search(student S[],int N,char *n);

};
void setdata(student &s)                              //定义成绩录入函数 
{
	cout<<"输入学号,姓名,语文,数学,英语成绩:"<<endl;
	cin>>s.number>>s.name>>s.chinese>>s.math>>s.english;
	s.total=s.chinese+s.math+s.english;
	s.average=s.total/3;
	
}
void compare(student *s,int n) 
 {
 	student stu;
 	for(int i=0;i<n;i++)
 	for(int j=1;j<n-i;j++)
 	{if(s[j].average>s[j-1].average)
 	{
	 stu=s[j];
	 s[j]=s[j-1];
	 s[j-1]=stu;}
	 }
 }
 void printf(student &s)
 {
cout<<s.number<<"\t"<<s.name<<"\t"<<s.chinese<<"\t"<<s.math
	<<"\t"<<s.english<<"\t"<<s.total<<"\t"<<s.average<<endl; 
 }
 
 int search(student S[],int N,char *n)
 {
 	for(int i=0;i<N;i++)
 	{
 		if(strcmp(S[i].number,n)==0)
 		return i;
	 }
	return -1;
 } 
int main() 
{
	cout<<"     ----------------------------------"
	      "---------------"<<endl;
	    cout<<"                欢迎使用学生成绩管理系统           "<<endl<<endl; 
		cout<<"         ☆☆☆☆☆☆"
		      "☆☆☆☆    择命令菜单    ☆☆☆☆☆☆☆☆☆"<<endl;
	    cout<<" ┆┆  ================================================= ┆┆"<<endl; 
		cout<<"             1.添加学生信息并保存                 "<<endl;
		cout<<"             2.输出所有学生信息             "<<endl;
		cout<<"             3.查找同学信息                     "<<endl;
		cout<<"             4.输出排序后的"
		      "学生信息              "<<endl;
		cout<<"             5.删除学生信息             "<<endl;
		cout<<"             0.退出系统           "<<endl;
        cout<<" ┇┇  ================================================= ┆┆"<<endl;
		cout<<"       ☆☆☆☆☆☆☆☆☆"
		      "☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆"<<endl;
	int m=0;
	
	student S[10]=
	{student("1001","王宇",85,94,83),
	student("1002","李明",78,89,65),
	student("1003","吴阳",83,62,85),
	student("1004","高程",85,64,83),
	student("1005","李丽",95,92,89)};
     
//	sort(S,m);
	int order=1;
	while(order!=0)
	{   
	    
		cout<<"输入命令选择:";
		cin>>order;
		switch(order)
		{
			case 1:
			cout<<"输入添加学生信息的人数"<<endl ;               cin>>m; 
				{if(m>0)
	 for(int i=5;i<m+5;i++)
	{
cout<<"下面输入第"<<i+1<<"位同学的数据:"<<endl;
		setdata(S[i]);
		cout<<endl; 
	} 
			break;
			case 2:
	cout<<"输出已保存的学生信息"<<endl;
	cout<<"学号:"<<"\t"<<"姓名:"<<"\t"<<"语文:"<<"\t"
	    <<"数学:"<<"\t"<<"英语:"<<"\t"<<"总分"<<"\t"<<"平均分"<<endl;
				if(m>0)
				{
						for(int k=0;k<m+5;k++)
					printf(S[k]);
				}
				else 
					for(int k=0;k<5;k++)
					printf(S[k]);
				break;
			case 3:
				{
					char n[10];
					cout<<"输入您要查找的学号:";
					cin>>n;
					int result=search(S,m+5,n);
					if(result==-1)
					cout<<"您输入的学号不存在!!!"<<endl;
					else 
					printf(S[result]);
				}
				break;
			case 4:
			cout<<"输出已保存的学生信息"<<endl;
				compare(S,m+5);
cout<<"学号:"<<"\t"<<"姓名:"<<"\t"<<"语文:"<<"\t"
<<"数学:"<<"\t"<<"英语:"<<"\t"<<"总分"<<"\t"<<"平均分"<<endl;
				for(int k=0;k<m+5;k++)
					printf(S[k]);
					break;
			case 5:
			char n1[10];
					cout<<"输入您要查找的学号:";
					cin>>n1;
		int	result1=search(S,m+5,n1);
cout<<"学号:"<<"\t"<<"姓名:"<<"\t"<<"语文:"<<"\t"
<<"数学:"<<"\t"<<"英语:"<<"\t"<<"总分"<<"\t"<<"平均分"<<endl;
		for(int k=0;k<m+5;k++)
		{       if(k!=result1)
					printf(S[k]);
			}
			break;	//cout<<"您输入的命令不存在!!!"<<endl;
		 } 
	}} cout<<"您已退出成绩管理系统!!!"<<endl;
	return 0;
}

相关推荐
©️2020 CSDN 皮肤主题: 技术工厂 设计师:CSDN官方博客 返回首页