标签:ima tput strcpy ons include fclose 信息 准考证 img
《实验七》
验证性实验1:
验证性内容2:
验证性内容3:
验证性内容4:
以二进制形式存入file4.dat后,内容不可以直接读出
编程练习:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const int N = 5;
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) {
FILE *fp;
int i;
fp=fopen("examinee.txt","r");
if(fp==NULL)
printf("文件打开失败!");
for(i=0;i<n;i++)
fscanf(fp,"%ld%s%f%f",&s[i].id,s[i].name,&s[i].objective,&s[i].subjective);
fclose(fp);
}
void output(STU s[], int n) {
FILE *fp;
int i;
fp=fopen("result.txt","w");
if(fp==NULL)
printf("文件打开失败!");
for(i=0;i<n;i++)
fprintf(fp,"%8ld %s %5.2f %5.2f %5.2f %s\n",s[i].id,s[i].name,s[i].objective,s[i].subjective,s[i].sum,s[i].level);
fclose(fp);
}
void process(STU s[], int n) {
int i,j;STU temp;
for(i=0;i<n;i++){
s[i].sum=s[i].objective+s[i].subjective;}
for(i=0;i<n;i++){
for(j=0;j<n-1-i;j++){
if(s[j].sum<s[j+1].sum){
temp=s[j+1];
s[j+1]=s[j];
s[j]=temp;
}
}
}
for(i=0;i<n;i++){
if((i+1)<=0.1*n)
strcpy(s[i].level,"优秀");
else if((i+1)>0.5*n)
strcpy(s[i].level,"不合格");
else
strcpy(s[i].level,"合格");
}
}
标签:ima tput strcpy ons include fclose 信息 准考证 img
原文地址:https://www.cnblogs.com/Francis-BJ/p/12125285.html