学生管理系统

//学生管理系统

#include <stdio.h>
#include <malloc.h>
#include <string>
//定义结构体
struct Student
{
int age;
float score;
char name[100];
};
void main (void)
{

//变量声明
int len = 0;
int i = 0;
int j = 0;
struct Student t;
struct Student *pArr = NULL;

//函数声明
void InputStudent(struct Student *, int);
void sort(struct Student *, int);
void OutputStudent(struct Student *, int);

//动态构造一维数组
printf("请输入学生的个数:\n");
printf("len = ");
scanf("%d", &len);
pArr = (struct Student *)malloc(len * sizeof(struct Student));

//输入
for (i=0;i<len;++i)
{
	InputStudent(pArr, i);
}

//按降序进行冒泡排序
	sort(pArr, len);

//输出
	OutputStudent(pArr, len);

return;

}
void InputStudent(struct Student * pstu, int i) 
{
	printf("请输入第%d个学生的信息:\n", i+1);
	printf("age = ");
	scanf("%d", &pstu[i].age);
	printf("\n");

	printf("score = ");
	scanf("%f", &pstu[i].score);
	printf("\n");

	printf("name = ");
	scanf("%s", pstu[i].name);//name 作为数组名不需要&
	printf("\n");

}
void sort(struct Student * pArr, int len)
{
	int i, j = 0;
	struct Student t;
	for(i=0; i<len-1; ++i)
	{
		for(j=0; j<len-1-i; ++j)
		{
			if(pArr[j].score < pArr[j+1].score)
			{
				t = pArr[j];
				pArr[j] = pArr[j+1];
				pArr[j+1] = t;
			}
		}
	}
}
void OutputStudent(struct Student * pArr, int len) 
{
	int i = 0; 
	for (i=0;i<len;++i)
	{
	printf("第%d个学生的信息是:\n", i+1);
		
	printf("age = %d", pArr[i].age);
	printf("\n");

	printf("score = %f", pArr[i].score);
	printf("\n");

	printf("name = %s", pArr[i].name);
	printf("\n");

	printf("\n");
	}

}

/*****************************************
运行结果
—————————————————————
请输入学生的个数:
len =

输入值:3

请输入第1个学生的信息:
age =

输入值:20

score =

输入值:80.8

name =

输入值:张三

请输入第2个学生的信息:
age =

输入值:21

score =

输入值:98.5

name =

输入值:李四

请输入第3个学生的信息:
age =

输入值:22

score =

输入值:84.6

name =

输入值:王五

第1个学生的信息是:
age = 21
score = 98.500000
name = 李四

第2个学生的信息是:
age = 22
score = 84.599998
name = 王五

第3个学生的信息是:
age = 20
score = 80.800003
name = 张三

press any key to continue
————————————————
程序结束
*****************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值