# ✨实验内容

## 🕐任务一

📃代码：

#include <stdio.h>
#include <string.h>
#define N 3
typedef struct student
{
int id;
char name[20];
char subject[20];
float perf;
float mid;
float final;
float total;
char level[10];
}stu;
void input(stu[],int);
void calc (stu[],int);
int fail (stu[],stu[],int);
void sort (stu[],int);
void print (stu[],int);
int main()
{
stu st[N],fst[N];
int k;
printf("录入学生成绩信息：\n");
input(st,N);
printf("\n学生成绩处理...\n");
calc(st,N);
k=fail(st,fst,N);
sort(st,N);
printf("\n学生成绩排名情况:\n");
print(st, N);
printf("\n不及格学生信息：\n");
print(fst,k);
return 0;
}

void input (stu s[],int n)
{
for (int i = 0; i < n; ++i)
scanf("%d %s %s %f %f %f",&s[i].id,s[i].name,s[i].subject,&s[i].perf,&s[i].mid,&s[i].final);
}

void calc (stu s[],int n)
{

for (int i = 0; i < n; ++i)
{
s[i].total=s[i].perf*0.2+s[i].mid*0.2+s[i].final*0.6;
if(s[i].total>90)
strcpy(s[i].level,"优");
else if (s[i].total>80)
strcpy(s[i].level,"良");
else if (s[i].total>70)
strcpy(s[i].level,"中");
else if (s[i].total>60)
strcpy(s[i].level,"及格");
else
strcpy(s[i].level,"不及格");
}

}

int fail (stu s[],stu f[],int n)
{
int k=0;
for (int i = 0; i < n; ++i)
if (s[i].total<60)
f[k++]=s[i];
return k;
}

void sort (stu s[],int n)
{
stu temp;
for (int i = 0; i < n; ++i)
for (int j = 0; j < n-1; ++j)
if (s[j].total<s[j+i].total)
{
temp=s[j];
s[j]=s[j+1];
s[j+1]=temp;
}
}

void print (stu s[],int n)
{

printf("---------------\n");
printf("学号\t姓名\t考试科目\t平时成绩\t期中成绩\t期末成绩\t总评成绩\t成绩等级\n");
for (int i = 0; i < n; ++i)
{
printf("%d\t%s\t%s\t%-.2f\t\t%-.2f\t\t%-.2f\t\t%-.2f\t%s\n",s[i].id,s[i].name,s[i].subject,s[i].perf,s[i].mid,s[i].final,s[i].total,s[i].level);
}

}


🎨截图：

🤓反思：

## 🕑任务二

#include <stdio.h>
#include <string.h>
const int N=5;
typedef struct student
{
long id;
char name[20];
int score;
}stu;
void input (stu [],int);
int findminlist (stu [],stu [],int);
void output(stu [],int);

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

void input (stu s[],int n)
{
for (int i = 0; i < n; ++i)
scanf("%ld %s %d",&s[i].id,s[i].name,&s[i].score);
}

int findminlist (stu s[],stu t[],int n)
{
int min,count=0;
for (int i = 0; i < n; ++i)
{
min = s[0].score;
if (min > s[i].score)
min = s[i].score;
}
for (int i = 0; i < n; ++i)
if (min==s[i].score)
t[count++]=s[i];
return count;
}

void output(stu s[],int n)
{
for (int i = 0; i < n; ++i)
printf("%ld %s %d\n",s[i].id,s[i].name,s[i].score);
}


## 🕒任务三

📃代码：

#include <stdio.h>
#include <string.h>
const int N = 10;
typedef struct student
{
long 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 s[N];
printf("录入%d个考生信息: 准考证号，姓名，客观题得分(<=40)，操作题得分(<=60):\n",N);
input(s,N);
printf("\n对考生信息进行处理: 计算总分，确定等级\n");
process(s,N);
printf("\n打印考生完整信息: 准考证号，姓名，客观题得分，操作题得分，总分，等级:\n");
output(s,N);
return 0;
}
void input(STU s[],int n)
{
for (int i = 0; i < n; ++i)
scanf("%ld%s%f%f",&s[i].id,s[i].name,&s[i].objective,&s[i].subjective);
}
void output(STU s[], int n)
{
for (int i = 0; i < n; ++i)
printf("%ld %s %f %f %f %s\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, j, k;
STU temp;
for (i = 0; i < n; ++i)
{
s[i].sum = 0.4 * s[i].subjective + 0.6 * s[i].objective;
}
for (i = 0; i < n - 1; i++)
{
k = i;
for (j = i + 1; j < n; j++)
if (s[j].sum < s[k].sum)
k = j;
if (k != i)
{
temp = s[i];
s[i] = s[k];
s[k] = temp;
}
}
for ( i = 0; i < n; ++i)
{
if (i<=n/10)
strcpy(s[i].level,"优秀");
else if (i<=n/2)
strcpy(s[i].level,"合格");
else
strcpy(s[i].level,"不及格");
}
}


🎨截图：

🤓反思：

posted @ 2020-12-24 17:18  李柳星  阅读(55)  评论(1编辑  收藏  举报