最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

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

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

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

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

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

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

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

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

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

輸入3號學(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ù)計算平均分,提示“平均分已計算。請使用命令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é)號”。

輸入2 找到2號學(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ù)組元素時,要將學(xué)號單獨處理,輸出為整數(shù)(即保留0位小數(shù))。同理,在計算成績時也要將第1列的學(xué)號撇開,只計算第2列之后的。成績保留1位小數(shù)。
2)學(xué)生人數(shù)n貫穿始終,通過n的值判斷當前命令的子函數(shù)是否能夠調(diào)用執(zhí)行。例如:當n=0時,說明還沒有錄入成績。而一旦輸入命令T,也即調(diào)用Type子函數(shù)錄入了成績,則n的值就不再是0。當n!=0時,就可以進行其他的成績操作,但不能再執(zhí)行錄用成績的操作。所以當用戶輸入的命令無法執(zhí)行時,應(yī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("平均分已計算,請使用命令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é)號 語文 數(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é)號 語文 數(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 = 計算學(xué)生平均分 ? ? ? ? * \n");
?? ?printf(" * ? L = 列出成績單 ? ? ? ? ? ? * \n");
?? ?printf(" * ? P = 按平均成績由高到低排序 * \n");
?? ?printf(" * ? S = 按學(xué)號查詢學(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é)生號:");
?? ?scanf("%d",&s);
?? ?printf("學(xué)號 語文 數(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ù)部分拿出來,新建兩個個文件: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”(雙引號,不是<>)。
編譯的時候需要將主函數(shù)以及新建的fun.c文件一起編譯,運行還是同之前一樣,用./a.out運行即可。

具體如下圖所示:

1.新建兩個文件(同名,不同后綴),編譯并運行(需要多文件同時編譯)。

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é)號 語文 數(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é)號 語文 數(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 = 計算學(xué)生平均分 ? ? ? ? * \n");
?? ?printf(" * ? L = 列出成績單 ? ? ? ? ? ? * \n");
?? ?printf(" * ? P = 按平均成績由高到低排序 * \n");
?? ?printf(" * ? S = 按學(xué)號查詢學(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é)生號:");
?? ?scanf("%d",&s);
?? ?putchar(10);
?? ?printf("學(xué)號 語文 數(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("平均分已計算,請使用命令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)文章

  • C語言實現(xiàn)密碼本

    C語言實現(xiàn)密碼本

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)密碼本,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2020-02-02
  • C++?哈希表的基本用法及說明

    C++?哈希表的基本用法及說明

    這篇文章主要介紹了C++?哈希表的基本用法及說明,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • C語言實現(xiàn)24點游戲源代碼

    C語言實現(xiàn)24點游戲源代碼

    這篇文章主要為大家詳細介紹了C語言實現(xiàn)24點游戲源代碼,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-10-10
  • C++游戲教程基本技巧之隨機化詳解

    C++游戲教程基本技巧之隨機化詳解

    在小游戲的制作中時常常會要用到隨機數(shù),這篇文章就來和大家談?wù)凜++中這個所謂的“隨機”。文中的示例代碼講解詳細,感興趣的小伙伴可以了解一下
    2022-11-11
  • 利用Matlab實現(xiàn)迭代適應(yīng)點算法

    利用Matlab實現(xiàn)迭代適應(yīng)點算法

    道格拉斯-普克算法(Douglas–Peucker?algorithm,亦稱為拉默-道格拉斯-普克算法、迭代適應(yīng)點算法、分裂與合并算法)是將曲線近似表示為一系列點,并減少點的數(shù)量的一種算法。本文將利用Matlab實現(xiàn)這一算法,需要的可以參考一下
    2022-04-04
  • C語言中g(shù)etchar和putchar的使用方法詳解

    C語言中g(shù)etchar和putchar的使用方法詳解

    我們知道scanf函數(shù)可以從鍵盤輸入信息,而printf則可以輸出信息,同樣地,getchar和putchar也有同樣的功能,下面我來給大家介紹putchar和getchar的使用方法,需要的朋友可以參考下
    2023-08-08
  • C語言小程序 如何判斷三角型類型

    C語言小程序 如何判斷三角型類型

    第一個判斷三角形的類型,兩個浮點型數(shù)據(jù)不能直接判斷相等,為了輸入方便一些,自己設(shè)置的精度比較低,10^(-3)
    2013-07-07
  • Windows程序內(nèi)部運行機制實例詳解

    Windows程序內(nèi)部運行機制實例詳解

    這篇文章主要介紹了Windows程序內(nèi)部運行機制實例詳解,對于學(xué)習(xí)Windows程序設(shè)計來說是非常重要的一課,需要的朋友可以參考下
    2014-08-08
  • Linux中使用C語言的fork()函數(shù)創(chuàng)建子進程的實例教程

    Linux中使用C語言的fork()函數(shù)創(chuàng)建子進程的實例教程

    fork是一個在Linux系統(tǒng)環(huán)境下專有的函數(shù),現(xiàn)有的進程調(diào)用fork后將會創(chuàng)建一個新的進程,這里我們就來看一下Linux中使用C語言的fork()函數(shù)創(chuàng)建子進程的實例教程
    2016-06-06
  • C/C++ 讀取16進制文件的方法

    C/C++ 讀取16進制文件的方法

    下面小編就為大家?guī)硪黄狢/C++ 讀取16進制文件的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2016-12-12

最新評論

蕲春县| 双桥区| 阜南县| 武平县| 高要市| 临颍县| 崇礼县| 武强县| 隆安县| 广丰县| 华亭县| 阆中市| 探索| 汨罗市| 保亭| 渑池县| 吴江市| 吴川市| 阆中市| 温泉县| 阳泉市| 启东市| 柯坪县| 基隆市| 千阳县| 西吉县| 永德县| 离岛区| 蓬溪县| 小金县| 宜昌市| 安义县| 锡林郭勒盟| 涿州市| 宝坻区| 禄劝| 龙南县| 嘉荫县| 南郑县| 天峻县| 北碚区|