91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

C語言版學生成績管理系統

發布時間:2020-10-11 06:24:11 來源:腳本之家 閱讀:132 作者:isry 欄目:編程語言

本文實例為大家分享了C語言版學生成績管理系統的具體代碼,供大家參考,具體內容如下

#include<stdio.h> 
#include<stdlib.h> 
#include<time.h> 
#include<conio.h> 
#include<string.h> 
#include<algorithm> 
char buf[255]; 
char c=14; 
char path[]="D:\\data"; 
char tmp[]="D:\\tmp"; 
struct Student 
{ 
  char Name[20]; 
  char No[20]; 
  char Dept[20]; 
  char ClassNo[20]; 
  double Math,Chinese,English; 
  double Ave; 
  bool Pass; 
}students[500]; 
bool cmp1(Student s1,Student s2) 
{ 
  return s1.Chinese>s2.Chinese; 
} 
bool cmp2(Student s1,Student s2) 
{ 
  return s1.Math>s2.Math; 
} 
bool cmp3(Student s1,Student s2) 
{ 
  return s1.English>s2.English; 
} 
bool cmp4(Student s1,Student s2) 
{ 
  return s1.Ave>s2.Ave; 
} 
//---------------------------------------------------------void Sort(int cmd) 
/* 
1 ChineseSort 
2 MathSort 
3 EnglishSort 
4 AveSort 
*/ 
int Sort(int cmd) 
{ 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=0; 
  while((n=fread(&stu,sizeof(stu),1,fp)>0)) 
  { 
    students[cnt++]=stu; 
  } 
  fclose(fp); 
  switch(cmd) 
  { 
  case 1: 
  std::sort(students,students+cnt,cmp1); 
    break; 
  case 2: 
  std::sort(students,students+cnt,cmp2); 
    break; 
  case 3: 
  std::sort(students,students+cnt,cmp3); 
    break; 
  case 4: 
  std::sort(students,students+cnt,cmp4); 
    break; 
  default: 
    exit(0); 
  } 
  return cnt; 
} 
//---------------------------------------------------------PrintTitle() 
void PrintTitle() 
{ 
  printf("%-8s%-12s%-12s%-8s%-7s%-7s%-7s%-7s%-s\n","姓名","班級","學號","系院","語文","數學","英語","平均分","及格"); 
} 
//---------------------------------------------------------Print(Student stu) 
void Print(Student stu) 
{ 
  printf("%-8s%-12s%-12s%-8s%-7.2lf%-7.2lf%-7.2lf%-7.2lf%-s\n",stu.Name,stu.ClassNo,stu.No,stu.Dept,stu.Chinese,stu.Math,stu.English,stu.Ave,stu.Pass?"是":"否"); 
} 
//---------------------------------------------------------PrintNo(char No[]) 
void PrintNo(char No[]) 
{ 
  Student stu; 
  int n; 
  bool find=0; 
  FILE *fp=fopen(path,"ab+");//以ab+方式打開防止data文件不存在時發生錯誤 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  { 
    if(!strcmp(stu.No,No)) 
    { 
      find=1; 
      break; 
    } 
  } 
  fclose(fp); 
  if(find) 
  { 
    PrintTitle(); 
    Print(stu); 
  } 
  else 
    puts("未找到!"); 
} 
//---------------------------------------------------------PrintClass(char ClassNo[]) 
void PrintClass(char ClassNo[]) 
{ 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=0; 
  while((n=fread(&stu,sizeof(stu),1,fp)>0)) 
  { 
    if(!strcmp(stu.ClassNo,ClassNo)) 
    { 
      if(cnt==0) 
        PrintTitle(); 
      Print(stu); 
      cnt++; 
    } 
  } 
  fclose(fp); 
  if(cnt==0) 
    puts("無數據"); 
  else 
    printf("共%d條\n",cnt); 
} 
//---------------------------------------------------------PrintDept(char Dept[]) 
void PrintDept(char Dept[]) 
{ 
    Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=0; 
  while((n=fread(&stu,sizeof(stu),1,fp)>0)) 
  { 
    if(!strcmp(stu.Dept,Dept)) 
    { 
      if(cnt==0) 
        PrintTitle(); 
      Print(stu); 
      cnt++; 
    } 
  } 
  fclose(fp); 
  if(cnt==0) 
    puts("無數據"); 
  else 
    printf("共%d條\n",cnt); 
} 
//---------------------------------------------------------PrintAll() 
void PrintAll() 
{ 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=0; 
  while((n=fread(&stu,sizeof(stu),1,fp)>0)) 
  { 
    if(cnt==0) 
      PrintTitle(); 
    Print(stu); 
    cnt++; 
  } 
  fclose(fp); 
  if(cnt==0) 
    puts("無數據"); 
  else 
    printf("共%d條\n",cnt); 
} 
//---------------------------------------------------------Input() 
Student Input() 
{ 
  Student stu; 
  puts("請輸入姓名、班級、學號、系院:"); 
  scanf("%s%s%s%s",&stu.Name,&stu.ClassNo,&stu.No,&stu.Dept); 
  puts("請輸入各科成績:語文、數學、英語"); 
  scanf("%lf%lf%lf",&stu.Chinese,&stu.Math,&stu.English); 
  stu.Ave=(stu.Chinese+stu.Math+stu.English)/3; 
  if(stu.Chinese>=60&&stu.Math>=60&&stu.English>=60) 
    stu.Pass=1; 
  else 
    stu.Pass=0; 
  return stu; 
} 
//---------------------------------------------------------Insert() 
void Insert() 
{ 
  int cmd; 
  do{ 
    Student stu=Input(); 
    FILE *fp=fopen(path,"ab+"); 
    fwrite(&stu,sizeof(stu),1,fp); 
    fclose(fp); 
    puts("錄入成功"); 
    puts("繼續錄入嗎?[1]是[0]否"); 
    scanf("%d",&cmd); 
  }while(cmd==1); 
} 
//---------------------------------------------------------Del() 
void Del() 
{ 
  int cmd,cmd2; 
  char No[20]; 
  do{ 
  puts("請輸入要刪除的學號:"); 
  scanf("%s",&No); 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  FILE *fp2=fopen(tmp,"wb"); 
  int n,find=0; 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  { 
    if(!strcmp(stu.No,No)) 
    { 
      find=1; 
      Print(stu); 
      puts("確定要刪除嗎?[1]確定[0]取消"); 
      scanf("%d",&cmd2); 
      if(cmd2==1) 
        puts("已刪除"); 
      else 
        fwrite(&stu,sizeof(stu),1,fp2); 
    } 
    else 
    fwrite(&stu,sizeof(stu),1,fp2); 
  } 
  fclose(fp); 
  fclose(fp2); 
  if(find==0) 
  { 
    printf("未找到學號%s\n",No); 
    remove(tmp); 
  } 
  else 
  { 
    remove(path); 
    rename(tmp,path); 
  } 
  puts("繼續刪除嗎?[1]是[0]否"); 
  scanf("%d",&cmd); 
  }while(cmd==1); 
} 
//---------------------------------------------------------Change() 
void Change() 
{   
  int cmd; 
  char No[20]; 
  do{ 
  puts("請輸入要更改的學號:"); 
  scanf("%s",&No); 
  Student stu; 
  int find=0; 
  FILE *fp=fopen(path,"ab+"); 
  FILE *fp2=fopen(tmp,"wb"); 
  int n; 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  { 
    if(!strcmp(stu.No,No)) 
    { 
      find=1; 
      stu=Input(); 
      fwrite(&stu,sizeof(stu),1,fp2); 
    } 
    else 
      fwrite(&stu,sizeof(stu),1,fp2); 
  } 
  fclose(fp); 
  fclose(fp2); 
  if(find) 
  { 
    remove(path); 
    rename(tmp,path); 
    puts("更改成功!"); 
  } 
  else 
  { 
    printf("未找到學號%s\n",No); 
    remove(tmp); 
  } 
  puts("繼續更改嗎?[1]是[0]否"); 
  scanf("%d",&cmd); 
  }while(cmd==1); 
} 
//---------------------------------------------------------AboutCourse 
void Chinese() 
{ 
  double sum=0,ave; 
  int pass=0,fail=0,better=0; 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=Sort(1); 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  { 
    sum+=stu.Chinese; 
    if(stu.Chinese>=60) 
      { 
        pass++; 
        if(stu.Chinese>=80) 
          better++; 
      } 
    else 
      fail++; 
  } 
  ave=sum/cnt; 
  puts("語文成績分析……"); 
  printf("共有%d學生\n優秀:%d人\n及格:%d人\n不及格:%d人\n及格率:%.2lf%%\n",cnt,better,pass,fail,100.0*pass/cnt); 
  printf("%-8s%-10s%-12s%-s\n","名次","姓名","學號","語文"); 
  for(int i=0;i<cnt;i++) 
  { 
    printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].Chinese); 
  } 
  printf("平均分:%.2lf\n",ave); 
} 
void Math() 
{ 
  double sum=0,ave; 
  int pass=0,fail=0,better=0; 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=Sort(2); 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  { 
    sum+=stu.Math; 
    if(stu.Math>=60) 
      { 
        pass++; 
        if(stu.Math>=80) 
          better++; 
      } 
    else 
      fail++; 
  } 
  ave=sum/cnt; 
  puts("數學成績分析……"); 
  printf("共有%d學生\n優秀:%d人\n及格:%d人\n不及格:%d人\n及格率:%.2lf%%\n",cnt,better,pass,fail,100.0*pass/cnt); 
  printf("%-8s%-10s%-12s%-s\n","名次","姓名","學號","數學"); 
  for(int i=0;i<cnt;i++) 
  { 
    printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].Math); 
  } 
  printf("平均分:%.2lf\n",ave); 
} 
void English() 
{ 
  double sum=0,ave; 
  int pass=0,fail=0,better=0; 
  Student stu; 
  FILE *fp=fopen(path,"ab+"); 
  int n,cnt=Sort(3); 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  {   
    sum+=stu.English; 
    if(stu.English>=60) 
      { 
        pass++; 
        if(stu.English>=80) 
          better++; 
      } 
    else 
      fail++; 
  } 
  ave=sum/cnt; 
  puts("英語成績分析……"); 
  printf("共有%d學生\n優秀:%d人\n及格:%d人\n不及格:%d人\n及格率:%.2lf%%\n",cnt,better,pass,fail,100.0*pass/cnt); 
  printf("%-8s%-10s%-12s%-s\n","名次","姓名","學號","英語"); 
  for(int i=0;i<cnt;i++) 
  { 
    printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].English); 
  } 
  printf("平均分:%.2lf\n",ave); 
} 
void Average() 
{ 
  Student stu; 
  int n,cnt=Sort(4); 
  double sum=0; 
  FILE *fp=fopen(path,"ab+"); 
  while((n=fread(&stu,sizeof(stu),1,fp))>0) 
  {   
    sum+=stu.Chinese; 
    sum+=stu.Math; 
    sum+=stu.English; 
  } 
  puts("平均成績分析……"); 
  printf("%-8s%-10s%-12s%-s\n","名次","姓名","學號","平均成績"); 
  for(int i=0;i<cnt;i++) 
  { 
    printf("第%2d名 %-10s%-12s%-8.2lf\n",i+1,students[i].Name,students[i].No,students[i].Ave); 
  } 
  printf("平均分:%.2lf\n",sum/cnt/3); 
} 
//---------------------------------------------------------Search() 
void Search() 
{ 
  int cmd,cmd2; 
  while(1) 
  { 
    system("cls"); 
    puts("[1] 按學號查詢"); 
    puts("[2] 按班級查詢"); 
    puts("[3] 輸出全部"); 
    puts("[4] 按系別查詢"); 
    puts("[5] 課程分析"); 
    puts("[0] 返回主界面"); 
    scanf("%d",&cmd); 
    if(cmd==0) 
      break; 
    switch(cmd) 
    { 
    case 1: 
      { 
      char No[20]; 
      puts("請輸入要查詢的學號:"); 
      scanf("%s",&No); 
      PrintNo(No); 
      } 
      break; 
    case 2: 
      { 
        char ClassNo[20]; 
        puts("請輸入要查詢班級號:"); 
        scanf("%s",&ClassNo); 
        PrintClass(ClassNo); 
      } 
      break; 
    case 3: 
      PrintAll(); 
      break; 
    case 4: 
      { 
        char Dept[20]; 
        puts("請輸入要查詢的系別:"); 
        scanf("%s",&Dept); 
        PrintDept(Dept); 
      } 
      break; 
    case 5: 
      while(1) 
      { 
        puts("[1] 語文成績分析"); 
        puts("[2] 數學成績分析"); 
        puts("[3] 英語成績分析"); 
        puts("[4] 平均成績分析"); 
        puts("[0] 返回上一級"); 
        scanf("%d",&cmd2); 
        if(cmd2==0) 
          break; 
        switch(cmd2) 
        { 
        case 1: 
          Chinese(); 
          break; 
        case 2: 
          Math(); 
          break; 
        case 3: 
          English(); 
          break; 
        case 4: 
          Average(); 
          break; 
        default: 
          puts("不合法指令!"); 
        } 
      } 
      break; 
    default: 
      puts("不合法指令!"); 
    } 
    while(1) 
    { 
      puts("[0] 返回"); 
      puts("[1] 錄入"); 
      puts("[2] 刪除"); 
      puts("[3] 修改"); 
      scanf("%d",&cmd2); 
      if(cmd2==0) 
        break; 
      switch(cmd2) 
      { 
      case 1: 
        Insert(); 
          break; 
      case 2: 
        Del(); 
        break; 
      case 3: 
        Change(); 
        break; 
      default: 
        puts("不合法指令!"); 
      } 
    } 
  } 
} 
//---------------------------------------------------------Menu() 
void ShowMenu1() 
{   
  int i; 
  puts(""); 
  printf("         "); 
  for(i=0;i<14;i++) 
    putchar(c); 
  printf("成績管理分析系統"); 
  for(i=0;i<14;i++) 
    putchar(c); 
  puts(""); 
  printf("        %c                       %c\n",c,c); 
  printf("         %c        請輸入指令        %c\n",c,c); 
  printf("        %c                       %c\n",c,c); 
  printf("         %c        [0] 退出         %c\n",c,c); 
  printf("        %c                       %c\n",c,c); 
  printf("         %c        [1] 錄入         %c\n",c,c); 
  printf("        %c                       %c\n",c,c); 
  printf("         %c        [2] 刪除         %c\n",c,c); 
  printf("        %c                       %c\n",c,c); 
  printf("         %c        [3] 查詢         %c\n",c,c); 
  printf("        %c                       %c\n",c,c); 
  printf("         %c        [4] 更改         %c\n",c,c); 
  printf("        %c                       %c\n",c,c); 
  printf("         "); 
  for(i=0;i<44;i++) 
    putchar(c); 
  puts(""); 
} 
void ShowMenu2() 
{   
  int i; 
  puts(""); 
  printf("         "); 
  for(i=0;i<14;i++) 
    putchar(c); 
  printf("成績管理分析系統"); 
  for(i=0;i<14;i++) 
    putchar(c); 
  puts(""); 
  printf("         %c                     %c\n",c,c); 
  printf("        %c         請輸入指令         %c\n",c,c); 
  printf("         %c                     %c\n",c,c); 
  printf("        %c         [0] 退出          %c\n",c,c); 
  printf("         %c                     %c\n",c,c); 
  printf("        %c         [1] 錄入          %c\n",c,c); 
  printf("         %c                     %c\n",c,c); 
  printf("        %c         [2] 刪除          %c\n",c,c); 
  printf("         %c                     %c\n",c,c); 
  printf("        %c         [3] 查詢          %c\n",c,c); 
  printf("         %c                     %c\n",c,c); 
  printf("        %c         [4] 更改          %c\n",c,c); 
  printf("         %c                     %c\n",c,c); 
  printf("         "); 
  for(i=0;i<44;i++) 
    putchar(c); 
  puts(""); 
} 
//---------------------------------------------------------void RandColor() 
void RandColor() 
{ 
  int a,b; 
  char param[20]="color ",param2[10]; 
  do{ 
    a=rand()%16; 
    b=rand()%16; 
  }while(a==b); 
  sprintf(param2,"%x%x",a,b); 
  strcat(param,param2); 
  system(param); 
} 
//---------------------------------------------------------main() 
int main() 
{ 
  int cmd; 
  srand(time(NULL)); 
  for(int i=0;i<8;i++) 
  { 
  RandColor(); 
  system("cls"); 
  ShowMenu1(); 
  system("cls"); 
  ShowMenu2(); 
  } 
  system("color 0a"); 
  while(1) 
  { 
    system("cls"); 
    ShowMenu1(); 
    printf("[ ]\b\b"); 
    scanf("%d",&cmd); 
    if(cmd==0) 
      break; 
    switch(cmd) 
    { 
    case 1: 
      Insert(); 
      break; 
    case 2: 
      Del(); 
      break; 
    case 3: 
      Search(); 
      break; 
    case 4: 
      Change(); 
      break; 
    default: 
      puts("命令不合法!"); 
    } 
  } 
  return 0; 
} 

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

永昌县| 宿州市| 临清市| 资兴市| 合川市| 巫山县| 吉安市| 浦东新区| 通榆县| 溆浦县| 蓬莱市| 杭锦旗| 卓尼县| 蚌埠市| 田东县| 基隆市| 桐柏县| 子长县| 九寨沟县| 许昌县| 台南县| 晋州市| 芦山县| 富川| 蒲城县| 黄龙县| 新邵县| 兴业县| 金川县| 盐边县| 沭阳县| 满洲里市| 和硕县| 濮阳县| 颍上县| 晋中市| 乌兰浩特市| 城固县| 金湖县| 和静县| 宁武县|