本人是大一新生剛剛學習c語言不久,感覺寫到這個東西還是有些吃力,特地分享一下自己的代碼和心得。(大一學生剛接觸編程能力有限 僅限初學者交流溝通)
先放代碼(編程環境vs2019)
#define _CRT_SECURE_NO_WARNINGS 1
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int n = 0;
struct student
{
unsigned long long num;
char name[30];
float score;
float sum;
float aver;
};
void shurushuju(struct student stu[], int n);
void sumandave(struct student stu[], int n);
void third(struct student stu[], int n);
void four(struct student stu[], int n);
void chaxun(struct student stu[], int n);
void fenxi(struct student stu[], int n);
int main(void)
{
struct student stu[30];
printf("請輸入學生人數:");
scanf("%d", &n);
while (1)
{
int A = 0;
printf(" 歡迎來到 《《《《天工大成績管理系統》》》》\n");
printf(" ************************************************\n");
printf(" 1.Input record\n");
printf(" 2.Caculate total and average score of course\n");
printf(" 3.Sort in descending order by score\n");
printf(" 4.Sort in ascending order by number\n");
printf(" 5.Search by number\n");
printf(" 6.Statistic analysis\n");
printf(" 7.List record(第七個功能和題設違背 寫不了)\n");
printf(" 0.Exit\n");
printf(" ************************************************\n");
printf(" 請輸入你的選擇序號:");
scanf("%d", &A);
switch (A)
{
case 1:
shurushuju(stu, n);
break;
case 2:
sumandave(stu, n);
break;
case 3:
third(stu, n);
break;
case 4:
four(stu, n);
break;
case 5:
chaxun(stu, n);
break;
case 6:
fenxi(stu, n);
break;
case 0:
exit(0);
default:printf("error");
}
}
return 0;
}
//輸入基礎數據到結構體里
void shurushuju(struct student stu[], int n)
{
int i = 0;
printf("輸入學號 姓名 成績:\n");
for (i = 0;i< n;i++)
{
scanf("%lld %s %f", &stu[i].num, stu[i].name, &stu[i].score);
printf("%lld,%s,%.1f已錄入!", stu[i].num, stu[i].name, stu[i].score);
getchar();
}
}
//負責計算總和以及平均數
void sumandave(struct student stu[], int n)
{
float stuTemp1 = 0;
float aver1;
int j;
for (j = 0;j< n;j++)
{
stuTemp1 += stu[j].score;
};
aver1 = stuTemp1 / n;
printf("總和是%.1f 平均分是%.1f\n", stuTemp1, aver1);
getchar();
}
//冒泡排序 剛學會
void third(struct student stu[], int n)
{
int i, j;
struct student stuTemp;
for (i = 0;i< n - 1;i++)
{
for (j = 0;j< n - 1 - i;j++)
{
if ((stu[j].score)< (stu[j + 1].score))
{
stuTemp = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = stuTemp;
}
}
}
for (i = 0; i< n; i++)
{
printf("%lld %s %.1f\n", stu[i].num, stu[i].name, stu[i].score);
}
}
//按照學號從小到大排列成績表
void four(struct student stu[], int n)
{
int i, j;
struct student stuTemp2;
for (i = 0;i< n - 1;i++)
{
for (j = 0;j< n - 1 - i;j++)
{
if ((stu[j].num) >(stu[j + 1].num))
{
stuTemp2 = stu[j];
stu[j] = stu[j + 1];
stu[j + 1] = stuTemp2;
}
}
}
for (i = 0; i< n; i++)
{
printf("%lld %s %.1f\n", stu[i].num, stu[i].name, stu[i].score);
}
}
//通過學號查詢學生成績等信息
void chaxun(struct student stu[], int n)
{
unsigned long long point;
int i = 1;
int j = 0;
while (i)
{
printf("請先輸入學號");
scanf("%lld", &point);
for (j = 0;j< n;j++)
{
if (point == stu[j].num)
{
printf("%lld %s %.1f\n", stu[j].num, stu[j].name, stu[j].score);
}
}
}
}
//分析一波
void fenxi(struct student stu[], int n)
{
int A = 0, B = 0, C = 0, D = 0, E = 0, i = 0;
for (i = 0;i< n;i++)
{
if (stu[i].score<= 100 && stu[i].score >= 90)
A++;
if (stu[i].score<= 89 && stu[i].score >= 80)
B++;
if (stu[i].score<= 79 && stu[i].score >= 70)
C++;
if (stu[i].score<= 69 && stu[i].score >= 60)
D++;
if (stu[i].score<= 59 && stu[i].score >= 0)
E++;
}
printf("每個類別的人數有\nA:%d人\nB:%d人\nC:%d人\nD:%d人\nE:%d人\n ", A, B, C, D, E);
float a = 0, b = 0, c = 0, d = 0, e = 0;
a = 100 * A / n;
b = 100 * B / n;
c = 100 * C / n;
d = 100 * D / n;
e = 100 * E / n;
printf("每個類別所占百分比是\nA:%.1f%%\nB:%.1f%%\nC:%.1f%%\nD:%.1f%%\nE:%.1f%%\n", a, b, c, d, e);
}
涉及到一些知識點
比如說
1冒泡排序
2使用類似stu[i].score 去獲取結構體的數據
3名字是用字符串類型定義的 字符串都是使用數組 所以定義結構體一開始name都有[] 一開始不太清楚胡亂去加沒有理解清楚其中的意義
4因為我們學校學號位數超越了長整型 一開始一直亂碼 所以選用了更大的unsigined long long 后續輸出符也注意是%lld
最后歡迎初學者一起交流
你是否還在尋找穩定的海外服務器提供商?創新互聯www.cdcxhl.cn海外機房具備T級流量清洗系統配攻擊溯源,準確流量調度確保服務器高可用性,企業級服務器適合批量采購,新人活動首月15元起,快前往官網查看詳情吧
本文標題:高級程序設計(大一教材)第八/8章實驗學生成績管理系統-創新互聯
地址分享:http://newbst.com/article42/dipghc.html
成都網站建設公司_創新互聯,為您提供自適應網站、Google、ChatGPT、營銷型網站建設、微信小程序、網站設計
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯