溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

使用C語(yǔ)言怎么編寫(xiě)一個(gè)學(xué)生成績(jī)管理系統(tǒng)

發(fā)布時(shí)間:2020-12-22 13:57:27 來(lái)源:億速云 閱讀:309 作者:Leah 欄目:開(kāi)發(fā)技術(shù)

本篇文章給大家分享的是有關(guān)使用C語(yǔ)言怎么編寫(xiě)一個(gè)學(xué)生成績(jī)管理系統(tǒng),小編覺(jué)得挺實(shí)用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說(shuō),跟著小編一起來(lái)看看吧。

編程實(shí)現(xiàn)如下學(xué)生成績(jī)管理:

(1)錄入每個(gè)學(xué)生的學(xué)號(hào)和考試成績(jī);
(2)計(jì)算課程的總分和平均分;
(3)按成績(jī)由高到低排出名次表;
(4)按學(xué)號(hào)由小到大排出成績(jī)表;
(5)按學(xué)號(hào)查詢學(xué)生排名及其考試成績(jī);
(6)按優(yōu)秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5個(gè)類別,統(tǒng)計(jì)每個(gè)類別的人數(shù)以及所占的百分比;
(7)輸出每個(gè)學(xué)生的學(xué)號(hào)、考試成績(jī),以及課程總分和平均分。

輸入格式:

( 1 ) 錄入學(xué)生的人數(shù):

要求輸入數(shù)據(jù)格式為:"%d"
提示信息為:“Input student number(n<30):\n”

( 2 )錄入每個(gè)學(xué)生的學(xué)號(hào)和考試成績(jī):

要求輸入數(shù)據(jù)格式為:"%ld%f"
提示信息為:“Input student's ID and score:\n”

輸出格式:

1、菜單項(xiàng)的輸出顯示:

Management for Students' scores
1.Input record
2.Calculate total and average score of course
3.Sort in descending order by score
4.Sort in ascending order by number
5.Search by number
6.Statistic analysis
7.List record
0.Exit
Please Input your choice:

2、計(jì)算課程的總分和平均分:

要求輸出總分與平均分格式為:“sum=%.0f,aver=%.2f\n”

3、按成績(jī)由高到低排出名次表:

要求輸出格式為:"%ld\t%.0f\n"
提示信息為:“Sort in descending order by score:\n”

4、按學(xué)號(hào)由小到大排出成績(jī)表:

要求輸出格式為:"%ld\t%.0f\n"
提示信息為:“Sort in ascending order by number:\n”

5、按學(xué)號(hào)查詢學(xué)生信息及其考試成績(jī)(輸出學(xué)號(hào)與成績(jī)):

如果未查到此學(xué)號(hào)的學(xué)生,提示信息為:“Not found!\n”;
如果查詢到該學(xué)生,要求輸出格式為:"%ld\t%.0f\n"

6、按優(yōu)秀(90-100)、良好(80-89)、中等(70-79)、及格(60-69)、不及格(0-59)5個(gè)類別,統(tǒng)計(jì)每個(gè)類別的人數(shù)以及所占的百分比:
成績(jī)<60輸出提示格式為:"<60\t%d\t%.2f%%\n";
成績(jī)=100輸出格式為:"%d\t%d\t%.2f%%\n";
其他要求輸出百分比格式為:"%d-%d\t%d\t%.2f%%\n"

演示效果:

使用C語(yǔ)言怎么編寫(xiě)一個(gè)學(xué)生成績(jī)管理系統(tǒng)

使用C語(yǔ)言怎么編寫(xiě)一個(gè)學(xué)生成績(jī)管理系統(tǒng)

代碼:

#include<stdio.h>
#include<stdlib.h>
#include<conio.h>

//宏定義最大學(xué)生人數(shù)
#define stu_max 30

/*進(jìn)行函數(shù)的全局聲明*/

//獲取學(xué)生人數(shù)
int stu_num();
//顯示菜單獲取用戶輸入
char menu_tips();
//獲取學(xué)生學(xué)號(hào),及本門(mén)考試成績(jī)
void stu_information(long num[],float score[],int n);
//計(jì)算輸出課程的總分和平均分
void sum_aver(float score[],int n);
//模塊功能:交換兩個(gè)長(zhǎng)整型數(shù)據(jù)
void exchange_long(long *a,long *b);
//模塊功能:交換兩個(gè)浮點(diǎn)型數(shù)據(jù)
void exchange_float(float *a,float *b);
//按成績(jī)由高到低輸出名次表
void output_score(long num[],float score[],int n);
//按學(xué)號(hào)從小到大排出成績(jī)表
void output_num(long num[],float score[],int n);
//查詢輸出學(xué)生信息及考試成績(jī):
void query(long num[],float score[],int n);
//分?jǐn)?shù)劃界處理并輸出
void score_pro(float score[],int n);
//直接輸出對(duì)應(yīng)列表
void output(long num[],float score[],int n);
//暫停清屏
void clean();

int main()
{
 int n,i;
 long num[stu_max];
 float score[stu_max];
 n=stu_num();
 while(1)
 {
 i=menu_tips();
 switch(i)
 {
  case '1':printf("1"),stu_information(num,score,n),system("cls");break;
  case '2':printf("2"),sum_aver(score,n),clean();break;
  case '3':printf("3"),output_score(num,score,n),clean();break;
  case '4':printf("4"),output_num(num,score,n),clean();break;
  case '5':printf("5"),query(num,score,n),clean();break;
  case '6':printf("6"),score_pro(score,n),clean();break;
  case '7':printf("7"),output(num,score,n),clean();break;
  case '0':printf("0"),exit(0);break;
  default:printf("Input error!\n"),clean();
 }
 }
}

/*以下為函數(shù)功能模塊*/

//獲取學(xué)生人數(shù)
int stu_num()
{
 int n;
 printf("Input student number(n<30):\n");
 scanf("%d",&n);
 system("cls");
 return n;
}

//顯示菜單獲取用戶輸入
char menu_tips()
{
 printf(" -----------------------------------------------------------\n");
 printf("|  Management for Students' scores  |\n");
 printf(" -----------------------------------------------------------\n");
 printf("| 1.Input record     |\n");
 printf("| 2.Calculate total and average score of course |\n");
 printf("| 3.Sort in descending order by score   |\n");
 printf("| 4.Sort in ascending order by numbe   |\n");
 printf("| 5.Search by number     |\n");
 printf("| 6.Statistic analysis    |\n");
 printf("| 7.List record     |\n");
 printf("| 0.Exit      |\n");
 printf(" -----------------------------------------------------------\n");
 printf("\nPlease Input your choice:\n");
 char i;
 i=getch();
 return i;
}

//獲取學(xué)生學(xué)號(hào),及本門(mén)考試成績(jī)
void stu_information(long num[],float score[],int n)
{
 int i;
 printf("\nInput student's ID and score:\n");
 for(i=0;i<n;i++)
 scanf("%ld%f",&num[i],&score[i]);
}

//計(jì)算輸出課程的總分和平均分
void sum_aver(float score[],int n)
{
 int i;
 float sum,aver;
 for(i=0,sum=0;i<n;i++)
 sum+=score[i];
 aver=sum/n;
 printf("\nsum=%.0f,aver=%.2f\n",sum,aver);
}

//模塊功能:交換兩個(gè)長(zhǎng)整型數(shù)據(jù)
void exchange_long(long *a,long *b)
{
 long t;
 t=*a;
 *a=*b;
 *b=t;
}

//模塊功能:交換兩個(gè)浮點(diǎn)型數(shù)據(jù)
void exchange_float(float *a,float *b)
{
 float t;
 t=*a; *a=*b; *b=t;
}

//按成績(jī)由高到低輸出名次表
void output_score(long num[],float score[],int n)
{
 int i,j;
 for(j=n-1;j>0;j--)
 {
 for(i=0;i<j;i++)
  if(score[i]<score[i+1])
 {
  exchange_float(&score[i],&score[i+1]);
  exchange_long(&num[i],&num[i+1]);
 }
 }
 printf("\nSort in descending order by score:");
 output(num,score,n);
}

//按學(xué)號(hào)從小到大排出成績(jī)表
void output_num(long num[],float score[],int n)
{
 int i,j;
 for(j=n-1;j>0;j--)
 {
 for(i=0;i<j;i++)
  if(num[i]>num[i+1])
 {
  exchange_float(&score[i],&score[i+1]);
  exchange_long(&num[i],&num[i+1]);
 }
 }
 output(num,score,n);
}

//查詢輸出學(xué)生信息及考試成績(jī):
void query(long num[],float score[],int n)
{
 printf("\nEnter the ID to query:\n");
 long temp;
 scanf("%ld",&temp);
 int i;
 for(i=0;i<n;i++)
 {
 if(num[i]==temp)
 {
  printf("%ld\t%.0f\n",num[i],score[i]);
  return;
 }
 }
 printf("\nNot found!\n");
}

//分?jǐn)?shù)劃界處理并輸出
void score_pro(float score[],int n)
{
 int t[6]={0,0,0,0,0,0};
 /*前五個(gè)分別對(duì)應(yīng)優(yōu)秀、良好、中等、及格、不及格五個(gè)類別
 第六位存儲(chǔ)100分的人數(shù)*/
 int i,m;
 for(i=0;i<n;i++)
 {
 if(score[i]>=90&&score[i]<100) t[0]++;
 if(score[i]>=80&&score[i]<=89) t[1]++;
 if(score[i]>=70&&score[i]<=79) t[2]++;
 if(score[i]>=60&&score[i]<=69) t[3]++;
 if(score[i]>=0 &&score[i]<=59) t[4]++;
 if(score[i]==100)  t[5]++;
 }

 //遍歷t數(shù)組,輸出對(duì)應(yīng)的數(shù)據(jù)
 for(i=0,m=9;i<6;i++)
 {
 if(i==4)
  printf("<60\t%d\t%.2f%%\n",t[4],(float)t[4]/n*100);
 if(i==5)
  printf("%d\t%d\t%.2f%%\n",100,t[5],(float)t[5]/n*100);
 if(i!=4&&i!=5)
 {
  if(i==0)
  printf("\n");
  printf("%d-%d\t%d\t%.2f%%\n",m*10,m*10+9,t[i],(float)t[i]/n*100);
  m--;
 }
 }
}

//直接輸出對(duì)應(yīng)列表
void output(long num[],float score[],int n)
{
 int i;
 for(i=0;i<n;i++)
 {
 if(i==0)
  printf("\n");
 printf("%ld\t%.0f\n",num[i],score[i]);
 }
}

//暫停清屏
void clean()
{
 system("pause");
 system("cls");
}

以上就是使用C語(yǔ)言怎么編寫(xiě)一個(gè)學(xué)生成績(jī)管理系統(tǒng),小編相信有部分知識(shí)點(diǎn)可能是我們?nèi)粘9ぷ鲿?huì)見(jiàn)到或用到的。希望你能通過(guò)這篇文章學(xué)到更多知識(shí)。更多詳情敬請(qǐng)關(guān)注億速云行業(yè)資訊頻道。

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI