📄 xuesheng.txt
字号:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
struct student
{
int num;
char name[20];
float score[3];
float ave;
};
int i=0;//全局变量 统计个数
void wo(struct student a[] ); //录入函数
void shi(struct student a[]); //排序函数
void shui(struct student a[]); //插入函数
void del(struct student a[]); //删除函数
void display(struct student a[]);//显示函数
void main()
{
struct student stu[50];
int number;
do
{
printf("\n\t\t\t学员成绩管理\n\n");
printf("\n☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆\n");
printf("\n\n请选择功能\n0.退出\n1.录入\n2.显示\n3.排序\n4>插入\n5.删除\n\n------------------\n");
scanf("%d",&number);
printf("\n------------------\n\n");
switch (number)
{
case 0:break;
case 1:wo(stu);break;
case 2:display(stu);break;
case 3:shi(stu);break;
case 4:shui(stu);break;
case 5:del(stu);break;
}
}while(number!=0);
printf("谢谢你已查寻完毕!下次再见!");
printf("\n");
}
void wo(struct student a[]) //录入函数
{
int j;
char b;
float sum=0;
printf("请输入学员信息\n");
do
{
printf("学号:");
scanf("%d",&a[i].num);
printf("姓名:");
scanf("%s",a[i].name);
printf("三门成绩\n");
for(j=0;j<3;j++)
{
printf("成绩%d:",j+1);
scanf("%f",&a[i].score[j]);
}
a[i].ave=(a[i].score[0]+a[i].score[1]+a[i].score[2])/3;
i++;
printf("是否继续\n(Y/N)");
fflush(stdin);
scanf("%c",&b);
}while(b=='Y'||b=='y');
display(a);
}
void display(struct student a[]) //显示函数
{
int k;
printf("学号\t姓名\t平均值\n");
for(k=0;k<i;k++)
{
printf("%d\t%s\t%.2f\n",a[k].num,a[k].name,a[k].ave);
}
}
void shi(struct student a[]) //排序函数
{
int j,k;
struct student temp;
for(k=0;k<i;k++)
{
for(j=0;j<i-k;j++)
{
if(a[j].ave<a[j+1].ave)
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
printf("排序后的学员信息如下\n");
display(a);
}
void shui(struct student a[]) //插入函数
{
int j,k;
struct student temp;
printf("学号:");
scanf("%d",&temp.num);
printf("姓名:");
scanf("%s",temp.name);
printf("三门成绩\n");
for(j=0;j<3;j++)
{
printf("成绩%d:",j+1);
scanf("%f",&temp.score[j]);
}
temp.ave=(temp.score[0]+temp.score[1]+temp.score[2])/3;
for(j=0;j<i;j++)
{
if(temp.ave>a[j].ave)
{
break;
}
}
for(k=i;k>j;k--)
{
a[k]=a[k-1];
}
i++;
a[j]=temp;
display(a);
}
void del(struct student a[]) //删除函数
{
int k,j;
printf("请输入要删除的学号:");
scanf("%d",&k);
for(j=0;j<i;j++)
{
if(k==a[j].num)
{
break;
}
}
if(j<i)
{
for(k=j;k<i-1;k++)
{
a[j]=a[j+1];
}
i--;
printf("删除后的学员信息\n");
display(a);
}
else
{
printf("没有您要删除的学员\n");
display(a);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -