12.11函数 结构体 多文件编译

 1.脑图

定义一个数组,用来存放从终端输入的5个学生的信息【学生的信息包含学生的姓名、年纪、性别、成绩】

1>封装函数 录入5个学生信息

2>封装函数 显示学生信息

3>封装函数 删除第几个学生信息,删除后调用显示学生信息函数 显示

4> 封装函数 按照学生的成绩 进行降序,降序后调用显示学生信息函数 显示

要求:多文件编译完成。

头文件、源文件、测试文件(mian)

1. test.头文件

#ifndef  __TEST_H__
#define  __TEST_H__

struct student {
    char name[30];
    int age;
    char sex[10];
    float score;
};

void input_data(struct student list[],int n);
void show_data(struct student list[],int n);
//void delete_data()
void sort(struct student list[],int n);

#endif

2.test.c文件 

#include <stdio.h>
#include "test.h"
void input_data(struct student list[],int n)
{
	for(int i=0;i<n;i++)
	{
        printf("enter the %d name ,age,sex,score:\n",i+1);
		scanf("%s %d %s %f",list[i].name,&list[i].age,list[i].sex,&list[i].score);
	}

}
void show_data(struct student list[],int n)
{
	for(int i=0;i<n;i++)
	{
		printf("name:%s age:%d  sex:%s  score:%f\n",list[i].name,list[i].age,list[i].sex,list[i].score);
	}

}
//void delete_data()


void sort(struct student list[],int n)
{
	for (int i=0;i<n;i++)
	{
		for(int j=0;j<n-1-i;j++)
		{
			if (list[j].score<list[j+1].score)
			{ struct student temp=list[j];
				list[j]=list[j+1];
				list[j+1]=temp;
			}
		}
	}
}

3.main.c 

#include <stdio.h>
#include "test.h"

int main(int argc, const char *argv[])
{
	struct student list[5];

	printf("录入学生信息:\n");
    input_data(list,5);

	printf("显示学生信息\n");
	show_data(list,5);



	printf("按照成绩排序\n");
	sort(list,5);
	show_data(list,5);

	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值