欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C語言實(shí)現(xiàn)簡單學(xué)生成績管理系統(tǒng)項(xiàng)目

 更新時(shí)間:2022年07月22日 14:53:38   作者:xiq1212  
這篇文章主要為大家詳細(xì)介紹了C語言實(shí)現(xiàn)簡單學(xué)生成績管理系統(tǒng)項(xiàng)目,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了C語言實(shí)現(xiàn)學(xué)生成績管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

系統(tǒng)界面及相關(guān)要求

1)系統(tǒng)運(yùn)行,打開如下界面。列出系統(tǒng)幫助菜單(即命令菜單),提示輸入命令。

2)開始時(shí)還沒有錄入成績,所以輸入命令 L 也無法列出成績。應(yīng)提示“成績表為空!請先使用命令 T 錄入學(xué)生成績。”

同理,當(dāng)輸入其他的成績處理命令時(shí)也作相應(yīng)的處理。

3)輸入命令 T,調(diào)用Type子函數(shù)錄入成績。

界面提示輸入學(xué)生人數(shù)

輸入3 提示輸入3名學(xué)生的3門課成績,列出成績單的表頭“學(xué)號(hào) 語文 數(shù)學(xué) 英語”,提示學(xué)號(hào):1

輸入1號(hào)學(xué)生的3門課成績,用空格間隔,回車結(jié)束。提示學(xué)號(hào):2

輸入2號(hào)學(xué)生的3門課成績,用空格間隔,回車結(jié)束。提示學(xué)號(hào):3

輸入3號(hào)學(xué)生的3門課成績,用空格間隔,回車結(jié)束。Type子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

4)輸入命令 L ,調(diào)用List子函數(shù)輸出成績表。List子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

5)輸入命令 A ,調(diào)用Average子函數(shù)計(jì)算平均分,提示“平均分已計(jì)算。請使用命令L查看。” Average子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。
輸入命令 L ,調(diào)用List子函數(shù)輸出成績表。List子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

6)輸入命令 P ,調(diào)用Sort子函數(shù)將各學(xué)生記錄按平均分由高到低排序,提示“完成排序。請使用命令L查看。” Sort子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

輸入命令 L ,調(diào)用List子函數(shù)輸出成績表。List子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

7)輸入命令 S ,調(diào)用Search子函數(shù)查詢學(xué)生成績,提示“輸入要查詢的學(xué)生學(xué)號(hào)”。

輸入2 找到2號(hào)學(xué)生的成績并輸出。Search子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

8)輸入命令C 執(zhí)行清屏函數(shù)語句system(“clear”);

清除屏幕的所有內(nèi)容。提示輸入命令。

9)輸入命令H 調(diào)用Help子函數(shù)顯示幫助菜單。Help子函數(shù)調(diào)用結(jié)束,返回。提示輸入命令。

10)輸入命令Q ,則退出系統(tǒng)。

注意:

1)輸出數(shù)組元素時(shí),要將學(xué)號(hào)單獨(dú)處理,輸出為整數(shù)(即保留0位小數(shù))。同理,在計(jì)算成績時(shí)也要將第1列的學(xué)號(hào)撇開,只計(jì)算第2列之后的。成績保留1位小數(shù)。
2)學(xué)生人數(shù)n貫穿始終,通過n的值判斷當(dāng)前命令的子函數(shù)是否能夠調(diào)用執(zhí)行。例如:當(dāng)n=0時(shí),說明還沒有錄入成績。而一旦輸入命令T,也即調(diào)用Type子函數(shù)錄入了成績,則n的值就不再是0。當(dāng)n!=0時(shí),就可以進(jìn)行其他的成績操作,但不能再執(zhí)行錄用成績的操作。所以當(dāng)用戶輸入的命令無法執(zhí)行時(shí),應(yīng)當(dāng)給出提示。

代碼

#include <stdio.h>
#include <stdlib.h>
//#include "hs.h"
struct student
{
?? ?int id;
?? ?float yw;
?? ?float sx;
?? ?float wy;
?? ?float pj;
};
void help(void);
int type(struct student *p);
void list(struct student *p,int n);
void average(struct student *p,int n);
void search (struct student *p);
void sort(struct student *p,int n);
int main(int argc, const char *argv[])
{
?? ?char ch;
?? ?struct student stu[32];
?? ?int n=0;
?? ?while(1)
?? ?{
?? ??? ?printf("請輸入命令 = ");
?? ??? ?//getchar();
?? ??? ?scanf("%c",&ch);
?? ??? ?putchar(10);
?? ??? ?if(ch=='T')
?? ??? ?{
?? ??? ??? ?n=type(stu);
?? ??? ?}
?? ??? ?else if(ch=='L')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ??? ?list(stu,n);
?? ??? ?}
?? ??? ?else if(ch=='A')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?average(stu,n);
?? ??? ??? ??? ?printf("平均分已計(jì)算,請使用命令L查看!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(ch=='H')
?? ??? ??? ?help();
?? ??? ?else if(ch=='C')
?? ??? ??? ?system("clear");
?? ??? ?else if(ch=='S')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?search(stu);
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(ch=='P')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?sort(stu,n);
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(ch=='Q')
?? ??? ?{
?? ??? ??? ?printf("Press any key to continue!\n");
?? ??? ??? ?return -1;
?? ??? ?}
?? ??? ?getchar();
?? ?}
?? ?return 0;
}
int type(struct student *p)
{
?? ?int n=0;
?? ?printf("請輸入學(xué)生人數(shù):");
?? ?scanf("%d",&n);
?? ?printf("請輸入學(xué)生三門課的成績:\n");
?? ?printf("學(xué)號(hào) 語文 數(shù)學(xué) 外語\n");
?? ?for(int i=0;i<n;i++)
?? ?{
?? ??? ?printf("%d ? ?",i+1);
?? ??? ?struct student stu[i];
?? ??? ?scanf("%f %f %f",&(p+i)->yw,&(p+i)->sx,&(p+i)->wy);
?? ?}
?? ?return n;
}
void list(struct student *p,int n)
{
?? ?printf("學(xué)生成績?nèi)缦拢篭n");
?? ?printf("學(xué)號(hào) 語文 數(shù)學(xué) 外語 平均分\n");
?? ?for(int i=0;i<n;i++)
?? ?{
?? ??? ?printf("%d ? ?",i+1);
?? ??? ?printf("%.1f %.1f %.1f %.1f",p->yw,p->sx,p->wy,p->pj);
?? ??? ?p++;
?? ??? ?putchar(10);
?? ?}
}
void average(struct student *p,int n)
{
?? ?for(int i=0;i<n;i++)
?? ?{
?? ??? ?(p->pj)=((p->yw)+(p->sx)+(p->wy))/3;
?? ??? ?p++;
?? ?}
}
void help(void)
{
?? ?printf("**********************************\n");
?? ?printf(" * ?學(xué)生成績管理系統(tǒng)——幫助菜單 ?* \n");
?? ?printf("**********************************\n");
?? ?printf(" * ? H = 顯示幫助菜單 ? ? ? ? ? * \n");
?? ?printf(" * ? T = 成績錄入 ? ? ? ? ? ? ? * \n");
?? ?printf(" * ? A = 計(jì)算學(xué)生平均分 ? ? ? ? * \n");
?? ?printf(" * ? L = 列出成績單 ? ? ? ? ? ? * \n");
?? ?printf(" * ? P = 按平均成績由高到低排序 * \n");
?? ?printf(" * ? S = 按學(xué)號(hào)查詢學(xué)生成績 ? ? * \n");
?? ?printf(" * ? C = 清屏 ? ? ? ? ? ? ? ? ? * \n");
?? ?printf(" * ? Q =退出系統(tǒng) ? ? ? ? ? ? ? ?* \n");
?? ?printf("**********************************\n");
?? ?printf(" *Copyright(c) 2022.3.15 By liq* \n");
?? ?printf("**********************************\n");
}
void search(struct student *p)
{
?? ?int s=0;
?? ?printf("請輸入要查詢的學(xué)生號(hào):");
?? ?scanf("%d",&s);
?? ?printf("學(xué)號(hào) 語文 數(shù)學(xué) 外語 平均分\n");
?? ?printf("%d ? %.1f ?%.1f ?%.1f ?%.1f",s,(p+s-1)->yw,(p+s-1)->sx,(p+s-1)->wy,(p+s-1)->pj);
?? ?putchar(10);
}
void sort(struct student *p,int n)
{
?? ?struct student temp;
?? ?int i,j;
?? ?for(i=0;i<n;i++)
?? ?{
?? ??? ?for(j=0;j<n-i-1;j++)
?? ??? ?{
?? ??? ??? ?if(p[j].pj<p[j+1].pj)
?? ??? ??? ?{
?? ??? ??? ??? ?temp=p[j];
?? ??? ??? ??? ?p[j]=p[j+1];
?? ??? ??? ??? ?p[j+1]=temp;
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?printf("排序完成,請使用命令L查看!\n");
}

注意

如需要分文件編寫。
只需要將上述代碼的函數(shù)部分拿出來,新建兩個(gè)個(gè)文件:fun.c、fun.h。其中fun.c文件用來存放上述代碼的結(jié)構(gòu)體聲明以及函數(shù)部分(加上相應(yīng)的頭文件)。fun.h用來存放結(jié)構(gòu)體聲明以及函數(shù)聲明(加上相應(yīng)的頭文件)。
在主函數(shù)中要加上對應(yīng)的頭文件:#include “fun.h”(雙引號(hào),不是<>)。
編譯的時(shí)候需要將主函數(shù)以及新建的fun.c文件一起編譯,運(yùn)行還是同之前一樣,用./a.out運(yùn)行即可。

具體如下圖所示:

1.新建兩個(gè)文件(同名,不同后綴),編譯并運(yùn)行(需要多文件同時(shí)編譯)。

2.hs.c存放結(jié)構(gòu)體聲明及對應(yīng)的函數(shù)(這里面的函數(shù)還可以拆分成其他的文件,這里我就不拆分了)。

#include <stdio.h>
#include <stdlib.h>
struct student
{
?? ?int id;
?? ?float yw;
?? ?float sx;
?? ?float wy;
?? ?float pj;
};
int type(struct student *p)
{
?? ?int n=0;
?? ?printf("請輸入學(xué)生人數(shù):");
?? ?scanf("%d",&n);
?? ?putchar(10);
?? ?printf("請輸入學(xué)生三門課的成績:\n");
?? ?putchar(10);
?? ?printf("學(xué)號(hào) 語文 數(shù)學(xué) 外語\n");
?? ?for(int i=0;i<n;i++)
?? ?{
?? ??? ?printf("%d ? ?",i+1);
?? ??? ?struct student stu[i];
?? ??? ?scanf("%f %f %f",&(p+i)->yw,&(p+i)->sx,&(p+i)->wy);
?? ?}
?? ?putchar(10);
?? ?return n;
}
void list(struct student *p,int n)
{
?? ?printf("學(xué)生成績?nèi)缦拢篭n");
?? ?printf("學(xué)號(hào) 語文 數(shù)學(xué) 外語 平均分\n");
?? ?for(int i=0;i<n;i++)
?? ?{
?? ??? ?printf("%d ? ?",i+1);
?? ??? ?printf("%.1f %.1f %.1f %.1f",p->yw,p->sx,p->wy,p->pj);
?? ??? ?p++;
?? ??? ?putchar(10);
?? ?}
?? ?putchar(10);
}
void average(struct student *p,int n)
{
?? ?for(int i=0;i<n;i++)
?? ?{
?? ??? ?(p->pj)=((p->yw)+(p->sx)+(p->wy))/3;
?? ??? ?p++;
?? ?}
}
void help(void)
{
?? ?printf("**********************************\n");
?? ?printf(" * ?學(xué)生成績管理系統(tǒng)——幫助菜單 ?* \n");
?? ?printf("**********************************\n");
?? ?printf(" * ? H = 顯示幫助菜單 ? ? ? ? ? * \n");
?? ?printf(" * ? T = 成績錄入 ? ? ? ? ? ? ? * \n");
?? ?printf(" * ? A = 計(jì)算學(xué)生平均分 ? ? ? ? * \n");
?? ?printf(" * ? L = 列出成績單 ? ? ? ? ? ? * \n");
?? ?printf(" * ? P = 按平均成績由高到低排序 * \n");
?? ?printf(" * ? S = 按學(xué)號(hào)查詢學(xué)生成績 ? ? * \n");
?? ?printf(" * ? C = 清屏 ? ? ? ? ? ? ? ? ? * \n");
?? ?printf(" * ? Q =退出系統(tǒng) ? ? ? ? ? ? ? ?* \n");
?? ?printf("**********************************\n");
?? ?printf(" *Copyright(c) 2022.3.15 By liq* \n");
?? ?printf("**********************************\n");
}
void search(struct student *p)
{
?? ?int s=0;
?? ?printf("請輸入要查詢的學(xué)生號(hào):");
?? ?scanf("%d",&s);
?? ?putchar(10);
?? ?printf("學(xué)號(hào) 語文 數(shù)學(xué) 外語 平均分\n");
?? ?printf("%d ? %.1f ?%.1f ?%.1f ?%.1f",s,(p+s-1)->yw,(p+s-1)->sx,(p+s-1)->wy,(p+s-1)->pj);
?? ?putchar(10);
}
void sort(struct student *p,int n)
{
?? ?struct student temp;
?? ?int i,j;
?? ?for(i=0;i<n;i++)
?? ?{
?? ??? ?for(j=0;j<n-i-1;j++)
?? ??? ?{
?? ??? ??? ?if(p[j].pj<p[j+1].pj)
?? ??? ??? ?{
?? ??? ??? ??? ?temp=p[j];
?? ??? ??? ??? ?p[j]=p[j+1];
?? ??? ??? ??? ?p[j+1]=temp;
?? ??? ??? ?}
?? ??? ?}
?? ?}
?? ?printf("排序完成,請使用命令L查看!\n");
}

3.hs.h存放結(jié)構(gòu)體聲明以及hs.c里面函數(shù)對應(yīng)的函數(shù)聲明。

#include <stdio.h>
#include <stdlib.h>
struct student
{
?? ?int id;
?? ?float yw;
?? ?float sx;
?? ?float wy;
?? ?float pj;
};
int type(struct student *p);
void list(struct student *p,int n);
void average(struct student *p,int n);
void help(void);
void search(struct student *p);
void sort(struct student *p,int n);

4.main函數(shù)

#include <stdio.h>
#include <stdlib.h>
#include "hs.h"
int main(int argc, const char *argv[])
{
?? ?char ch;
?? ?struct student stu[32];
?? ?int n=0;
?? ?while(1)
?? ?{
?? ??? ?printf("請輸入命令 = ");
?? ??? ?scanf("%c",&ch);
?? ??? ?putchar(10);
?? ??? ?if(ch=='T')
?? ??? ?{
?? ??? ??? ?n=type(stu);
?? ??? ?}
?? ??? ?else if(ch=='L')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ??? ?list(stu,n);
?? ??? ?}
?? ??? ?else if(ch=='A')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?average(stu,n);
?? ??? ??? ??? ?printf("平均分已計(jì)算,請使用命令L查看!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(ch=='H')
?? ??? ??? ?help();
?? ??? ?else if(ch=='C')
?? ??? ??? ?system("clear");
?? ??? ?else if(ch=='S')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?search(stu);
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(ch=='P')
?? ??? ?{
?? ??? ??? ?if(n==0)
?? ??? ??? ?{
?? ??? ??? ??? ?printf("成績表為空!請先使用T錄入成績!\n");
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ??? ?else
?? ??? ??? ?{
?? ??? ??? ??? ?sort(stu,n);
?? ??? ??? ??? ?putchar(10);
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else if(ch=='Q')
?? ??? ?{
?? ??? ??? ?printf("Press any key to continue!\n");
?? ??? ??? ?return -1;
?? ??? ?}
?? ??? ?getchar();
?? ?}
?? ?return 0;
}

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論