本人是大一新生剛剛學(xué)習(xí)c語(yǔ)言不久,感覺寫到這個(gè)東西還是有些吃力,特地分享一下自己的代碼和心得。(大一學(xué)生剛接觸編程能力有限 僅限初學(xué)者交流溝通)
先放代碼(編程環(huán)境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("請(qǐng)輸入學(xué)生人數(shù):");
scanf("%d", &n);
while (1)
{
int A = 0;
printf(" 歡迎來到 《《《《天工大成績(jī)管理系統(tǒng)》》》》\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(第七個(gè)功能和題設(shè)違背 寫不了)\n");
printf(" 0.Exit\n");
printf(" ************************************************\n");
printf(" 請(qǐng)輸入你的選擇序號(hào):");
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;
}
//輸入基礎(chǔ)數(shù)據(jù)到結(jié)構(gòu)體里
void shurushuju(struct student stu[], int n)
{
int i = 0;
printf("輸入學(xué)號(hào) 姓名 成績(jī):\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();
}
}
//負(fù)責(zé)計(jì)算總和以及平均數(shù)
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();
}
//冒泡排序 剛學(xué)會(huì)
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);
}
}
//按照學(xué)號(hào)從小到大排列成績(jī)表
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);
}
}
//通過學(xué)號(hào)查詢學(xué)生成績(jī)等信息
void chaxun(struct student stu[], int n)
{
unsigned long long point;
int i = 1;
int j = 0;
while (i)
{
printf("請(qǐng)先輸入學(xué)號(hào)");
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("每個(gè)類別的人數(shù)有\(zhòng)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("每個(gè)類別所占百分比是\nA:%.1f%%\nB:%.1f%%\nC:%.1f%%\nD:%.1f%%\nE:%.1f%%\n", a, b, c, d, e);
}
涉及到一些知識(shí)點(diǎn)
比如說
1冒泡排序
2使用類似stu[i].score 去獲取結(jié)構(gòu)體的數(shù)據(jù)
3名字是用字符串類型定義的 字符串都是使用數(shù)組 所以定義結(jié)構(gòu)體一開始name都有[] 一開始不太清楚胡亂去加沒有理解清楚其中的意義
4因?yàn)槲覀儗W(xué)校學(xué)號(hào)位數(shù)超越了長(zhǎng)整型 一開始一直亂碼 所以選用了更大的unsigined long long 后續(xù)輸出符也注意是%lld
最后歡迎初學(xué)者一起交流
你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級(jí)流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級(jí)服務(wù)器適合批量采購(gòu),新人活動(dòng)首月15元起,快前往官網(wǎng)查看詳情吧
本文標(biāo)題:高級(jí)程序設(shè)計(jì)(大一教材)第八/8章實(shí)驗(yàn)學(xué)生成績(jī)管理系統(tǒng)-創(chuàng)新互聯(lián)
地址分享:http://jinyejixie.com/article42/dipghc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、Google、ChatGPT、營(yíng)銷型網(wǎng)站建設(shè)、微信小程序、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容