Will the die switch hang up?
Recently, the results of the electrical model test have been announced soon, and I feel uneasy, but there is no alternative. So I wrote a program to predict whether the analog power will fail.
The scores and their default weights are shown in the following table:
Various achievements | Weight |
---|---|
The first process assessment | 5% |
The second process assessment | 5% |
The third process assessment | 5% |
4th process assessment | 5% |
operation | 10% |
experiment | 10% |
MOOC | 10% |
Final exam paper results | 50% |
This program can calculate the usual scores of the analog electronic course (the scores of the first 4 process assessments and homework, experiments, and MOOCs are converted in proportion), and give the minimum volume score without hanging!
代码:
#include <stdio.h>
#define M 7
float pscj = 0;
float pass_fail = 0;
float cj[2][M] = {
{
0} ,{
0.05,0.05,0.05,0.05,0.1,0.1,0.1} };
//第一行存储各项得分,第二行存储各项权重,默认权重初始化时已写入
float Daily_score(float score[2][M])//计算平时分数
{
float daily_cj = 0;
float i_cj = 0;
for (int i = 0; i < M; i++)
{
i_cj = cj[0][i] * cj[1][i];
daily_cj += i_cj;
}
return daily_cj;
}
void Q_A_1()//设置得分占比(各项权重)
{
float cj0[M] = {
0 };
for (int i = 0; i < 4; i++)
{
printf("请输入“第%d次过程考核”得分占比(小数):\n", i + 1);
scanf_s("%f", &cj0[i]);
}
printf("请输入“作业”得分占比(小数):");
scanf_s("%f", &cj0[4]);
printf("请输入“实验”得分占比(小数):");
scanf_s("%f", &cj0[5]);
printf("请输入“慕课”得分占比(小数):");
scanf_s("%f", &cj0[6]);
for (int i = 0; i < M; i++)
{
cj[1][i] = cj0[i];
}
}
void y_n() //更改权重
{
char x = 'x';
scanf_s("%c", &x,2);
if (x == 'n' || x == 'N')
{
printf("当前得分比重为默认值!\n");
}
else if (x == 'y' || x == 'Y')
{
Q_A_1();
printf("得分比重已重置!\n\n");
}
else
{
printf("请输入:“y”或“n”!\n");
y_n();
}
}
void Show() //展示默认信息
{
printf("本程序可以计算您的模电课程的平时成绩,并且给出您不挂的情况下的最少卷面分数!\n\n");
printf("开始!\n\n设置得分比重(默认):\n");
for (int i = 0; i < 4; i++)
{
printf("“第%d次过程考核”得分占比:%.2f %%\n", i + 1, 100.00 * cj[1][i]);
}
printf("“作业”得分占比:%.2f %%\n", 100.00 * cj[1][4]);
printf("“实验”得分占比:%.2f %%\n", 100.00 * cj[1][5]);
printf("“慕课”得分占比:%.2f %%\n", 100.00 * cj[1][6]);
printf("是(y)否(n)需要更改比重?\n请输入:“y”或“n”\n");
y_n();
}
void Q_A()//写入平时各项分数
{
for (int i = 0; i < 4;i++)
{
printf("请输入“第%d次过程考核”得分:", i + 1);
scanf_s("%f",&cj[0][i]);
}
printf("请输入“作业”得分:");
scanf_s("%f", &cj[0][4]);
printf("请输入“实验”得分:");
scanf_s("%f", &cj[0][5]);
printf("请输入“慕课”得分:");
scanf_s("%f", &cj[0][6]);
}
int flag(float arr[2][M]) //判断分数是否异常
{
int j = 0;
for (int i = 0; i < M; i++)
{
if (cj[0][i] > 100 || cj[0][i] < 0)
{
j++;
}
}
return j;
}
int main(int argc, char** argv)
{
Show();
loop:
{
Q_A();
if (flag(cj) == 0)
{
pscj = Daily_score(cj);
printf("您的平时成绩是:%.2f\n", pscj);
pass_fail = 2.00 * (60.00 - pscj);
if (pass_fail <= 100)
{
printf("您的卷面成绩至少为 %.2f 才能不挂科!\n\n", pass_fail);
printf("谢谢使用!祝您模电不挂科!\n");
}
else
{
printf("很遗憾!\n您的平时成绩太低,您的卷面成绩即使是满分(100)也会挂科!\n");
printf("不要气馁,明年再战!\n");
}
}
else
{
printf("输入有误!\n请输入正确的得分(必须为0~100范围内的数字)!\n\n");
goto loop;
}
}
return 0;
}
Written at the end:
There are many imperfections in this code.
For example: runtime
请输入:“y”或“n”!
Will repeat. Students who know how to solve it, please feel free to let me know! Comments are welcome!