首页 > 其他 > 详细

实验6

时间:2019-12-24 22:47:34      阅读:89      评论:0      收藏:0      [点我收藏+]
#include <stdio.h>
#include <stdlib.h> 

const int N=5;

// 定义结构体类型struct student,并定义STU为其别名 
typedef struct student {
	long no;
	char name[20];
	int score; 	
}STU;

// 函数声明 
void input(STU s[], int n);
int findMinlist(STU s[], STU t[], int n);
void output(STU s[], int n);

int main() {
	STU stu[N], minlist[N];
	int count;
	
	printf("录入%d个学生信息\n", N);
	input(stu, N);
	
	printf("\n统计最低分人数和学生信息...\n");
	count = findMinlist(stu, minlist, N);
	
	printf("\n一共有%d个最低分,信息如下:\n", count);
	output(minlist, count);
	 
	system("pause");
	return 0;
} 

// 输入n个学生信息,存放在结构体数组s中 
void input(STU s[], int n) {
	int i;
	for(i=0; i<n; i++) 
		scanf("%ld %s %d", &s[i].no, s[i].name, &s[i].score);
} 

// 输出结构体s中n个元素信息
void output(STU s[], int n) {
	int i;
	for(i=0; i<n; i++)
		printf("%ld %s %d\n", s[i].no, s[i].name, s[i].score); 
} 

// 在结构体数组s中,查找最低分学生的记录,将其存入结构体数组s中
// 形参n是结构体数组s中元素个数
// 函数返回最低分的学生人数 
int findMinlist(STU s[], STU t[], int n) {
	int i,k=0;STU min;
	for(i=1;i<5;i++){
		min.score=s[0].score;
		if(s[i].score<min.score)
		min.score=s[i].score;
	}

	for(i=0;i<5;i++){
	
	if(s[i].score==min.score)
	t[k++]=s[i];}
	return k;
} 

  技术分享图片

#include <stdio.h>
#include <stdlib.h> 
#include <string.h>
const int N = 10;

// 定义结构体类型struct student,并定义其别名为STU 
typedef struct student {
	long int id;
	char name[20];
	float objective;	/*客观题得分*/
	float subjective;	/*操作题得分*/
	float sum;
	char level[10];	
}STU; 

// 函数声明
void input(STU s[], int n);
void output(STU s[], int n);
void process(STU s[], int n);

int main() {
	STU stu[N];
	
	printf("录入%d个考生信息: 准考证号,姓名,客观题得分(<=40),操作题得分(<=60)\n", N); 
	input(stu, N);
	
	printf("\n对考生信息进行处理: 计算总分,确定等级\n");
	process(stu, N);
	
	printf("\n打印考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级\n");
	output(stu, N); 
	
	system("pause");
	return 0;
} 

// 录入考生信息:准考证号,姓名,客观题得分,操作题得分
void input(STU s[], int n) {
int i;
for(i=0;i<n;i++)
scanf("%d %s %f %f",&s[i].id,&s[i].name,&s[i].objective,&s[i].subjective);
}

//输出考生完整信息: 准考证号,姓名,客观题得分,操作题得分,总分,等级
void output(STU s[], int n) {
int i;
for(i=0; i<n; i++) {
     printf("%22ld %8s %10.2f %8.2f %8.2f %5s\n", s[i].id, s[i].name, s[i].objective, s[i].subjective, s[i].sum, s[i].level); 
}
}

// 对考生信息进行处理:计算总分,排序,确定等级
void process(STU s[], int n) {
	int i;
	for(i=0;i<n;i++){
	s[i].sum=s[i].objective*0.4+s[i].subjective*0.6;
	}
	int j,k;STU temp;
	for(j=0;j<n-1;j++){
	for(k=0;k<n-1-i;k++)
	if(s[k].sum<s[k+1].sum){
	
	temp=s[k];
	s[k]=s[k+1];
	s[k+1]=temp;}
	for(i=0;i<n;i++)
	if(i<=n/10)
	strcpy(s[i].level,"优秀");
	else if(i>n/10&&i<=n/2)
	strcpy(s[i].level,"合格");
	else strcpy(s[i].level,"不合格");
		
	}
	
}

  技术分享图片

实验6

原文:https://www.cnblogs.com/1234cwy/p/12093838.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!