| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2509 人关注过本帖
标题:用C写的学生管理系统,比较简单
只看楼主 加入收藏
仅有的温存
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-9
收藏
得分:0 
为什么录入学生成绩信息后  进入了无限循环 无法退出 保存哎, ,
2013-07-01 14:37
仅有的温存
Rank: 1
等 级:新手上路
帖 子:3
专家分:0
注 册:2013-4-9
收藏
得分:0 
回复 16楼 aKARL
你们课程设计也是这?
2013-07-01 14:39
aKARL
Rank: 1
等 级:新手上路
帖 子:36
专家分:6
注 册:2013-7-1
收藏
得分:0 
回复 22楼 仅有的温存
设计学生系统,不过用的TC无法存在汉字,我给楼主的给改了,有个问题就是录入后,统计界面无法查看
2013-07-01 14:41
aKARL
Rank: 1
等 级:新手上路
帖 子:36
专家分:6
注 册:2013-7-1
收藏
得分:0 
回复 23楼 aKARL
#include "stdio.h"
#include "conio.h"
#include "string.h"
#include "stdlib.h"
#define CMD_START printf ("   <<<======================= start =========================>>>\n");
#define CMD_END  printf ("   <<<======================= end =========================>>>\n");
#define  DATA_FILE "data.dat"
#define TEMP_FILE  "temp.dat"

typedef struct tagStudent
{
char ID[30];
char Name[30];
char Class[255];
char Sex;
int Math;  
int English;
int Compute;
int Philosophy;
int  PE;
struct tagStudent *next;
} Student;
int ShowMenu();
int WriteData(FILE* , Student* );
void Output_Rec(Student*);
void Input_Rec(Student*);
void CopyRec(Student* , Student* );
void Print();
void Add();  
void Delete();
void Statistics();
void Find(int);
int quit;
main()
{
int cmd;
quit = 0;
while( ! quit )
{
  cmd = ShowMenu();
  CMD_START
  switch( cmd )
  {
     case 1:
    Print();getch();break;
     case 2:
    Add(); getch();break;
     case 3:
    Delete();getch();break;
     case 4:
    Statistics();getch();break;
     case 5:
    Find(5);getch();break;
     case 6:
    Find(6);getch();break;
     case 7:
    quit = 1;
    getch();break;
     default:
    printf(" input digit \n");
    printf ("   <<<======================== end ==========================>>>\n");
    getch();break;
  }
  CMD_END
  system("cls");
  if (quit != 1)
  {
   printf(" Menu(click) ....\n");
   getch();
  }
}
}
int ShowMenu()
{
int cmd = 0;
char Menu_SeeData[]  = "\t1 .\tView the Records in the data file\n";
char Menu_Add[]   = "\t2 .\tAdd New Record\n";
char Menu_Delete[]  = "\t3 .\tDelete an old Record\n";
char Menu_Statistics[]  = "\t4 .\tMake a Statistics\n";
char Menu_Find_ID[]  = "\t5 .\tFind a Record from the ID\n";
char Menu_Find_Name[] = "\t6 .\tFind a Record from the Name\n";
char Menu_Quit[]  = "\t7 .\tQuit\n";
system("COLOR e");
system("cls");
printf ("\n       *                    start                      * \n");
printf ("\n      *                                                                *\n");
printf ("   <<<============================= * ==================================>>>\n");
printf ("      >\t\t\t       1.Student information      \t\t\t<\n");
printf ("      >\t\t\t       2.Write to student information     \t\t\t<\n");
printf ("      >\t\t\t       3.Delete student information      \t\t\t<\n");
printf ("      >\t\t\t       4.Student achievement      \t\t\t<\n");
printf ("      >\t\t\t       5.Student id        \t\t\t<\n");
printf ("      >\t\t\t       6.Student name        \t\t\t<\n");
printf ("      >\t\t\t       7.Break         \t\t\t<\n\n");
printf ("    <<----------------------------- * ---------------------------------->>\n");
printf("\n\n\tinput digit:");
scanf("%d" , &cmd);
printf("\n");
system("cls");
return cmd;
}
void Print()
{
FILE* fp = NULL;
Student rec;
int i = 0;
fp = fopen(DATA_FILE , "rb");
if(fp == NULL)
{
  printf(" open error %s\n" , DATA_FILE);
  getch();
  return ;
}
while(ReadData(fp , &rec))
{
  Output_Rec(&rec);
  printf(" ---------------------------------------------------------------\n");
  i++;
  if(i>1 && i % 3 == 0)
  {
   printf("\n end(click) ... \n");
   getch();
  }
}
printf("\nHave\t%d\tInformation .\n" , i );
fclose(fp);
system("pause");
}
void Add()
{
Student rec;
FILE* fp = NULL;
char a;
Input_Rec( &rec );
fp = fopen(DATA_FILE ,"ab");
if( fp == NULL)
{
  printf(" Open Error \n");
  return ;
}
if( WriteData(fp, &rec) == 1)
  printf("\n\nOK\n\n");
else
  printf("\n\n Open Error \n");
  printf("GO ON?:y/n\n");
  scanf("%c",&a);
  scanf("%c",&a);
  if(a=='N' || a=='n')
  {
      fclose(fp);
      system("cls");
      ShowMenu();
  }
  else
  Add();
}
void Delete()
{
Student rec;
FILE* fpr,*fpw;
char buf[30];
char cmd[255];
char num1;
int del_count;
del_count = 0;
printf("\n Delete Student ID: .");
printf("\n ID : ");
scanf("%s" , buf);
fpr = fopen(DATA_FILE ,"rb");
 while(ReadData(fpr ,&rec))
  {
   if(strcmp(rec.ID , buf) == 0)
   {
    del_count++;
    Output_Rec(&rec);
    printf(" ---------------------------------------------------------------\n");
   }
  }
 printf("Are you sure?Y/N\n");
 scanf("%c",&num1);
 scanf("%c",&num1);
 if(num1=='N' || num1=='n')
{
system("cls");
ShowMenu();
}

if( fpr == NULL)
{
  printf(" Open Error ... \n");
  return ;
}
fpw = fopen(TEMP_FILE,"wb");
if( fpw == NULL)
{
  printf(" Open Error \n");
  return ;
}
while(ReadData(fpr , &rec))
{
  if(strcmp(rec.ID , buf) != 0)
  {
   WriteData(fpw, &rec);
  }
  else
  {
   del_count++;
  }
}
fclose(fpr);
fclose(fpw);
strcpy(cmd , "del ");
strcat(cmd ,DATA_FILE);
system(cmd);
rename(TEMP_FILE,DATA_FILE);
printf("\n\t%dInformation have delete \n",del_count);
system("pause");

}
void Statistics()
{
int i50,i60,i70,i80,i90;
float avg;
int sum ,sum_high,sum_low;
Student stu_high,stu_low;
Student stu_math_high,stu_english_high;
Student stu_compute_high,stu_philosophy_high,stu_PE_high;
Student stu_math_low,stu_english_low;
Student stu_compute_low, stu_philosophy_low,stu_PE_low;
FILE* fp;
Student rec;
int count;
count = sum = sum_high = sum_low = i50 = i60 = i60 = i70 =i80 = i90 = 0;
fp = NULL;
fp = fopen(DATA_FILE ,"rb");
if(fp == NULL)
{
  printf("\nRead Error \n");
  return;
}
while(ReadData(fp , &rec))
{
  count++;
  sum = rec.Math + rec.English + + rec.PE+ rec.Philosophy;

  avg = ((float)sum) / 5;
  if(avg < 60)
   i50++;
  else if(avg <70)
   i60++;
  else if(avg < 80)
   i70++;
  else if(avg < 90)
   i80++;
  else
   i90++;
  if(count <= 1)
  {
   sum_high = sum_low = sum;
   CopyRec(&stu_high , &rec);
   CopyRec(&stu_low ,&rec);
  }
  else
  {
   if(sum > sum_high)
   {
    sum_high = sum;
    CopyRec(&stu_high , &rec);
   }
   if(sum < sum_low)
   {
    sum_low = sum;
    CopyRec(&stu_low , &rec);
   }
  }
  if(count == 1)
  {
   CopyRec(&stu_math_high,&rec);
   CopyRec(&stu_english_high , &rec);
   CopyRec(&stu_compute_high, &rec);
   CopyRec(&stu_philosophy_high,&rec);
   CopyRec(&stu_PE_high , &rec);
   CopyRec(&stu_math_low,&rec);
   CopyRec(&stu_english_low , &rec);
   CopyRec(&stu_compute_low, &rec);
   CopyRec(&stu_philosophy_low,&rec);
   CopyRec(&stu_PE_low , &rec);
  }
  else
  {
   if(rec.Math > stu_math_high.Math)
    CopyRec(&stu_math_high ,&rec);
   if(rec.English > stu_english_high.English)
    CopyRec(&stu_english_high ,&rec);
   if( > stu_compute_)
    CopyRec(&stu_compute_high , &rec);
   if(rec.Philosophy > stu_philosophy_high.Philosophy)
    CopyRec(&stu_philosophy_high , &rec);
   if(rec.PE > stu_PE_high.PE)
    CopyRec(&stu_PE_high , &rec);
   if(rec.Math < stu_math_low.Math)
    CopyRec(&stu_math_low ,&rec);
   if(rec.English < stu_english_low.English)
    CopyRec(&stu_english_low ,&rec);
   if( < stu_compute_)
    CopyRec(&stu_compute_low , &rec);
   if(rec.Philosophy < stu_philosophy_low.Philosophy)
    CopyRec(&stu_philosophy_low , &rec);
   if(rec.PE < stu_PE_low.PE)
    CopyRec(&stu_PE_low , &rec);
  }
}
if(count < 1)
{
  printf("\n NO RECORD \n");
}
else
{
  printf("\n section distribute:\n");
  printf("\t    <  60\t:\t%d\n",i50);
  printf("\t60  -  69\t:\t%d\n",i60);
  printf("\t70  -  79\t:\t%d\n",i70);
  printf("\t80  -  90\t:\t%d\n",i80);
  printf("\t   >=  90\t:\t%d\n",i90);
  printf(" ---------------------------------------------------------------\n");
  system("pause");
  printf("\n High Student\n");
  printf(" Score: %d\n" , sum_high);
  printf(" Student :\n");
  Output_Rec(&stu_high);
  printf("\n Low Student\n");
  printf(" Score : %d\n" , sum_low);
  printf(" Student :\n");
  Output_Rec(&stu_low);
  printf(" ---------------------------------------------------------------\n");
  printf(" Math High:\n");
  Output_Rec(&stu_math_high);
  printf(" Math Low :\n");
  Output_Rec(&stu_math_low);
  printf(" ---------------------------------------------------------------\n");
  printf(" English High :\n");
  Output_Rec(&stu_english_high);
  printf(" English Low :\n");
  Output_Rec(&stu_english_low);
  printf(" ---------------------------------------------------------------\n");
  printf(" Compute High :\n");
  Output_Rec(&stu_compute_high);
  printf(" Compute Low :\n");
  Output_Rec(&stu_compute_low);
  printf(" ---------------------------------------------------------------\n");
  printf(" Philosophy High :\n");
  Output_Rec(&stu_philosophy_high);
  printf(" Philosophy Low :\n");
  Output_Rec(&stu_philosophy_low);
  printf(" ---------------------------------------------------------------\n");
  printf(" Pe High :\n");
  Output_Rec(&stu_PE_high);
  printf(" Pe Low :\n");
  Output_Rec(&stu_PE_low);
  printf(" ---------------------------------------------------------------\n");
  system("pause");
}
fclose(fp);
}
void Find(int isFind_From_ID)
{
char buf[30];
Student rec;
int find_count;
FILE* fp;
find_count = 0;
fp = fopen(DATA_FILE ,"rb");
if( fp == NULL)
{
  printf("\n open error ...\n");
  return;
}
switch(isFind_From_ID)
{
case 5:
  printf("\n writr student id: ");
  scanf("%s",buf);
  while(ReadData(fp ,&rec))
  {
   if(strcmp(rec.ID , buf) == 0)
   {
    find_count++;
    Output_Rec(&rec);
    printf(" ------------------------------------------------------\n");
   }
  }
  getch();
  break;
case 6:
  printf("\n writr student id : ");
  scanf("%s",buf);
  while(ReadData(fp , &rec))
  {
   if(strcmp(rec.Name, buf) >=0)
   {
    find_count++;
    Output_Rec(&rec);
    printf(" -----------------------------------------------------\n");
   }
  }
  getch();
  break;
default:
  printf(" \n pleace ...\n");
}
if(find_count >0)
{
  printf("\n have\t%d\t information\n",find_count);
}
else
{
  printf("\n sorry\n NO have \n");
  printf("\n Suggest to use keywords \n");
}
fclose(fp);
}
int ReadData(FILE* fp, Student* Dest_Rec)
{
int r;
if(( fp == NULL ) || ( Dest_Rec == NULL))
  return 0;
r = fread(Dest_Rec ,sizeof(Student) ,1 ,fp);
if(r != 1)
  return 0;
 return 1;
}
int WriteData(FILE* fp, Student* Src_Rec)
{
int r;
if((fp == NULL) || (Src_Rec == NULL))
  return 0;
r = fwrite(Src_Rec , sizeof(Student) , 1, fp);
if(r != 1)
  return 0;
return 1;
}
void Output_Rec( Student* stu)
{
 printf("\n");
 printf("  Name : %s", stu->Name);
 printf("\n  Sex : ");
if( stu->Sex == 'M' || stu->Sex == 'm' )
 printf("Male");
else
 printf("Female");
 printf("  ID : %s\t\tClass : %s\n",stu->ID,stu->Class);
 printf("  Math = %d\t\tEnglish = %d\t\tCompute =%d\n" ,stu->Math ,stu->English, stu->Compute);
 printf("  Philosophy = %d\t\tPE = %d\n", stu->Philosophy ,stu->PE);
 printf("\n");
}
void Input_Rec( Student* stu)
{
if(stu == NULL)
  return;
printf("\n Name = ");
scanf("%s",stu->Name);
printf("\tSex = (F|M) ");
while(1)
{
  stu->Sex = getch();
  if(stu->Sex == 'F' || stu->Sex == 'f' || stu->Sex == 'M' || stu->Sex == 'm')
  {
   printf("%c",stu->Sex);
   break;
  }
}
printf("\n ID = ");
scanf("%s" , stu->ID);
printf("\n Class = ");
scanf("%s" , stu->Class);
printf("\n Math = ");
scanf("%d", &(stu->Math));
printf("\n English = ");
scanf("%d" ,&(stu->English));
printf("\n Compute = ");
scanf("%d" , &(stu->Compute));
printf("\n Philosophy = ");
scanf("%d" , &(stu->Philosophy));
printf("\n PE = ");
scanf("%d" , &(stu->PE));
printf("\n");

}
void CopyRec(Student* dest_stu, Student* src_stu)
{
strcpy(dest_stu->Name ,src_stu->Name);
strcpy(dest_stu->ID ,src_stu->ID);
strcpy(dest_stu->Class ,src_stu->Class);
dest_stu->Sex = src_stu->Sex;
dest_stu->Math = src_stu->Math;
dest_stu->English = src_stu->English;
dest_stu->Compute = src_stu->Compute;
dest_stu->Philosophy = src_stu->Philosophy;
dest_stu->PE = src_stu->PE;
}
2013-07-01 14:42
aKARL
Rank: 1
等 级:新手上路
帖 子:36
专家分:6
注 册:2013-7-1
收藏
得分:0 
回复 22楼 仅有的温存
怎么弄啊,求救啊,统计只能看到最下方的PE,向上就会跳回MENU,你怎么整的
2013-07-01 14:44
长歌、
Rank: 2
来 自:河南省济源市
等 级:论坛游民
帖 子:10
专家分:16
注 册:2013-7-1
收藏
得分:0 
楼主 怎么才能使用多文件方式实现设计.
怎么建立头文件?
2013-07-02 10:54
止笺
Rank: 2
等 级:论坛游民
帖 子:15
专家分:19
注 册:2013-6-28
收藏
得分:0 
看了,有点复杂。。。
2013-07-03 22:42
cooble
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2013-7-5
收藏
得分:0 
   好长的程序哦 ,如果做成软件界面的更安逸。
2013-07-05 17:18
NothingHelp
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2013-7-6
收藏
得分:0 
下来看看
2013-07-06 11:04
AlexXu
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2012-9-27
收藏
得分:0 
回复 21楼 仅有的温存
不好意思啦,因为这只是之前的草稿,没有上传最终的版本,之前也没有注意到上传错了文件,不过没关系吧?反正重要的是知道思想就行了,代码实现的只是很简单的事。。。
2013-07-23 13:28
快速回复:用C写的学生管理系统,比较简单
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.031487 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved