📄 operate.h
字号:
/*=======================================*/
//结构体定义,变量定义
/*=======================================*/
#define MAX 50
int stu_max;
typedef struct{
int number;
char name[20];
char sex[2];
int english;
int math;
int total;
int average;
}student;
student stu[MAX];
/*=======================================*/
//显示所有元素
/*=======================================*/
void Print(student temp[])
{
for(int i=0; i<stu_max; i++)
{
printf("=第%d条记录==========",i+1);
printf("\n|学生学号:");
printf("%d",temp[i].number);
printf("\n|学生名字:");
printf("%s",temp[i].name);
printf("\n|学生性别:");
printf("%s",temp[i].sex);
printf("\n|学生英语成绩:");
printf("%d",temp[i].english);
printf("\n|学生数学成绩:");
printf("%d",temp[i].math);
stu[i].total=temp[i].english+temp[i].math;
printf("\n|学生总成绩:");
printf("%d",temp[i].total);
stu[i].average=temp[i].total/2;
printf("\n|学生平均成绩:");
printf("%d",temp[i].average);
printf("\n=第%d条记录显示完毕==\n\n",i+1);
printf("\n");
}
}
/*=======================================*/
//数组插入操作,第I个后位置插入
/*=======================================*/
void Insert(student temp[], int position)
{
student tmp;
if(position>stu_max)
printf("插入位置过大\n");
else
{
printf("|学生学号:");
scanf("%d",&tmp.number);
printf("|学生名字:");
scanf("%s",&tmp.name);
printf("|学生性别:");
scanf("%s",&tmp.sex);
printf("|学生英语成绩:");
scanf("%d",&tmp.english);
printf("|学生数学成绩:");
scanf("%d",&tmp.math);
printf("\nn");
tmp.total=tmp.english+tmp.math;
tmp.average=tmp.total/2;
for(;stu_max>position;stu_max--)
{
temp[stu_max]=temp[stu_max-1];
}
stu_max++;
temp[position]=tmp;
}
}
/*=======================================*/
//数组删除操作
/*=======================================*/
void Delete(student temp[], int position)
{
if(position>stu_max)
printf("查找的位置过大\n");
else
{
for(;position<stu_max;position++)
{
temp[position-1]=temp[position];
}
stu_max--;
}
}
/*=======================================*/
//数组查找操作 (根据number查找)
/*=======================================*/
void Find(student temp[], int tempnum)
{
int i;
for(i=0; i<stu_max; i++)
{
if(tempnum==temp[i].number)
break;
}
printf("输出改记录:\n");
printf("\n|学生学号:");
printf("%d",temp[i].number);
printf("\n|学生名字:");
printf("%s",temp[i].name);
printf("\n|学生性别:");
printf("%s",temp[i].sex);
printf("\n|学生英语成绩:");
printf("%d",temp[i].english);
printf("\n|学生数学成绩:");
printf("%d",temp[i].math);
stu[i].total=temp[i].english+temp[i].math;
printf("\n|学生总成绩:");
printf("%d",temp[i].total);
stu[i].average=temp[i].total/2;
printf("\n|学生平均成绩:");
printf("%d",temp[i].average);
printf("\n");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -