网站策划的前景,服务好的企业网站怎么建设,wordpress注册没有密码错误,免费打广告平台有哪些思维导图
小练习#xff1a;
定义一个数组#xff0c;用来存放从终端输入的5个学生的信息【学生的信息包含学生的姓名、年纪、性别、成绩】
1封装函数 录入5个学生信息
2封装函数 显示学生信息
3封装函数 删除第几个学生信息#xff0c;删除后调用显示学…思维导图
小练习
定义一个数组用来存放从终端输入的5个学生的信息【学生的信息包含学生的姓名、年纪、性别、成绩】
1封装函数 录入5个学生信息
2封装函数 显示学生信息
3封装函数 删除第几个学生信息删除后调用显示学生信息函数 显示
4 封装函数 按照学生的成绩 进行降序降序后调用显示学生信息函数 显示
要求多文件编译完成。
头文件、源文件、测试文件mian
源文件5.c
#include stdio.h
#include string.h
#include 5.h//头文件
void sca(struct student stu[],int a)//输入数据
{for(int i0;ia;i){printf(请输入第%d个学生的姓名性别年龄成绩\n,i1);scanf(%s%s%d%f,stu[i].name,stu[i].sex,stu[i].age,stu[i].grdae);}
}
void put(struct student *p,int a)//输出成绩
{for(int j0;ja;j){printf(第%d位学生的姓名为%s 性别为%s 年龄为%d 成绩为%.1f\n,j1,(pj)-name,(pj)-sex,(pj)-age,(pj)-grdae);}
}
void del(struct student stu[],int a,int n)//删除把需要删除的放到最后再打印前面的数据
{for(int in-1;ia-1;i){stu[i]stu[i1];}put(stu,a-1);
}
void swap(struct student stu[],int a)//降序排序
{struct student temp;for(int i0;ia;i){for(int j0;ja-1-i;j){if(stu[j].grdaestu[j1].grdae)//冒泡排序{tempstu[j];stu[j]stu[j1];stu[j1]temp;}}}printf(排序后的结果为\n);put(stu,a-1);
}
头文件5.h
#ifndef __5__//防止重引用
#define __5__
#include stdio.h
#include string.h
#include stdlib.h
#endif
struct student// 结构体
{char name[30];char sex[10];int age;float grdae;
};void sca(struct student stu[],int a);//输入
void put(struct student *p,int a);//输出
void del(struct student stu[],int a,int n);//删除
void swap(struct student stu[],int a);//排序测试文件mian6.c
#include stdio.h
#include string.h
#include5.h//引用头文件int main(int argc, const char *argv[])
{printf(请输入学生数量\n);int a;scanf(%d,a);struct student stu[a];sca(stu,a);//输入put(stu,a);//输出printf(请输入删除第几位学生 :);int n;scanf(%d,n);del(stu,a,n);//删除swap(stu,a);//排序return 0;
}运行截图