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

📄 student.h

📁 刚学习C++时写的学生成绩管理系统,只需要创建file.cpp和student.h就行了
💻 H
📖 第 1 页 / 共 2 页
字号:
	bool found;
	char   q[15];
	cin>>q;
	if(p==NULL)
		cout<<"兄弟,无节点数据,不能从链表里修改!"<<endl;
	else
	{
		p=h;
		found=false;
		while(!found&&p!=NULL)
		if(strcmp(p->name,q)==0)
		found=true;
		else
		p=p->link;
		if(found)
		{
	    cout<<"  ┎───┬───┬───┬───┬───┬────┬───┬───┬───┓"<<endl;
        cout<<setw(8)<<"│学号"<<setw(8)<<"│姓名"<<setw(8)<<"│语文"<<setw(8)<<"│数学"<<setw(8)<<"│英语"
        <<setw(9)<<"  │C++语言 │"
        <<setw(8)<<"总分│"<<setw(6)<<"平均分"<<setw(6)<<"│名次  │"<<endl;
         cout<<"  ├───┼───┼───┼───┼───┼────┼───┼───┼───┤"<<endl;
       cout<<"  │"<<setw(6)<<p->number<<"│"<<setw(6)<<p->name<<"│"<<setw(6)<<p->score[0]
       <<"│"<<setw(6)<<p->score[1]<<"│"
       <<setw(6)<<p->score[2]<<"│"<<setw(6)<<p->score[3]<<"  │"
	   <<setw(6)<<p->sum<<"│"<<setw(6)<<p->average<<"│"<<setw(6)<<
	   p->order<<"│"<<setw(6)<<endl;
	   cout<<"  ├───┼───┼───┼───┼───┼────┼───┼───┼───┤"<<endl;
       cout<<"  ┖───┴───┴───┴───┴───┴────┴───┴───┴───┚"<<endl;

		 do{cout<<"请输入修改后的语文成绩:";
		 cin>>p->score[0];
		 while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入语文成绩:";
		 cin>>p->score[0];}
		 if(p->score[0]>100||p->score[0]<0)
		 cout<<"注意数据只能在0~100之间"<<endl;}
		 while(p->score[0]>100||p->score[0]<0);
		 do{cout<<"请输入修改后数学成绩:";cin>>p->score[1];
         while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入数学成绩:";
		 cin>>p->score[1];}
		 if(p->score[1]>100||p->score[1]<0)
		 cout<<"注意数据只能在0~100之间"<<endl;}
		 while(p->score[1]>100||p->score[1]<0);
		 do{cout<<"请输入修改英语成绩:";cin>>p->score[2]; 
		 while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入英语成绩:";
		 cin>>p->score[2];}
		 if(p->score[2]>100||p->score[2]<0)
		 cout<<"注意数据只能在0~100之间"<<endl;}		
		 while(p->score[2]>100||p->score[2]<0);
		 do{cout<<"请输入修改后的C++成绩:";cin>>p->score[3];
		 while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入C++成绩:";
		 cin>>p->score[3];}
		 if(p->score[3]>100||p->score[3]<0)
		 cout<<"注意数据只能在0~100之间"<<endl  ;}
		 while(p->score[3]>100||p->score[3]<0);
		 float s=0,ave=0;
		 for(int i=0;i<4;i++)
		 s+=p->score[i];
		 ave=s/4.0;
		 p->sum=s;
		 p->average=ave;
    	 p->order=0;
		 cout<<"\n恭喜你,修改成功!"<<endl;
		}
			else
				cout<<"无该生信息"<<endl;
	}
	return h;

}
void save(student *h)
{   
	student *p;
	p=h;
	ofstream outfile;
    cout<<"请输入保存文件名:"<<endl;
	char str[15];
	cin>>str;
	outfile.open(str,ios::out);
	if(!outfile)
	{
		cout<<"f2.data can not open";
	    exit(0);
	}
outfile<<"  ┎───┬───┬───┬───┬───┬────┬───┬───┬───┓"<<endl;
outfile<<setw(8)<<"│学号"<<setw(8)<<"│姓名"<<setw(8)<<"│语文"<<setw(8)<<"│数学"<<setw(8)<<"│英语"<<setw(9)<<"  │C++语言 │"
<<setw(8)<<"总分│"<<setw(6)<<"平均分"<<setw(6)<<"│名次  │"<<endl;
outfile<<"  ├───┼───┼───┼───┼───┼────┼───┼───┼───┤"<<endl;
while(p!=NULL)
{
if(p->link!=NULL){
outfile<<"  │"<<setw(6)<<p->number<<"│"<<setw(6)<<p->name<<"│"<<setw(6)<<p->score[0]
<<"│"<<setw(6)<<p->score[1]<<"│"
    <<setw(6)<<p->score[2]<<"│"<<setw(6)<<p->score[3]<<"  │"
	<<setw(6)<<p->sum<<"│"<<setw(6)<<p->average<<"│"<<setw(6)<<
	p->order<<"│"<<setw(6)<<endl;
outfile<<"  ├───┼───┼───┼───┼───┼────┼───┼───┼───┤"<<endl; }
else
{
	outfile<<"  │"<<setw(6)<<p->number<<"│"<<setw(6)<<p->name<<"│"<<setw(6)<<p->score[0]
<<"│"<<setw(6)<<p->score[1]<<"│"
    <<setw(6)<<p->score[2]<<"│"<<setw(6)<<p->score[3]<<"  │"
	<<setw(6)<<p->sum<<"│"<<setw(6)<<p->average<<"│"<<setw(6)<<
	p->order<<"│"<<setw(6)<<endl;

outfile<<"  ┖───┴───┴───┴───┴───┴────┴───┴───┴───┚"<<endl;
}
 p=p->link;

}
 outfile.close();
 cout<<"成功保存"<<endl;
}

student* load()
{
	student *p,*q,*h=NULL;
	FILE *fp;
	char infile[10];
	cout<<"请输入要加载的文件名"<<endl;
	cin>>infile;
	if((fp=fopen(infile,"rb"))==NULL)
	{
		cout<<"不能打开文件"<<endl;
		exit(1);
	}
    p=new student;
	if(!p)
	{
	cout<<"无可用空间"<<endl;
	return h;
	}
	h=p;
	while(!feof(fp))
	{
		if(1!=fread(p,sizeof(student),1,fp))
			break;
		p->link=new student;
		if(!p->link)
		{
		 cout<<"无可用空间"<<endl;
		 return h;
		}
		q=p;
		p=p->link;
	}
	q->link=NULL;
	fclose(fp);
	cout<<"\n\n---你已经成功加载了数据---\n\n";
	return h;
}
student  *insert(student *h)
{   
	student *newnode,*p;
	newnode=new student;
	cout<<"请输入你要添加的记录";// 输入该学生的信息
		 cout<<"\n请输入学号";
	cin>>newnode->number;
	cout<<"请输入姓名:";
	cin>>newnode->name;
	 do{cout<<"请输入语文成绩:";cin>>newnode->score[0];
		 while(!cin)
		 {
		 cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入语文成绩:";
		 cin>>newnode->score[0];}
		 if(newnode->score[0]>100||newnode->score[0]<0)
		 cout<<"注意数据只能在0~100之间"<<endl;}
		 while(newnode->score[0]>100||newnode->score[0]<0);
		 do{cout<<"请输入数学成绩:";cin>>newnode->score[1];
         while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入数学成绩:";
		 cin>>newnode->score[1];}
		 if(newnode->score[1]>100||newnode->score[1]<0)
		 cout<<"注意数据只能在0~100之间"<<endl;}
		 while(newnode->score[1]>100||newnode->score[1]<0);
		 do{cout<<"请输入英语成绩:";
		 cin>>newnode->score[2]; 
		 while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入英语成绩:";
		 cin>>newnode->score[2];}
		 if(newnode->score[2]>100||newnode->score[2]<0)
		 cout<<"注意数据只能在0~100之间"<<endl;}		
		 while(newnode->score[2]>100||newnode->score[2]<0);
		 do{cout<<"请输入C++成绩:";
		 cin>>newnode->score[3];
		 while(!cin)
		 {cin.clear();
		 cin.ignore(80,'\n');
		 cout<<"数据输入错误,请重新输入C++成绩:";
		 cin>>newnode->score[3];}
		 if(newnode->score[3]>100||newnode->score[3]<0)
		 cout<<"注意数据只能在0~100之间"<<endl  ;}
		 while(newnode->score[3]>100||newnode->score[3]<0);
		 float s=0,ave=0;
		 for(int i=0;i<4;i++)
		 s+=newnode->score[i];
		 ave=s/4.0;
		 newnode->sum=s;
		 newnode->average=ave;
		 newnode->order=0;
	     p=h;
	     char name[10];
	     cout<<"请输入记录位置(你想把这条记录放在那条记录后面,就输入那条记录的姓名)"<<endl;
	//该记录将由你输入的学生的名字,将记录插入其后。
	cin>>name;
	if(p==NULL)
	{
	newnode->link=NULL;
    h=newnode;
	}
	else
	{
	if(strcmp(p->name,name)!=0)
		p=p->link;
	newnode->link=p->link;
	p->link=newnode;
	}
  	return h;
}
void computer(student *h)//计算学生的总分和总平均分
{
	student *p;
	p=h;

	float ss=0,aa=0;
	while(p!=0)
	{
		ss+=p->sum;
		aa+=p->average;
		p=p->link;
	}
	cout<<"****************总分***************"<<"******平均分*************************"<<endl;
	cout<<"                "<<ss<<"              "<<"         "<<aa<<"                      "<<endl;   
}
student *pm(student *h)//排名
{   
  int i=0;
	student *p,*q,*t,*h1;
	h1=h->link;
	h->link=NULL;
	while(h1!=NULL)
	{
		t=h1;
		h1=h1->link;
		p=h;
		q=h;
		while(t->sum<p->sum&&p!=NULL)
		{
			q=p;
			p=p->link;
		}
		if(p==q)
		{
		t->link=p;
		h=t;
		}
		else
		{
			t->link=p;
			q->link=t;
		}
	}
	p=h;
	while(p!=NULL)
	{
		i++;
		p->order=i;
		p=p->link;
	}
	cout<<"再次恭喜你了,排名成功!\n"<<endl;
	cout<<"按4可以显示排名后的所有记录"<<endl<<endl;
	return h;
}
void clr()
{
	system("cls");
}
};

⌨️ 快捷键说明

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