當前位置:首頁 » 編程語言 » c語言成績管理

c語言成績管理

發布時間: 2022-03-14 10:27:18

c語言 成績管理程序

#include<stdio.h>
#include <string.h>

#define Num_score 6 // 此處為6門的成績
#define Num_stu 3 // 此處為3個學生 可自己修改個數

#define score_H 90 //用於成績篩選
#define score_L 60
typedef struct
{
int id; //編號
char name[30]; //姓名
char gender[10]; //性別
float sc[Num_score]; //存儲Num_score門課的分數
float sum; //總成績
} stu;

int main()
{
stu s[Num_stu];
int i,j;
for(i = 0; i < Num_stu; i++)
{
printf("請輸入學生學號\n");
scanf("%d", &s[i].id);
printf("請輸入姓名\n");
scanf("%s",s[i].name);
printf("請輸入性別\n");
scanf("%s",s[i].gender);
printf("請輸入%d門課的成績\n",Num_score);
for(j = 0; j < Num_score; j++)
scanf("%f",&s[i].sc[j]);
s[i].sum = 0; //計算成績總和;
for(int k = 0 ; k < Num_score; k++)
s[i].sum = s[i].sum + s[i].sc[k];
// s[i].ave = s[i].sum / Num_score; //平均成績
}
for(i = 0; i < Num_stu; i++)
{
printf("學號%d的同學%s(%s)的總分為:%.2f \n",s[i].id, s[i].name,s[i].gender,s[i].sum);
for (j = 0; j < Num_score; j++)
{
printf("第%d門成績為:%.2f \n", j + 1, s[i].sc[j]);
}
}
//按總成績升序排列
stu stu_temp;
for (i = 1; i < Num_stu; i++)
{
for (j = 0; j < Num_stu - i; j++)
{
if (s[j].sum > s[j + 1].sum)
{
stu_temp = s[j];
s[j] = s[j + 1];
s[j + 1] = stu_temp;
}
}
}
//output
printf("按總成績排序後:\n");
for(i = 0; i < Num_stu; i++)
{
printf("學號%d的同學%s(%s)的總分為:%.2f \n",s[i].id, s[i].name,s[i].gender,s[i].sum);
for (j = 0; j < Num_score; j++)
{
printf("第%d門成績為:%.2f \n", j + 1, s[i].sc[j]);
}
}

// 成績查詢
int sid;
printf("請輸入學號進行查詢:\n");
scanf("%d",&sid);

int flag = 0;
for (i = 0; i < Num_stu; i++)
{
if (sid == s[i].id)
{
flag = 1;
for (j = 0; j < Num_score; j++)
{
printf("%s同學第 %d 門課程成績為:%.2f \n", s[i].name, j + 1, s[i].sc[j]);
}
printf("該同學的總分為:%.2f \n",s[i].sum);
break;
}
}
if (flag == 0)
{
printf("你輸入的信息有誤\n");
}

//成績篩選 >90 || < 60
for (i = 0 ; i < Num_score; i++)
{
printf("第%d門成績高於%d的同學\n", i + 1, score_H);
for (j = 0; j < Num_stu; j++)
{
if (s[j].sc[i] > score_H)
{
printf("%s %.2f \n", s[j].name, s[j].sc[i]);
}
}
}
for (i = 0; i < Num_score; i++)
{
printf("第%d門成績低於%d的同學\n", i + 1, score_L);
for (j = 0; j < Num_stu; j++)
{
if (s[j].sc[i] < score_L)
{
printf("%s %.2f \n", s[j].name, s[j].sc[i]);
}
}
}

return 0;
}

⑵ C語言成績管理系統

給你調試了一下,有些地方已經修改。
#include "stdio.h"
void sort(int m,float x[]);
float max (int m,float y[]);
float min (int m,float z[]);
main()
{
printf("********成績管理系統********\n");
printf("(可以輸入要求管理的學生人數自定)\n");
char string[20];
int i,j,k,a,b;
float math[4],chinese[4],english[4],sum[4],average[4],max1,max2,max3,min1,min2,min3;
for (i=0;i<3;i++)
{
printf("請輸入名字");
scanf("%s",string[i+1]); //string沒定義
printf("請輸入數學成績");
scanf("%d\n",&math[i+1]);
printf("請輸入語文成績");
scanf("%d\n",&chinese[i+1]);
printf("請輸入英語成績");
scanf("%d\n",&english[i+1]);
sum[i+1]=math[i+1]+chinese[i+1]+english[i+1]; //不同類型
average[i+1]=sum[i+1]/3;
}
printf("各科的最高分與最低分");
printf("數學 語文 英語");
sort(3,sum);
max1=max(3,math);
printf("%d\t",max1);
max2=max(3,chinese);
printf("%d\t",max2);
max3=max(3,english);
printf("%d\n",max3);
min1=min(3,math);
printf("%d\t",min1);
min2=min(3,chinese);
printf("%d\t",min2);
min3=min(3,english);
printf("%d\n",min3);
printf("輸出各科平均分");
for (a=1;a<=3;a++)
printf("%f\t",average[a]);
printf("\n");
printf("各科總分從大到小排列");
for (b=1;b<=3;b++)
printf("%f\t",sum[a]);
}
void sort(int m ,float x[])
{
int i,j;float t;
for (i=1;i<=m;i++)
if(x[j]<=x[j+1])
{
t=x[j];
x[j]=x[j+1];
x[j+1]=t;
}
}
float max(int m,float y[])
{
int i;float max;
max=y[1];
for (i=1;i<=m;i++)
if(max<y[i+1])
max=y[i+1];
return(max);
}
float min(int m,float z[])
{
int i;float min;
min=z[1];
for (i=1;i<=m;i++)
if(min>z[i+1])
min=z[i+1];
return(min);
}

⑶ C語言成績管理系統,

你是沈陽工業大學的把

⑷ c語言成績管理系統

#include<string.h>
#include<stdio.h>
#define N 100 //最多的學生數
#define HEADLINE " 姓名 學號 語文 數學 英語 總分\n" //標題

//function portotype
void Combine(FILE *,FILE*); //合並兩個文件
void Order(FILE *); //總分降序排列
void SearchS(char[] );//查找學生信息
void ScanfOneLine(FILE*);
void PrintOneLine(FILE*);
void Total(); //計算一個學生的總分
void PutIntoSZ(FILE*); //將數據放入數組中,便於排序
void PutIntoFile(struct student st[],FILE *); //將數據放迴文件
void PrnFile(FILE*);//列印文件內容
void PrintSZ();//列印數組中的數
void sort1();//冒泡排序
void sort2();//選擇排序
void sort3();//插入排序
void Search(); //輸入名字顯示該生基本信息

struct student
{
char sName[8]; //學生姓名
int sNo; //學號
int Chinese_score; //語文成績
int Math_score; //數學
int English_score; //英語
int itotal;
}ST={"LiMing",20,91,92,92,100},st[N];

int i; //st數組指標
int num; //st數組有效元素的個數

FILE *fp1,*fp2,*fp3,*fp4; //各個文件指針

main(void)
{
fp1=fopen("d:\\1.txt","r+");
fp2=fopen("d:\\2.txt","r+");

fp3=fopen("d:\\3.txt","a+");
if(fp1==NULL||fp2==NULL)
{
printf("cannot open file!");
}
else
{
Combine(fp1,fp2);
PutIntoSZ(fp3);
PrnFile(fp3);

}
fclose(fp1);
fclose(fp2);
fclose(fp3);

return 0;
}

void Combine(FILE* fp1,FILE* fp2)//OK
{

while(!feof(fp1))
{

ScanfOneLine(fp1);
PrintOneLine(fp3);
}
while(!feof(fp2))
{
ScanfOneLine(fp2);
PrintOneLine(fp3);
}
printf("i=%d\n",i);

}

void PutIntoSZ(FILE*fp)
{

fseek(fp,0L,0); // 確保是從文件頭開始讀的!
i=0;
while(!feof(fp))
{
ScanfOneLine(fp); //將文件中的數先存入結構體數組中,並計算總分
st[i].itotal=(st[i].Chinese_score +st[i].English_score
+st[i].Math_score );
i++; //若有N個學生,I的最後值是N

}
num=i;//記錄個數
}

void ScanfOneLine(FILE*fp)//讀一行數據並存入結構體數組中
{
fscanf(fp,"%s%d%d%d%d",&st[i].sName ,&st[i].sNo,
&st[i].Chinese_score ,&st[i].Math_score ,&st[i].English_score);

}

void PrintOneLine(FILE *fp)
{
fprintf(fp,"%8s %3d %5d %5d %5d \n",st[i].sName ,st[i].sNo,
st[i].Chinese_score ,st[i].Math_score ,st[i].English_score);

}

//排序
void Order(FILE* fp)
{

if(fp==fp3){
fclose(fp);
fp=fopen("d:\\3.txt","r+");//!以r+的方式打開才可
}

PutIntoSZ(fp); //將fp的值放入數組中以便排序 I的值為N-1

int k=num;
int temp=num;

//冒泡排序法
for(int k1=0;k1<k-1;k1++)
{
for(int j=0;j<num-2;j++)
{

if(st[j].itotal>st[j+1].itotal)
{
ST=st[j];st[j]=st[j+1];st[j+1]=ST;

}

}
num--;
}
num=temp;//保證num的值不變。標示st[] 有效元素個數
int h=0;

fseek(fp,0L,0);
for( ;h<k-1;)
{

fprintf(fp,"%-8s %3d %3d %3d %3d \n",
st[h].sName ,st[h].sNo,
st[h].Chinese_score ,st[h].Math_score ,st[h].English_score);

h++;

}

}

//列印文件
void PrnFile(FILE* fp)
{
if(fp==fp3){
fclose(fp);
fp=fopen("d:\\3.txt","r+");//!以r+的方式打開才可
}
printf(HEADLINE);

while(!feof(fp))
{
printf("%c",fgetc(fp));

}

return;

}
//數組的數放迴文件
void PrintSZ()
{
printf("num=%d",num);
int h=0 ;
num++;

printf(HEADLINE);
while(num--)
{

printf("%8s %3d %5d %5d %5d %5d",
st[h].sName ,st[h].sNo,
st[h].Chinese_score ,st[h].Math_score ,st[h].English_score,st[h].itotal);
printf("\n");
h++;

}

}

//冒泡排序
void sort1()
{
int tag=1;
for(int i=0;i<num-1&&tag==1;i++)
{
tag=0;
for(int j=0;j<N-i-1;i++)
{
if(st[j].itotal>st[j+1].itotal)
{
ST=st[j];st[j]=st[j+1];st[j+1]=ST;
tag=1;
}
}

}

}

//選擇排序法
void sort2()
{

for(int i=0;i<num-1;i++)
{
for(int j=0;j<num-i-1;j++)
{
if(st[j].itotal>st[j+1].itotal)
{
ST=st[j]; st[j]=st[j+1]; st[j+1]=ST;
}

}

}
}

// 插入排序
void sort3()
{
int j;
for(int i=0;i<num-1;i++)
{
j=i+1;
while(j--)
{
if(st[j].itotal<st[j-1].itotal)
{
ST=st[j]; st[j]=st[j-1]; st[j-1]=ST;
}
}
}

}

void Search()
{
char a[8];
printf("請輸入要查找的學生姓名:");
scanf("%s",a);
PutIntoSZ(fp1);
for(int i=0;i<num;i++)
{
if(!strcmp(st[i].sName,a))
{
printf(HEADLINE);
printf("%8s %3d %5d %5d %5d %5d \n",st[i].sName ,st[i].sNo,
st[i].Chinese_score ,st[i].Math_score ,st[i].English_score,st[i].itotal);
return;
}

}
printf("NOT FOUND!");
return;

}

⑸ c語言 成績管理系統

我有個自己寫的成績管理系統,lz要可以傳給你,可能功能和你的不是很一樣。

⑹ 成績管理系統 c語言

學生成績管理系統代碼
#include<stdio.h>
#include<malloc.h>
#include<string.h>
typedef struct Student
{
int no;
char name[10];
float score[3]; //three scores
float average; //average score
struct Student *next;
}Student;
void Initial(Student *p)
{
p=(Student*)malloc(sizeof(Student));//the head of the linklist
p->next=NULL;
}
void Input(Student *p)
{
Student *stu=(Student*)malloc(sizeof(Student));
printf("學號:"); scanf("%d",&stu->no);
printf("姓名:"); scanf("%s",stu->name);
printf("成績1:"); scanf("%f",&stu->score[0]);
printf("成績2:"); scanf("%f",&stu->score[1]);
printf("成績3:"); scanf("%f",&stu->score[2]);
stu->average=(stu->score[0]+stu->score[1]+stu->score[2])/3;
stu->next=NULL;
Student *ps=(Student*)malloc(sizeof(Student));
ps=p;
while(ps->next)
ps=ps->next;
ps->next=stu;
//free(ps);
}
void Output(Student *p)
{
Student *ps=(Student*)malloc(sizeof(Student));
ps=p->next;
printf("學號\t姓名\t成績1\t成績2\t成績3\t平均分\n");
while(ps!=NULL)
{
printf("%d\t",ps->no);
printf("%s\t",ps->name);
printf("%.1f\t",ps->score[0]);
printf("%.1f\t",ps->score[1]);
printf("%.1f\t",ps->score[2]);
printf("%.1f\t\n",ps->average);
ps=ps->next;
}
free(ps);
}
void Find(Student *p)
{
Student *ps=(Student*)malloc(sizeof(Student));
ps=p->next;
char name[10];
printf("輸入要查詢的學生姓名:");
scanf("%s",name);
while(strcmp(ps->name,name)!=0) //相同時為0
ps=ps->next;

printf("學號\t姓名\t成績1\t成績2\t成績3\t平均分\n");
printf("%d\t",ps->no);
printf("%s\t",ps->name);
printf("%.1f\t",ps->score[0]);
printf("%.1f\t",ps->score[1]);
printf("%.1f\t",ps->score[2]);
printf("%.1f\t\n",ps->average);

}
void swap(Student *p1, Student *p2) //swap two nodes for sorting
{
Student *temp=(Student*)malloc(sizeof(Student));
temp->no=p1->no;
strcpy(temp->name,p1->name);
temp->score[0]=p1->score[0];
temp->score[1]=p1->score[1];
temp->score[2]=p1->score[2];
temp->average=p1->average;

p1->no=p2->no;
strcpy(p1->name,p2->name);
p1->score[0]=p2->score[0];
p1->score[1]=p2->score[1];
p1->score[2]=p2->score[2];
p1->average=p2->average;

p2->no=temp->no;
strcpy(p2->name,temp->name);
p2->score[0]=temp->score[0];
p2->score[1]=temp->score[1];
p2->score[2]=temp->score[2];
p2->average=temp->average;
free(temp);
}
void Sort(Student *p) //sort by average
{
Student *p1=(Student*)malloc(sizeof(Student));
Student *p2=(Student*)malloc(sizeof(Student));
p1=p->next;
while(p1)
{
float avg=p1->average;
p2=p1->next;
while(p2)
{
if( avg< (p2->average))
{
swap(p1,p2);
avg=p2->average;
}
p2=p2->next;
}
p1=p1->next;
}
}
void Insert(Student *p)
{
printf("按平均分高低插入數據!\n");
Student *stu=(Student*)malloc(sizeof(Student));//the data being inserted

printf("學號:"); scanf("%d",&stu->no);
printf("姓名:"); scanf("%s",stu->name);
printf("成績1:"); scanf("%f",&stu->score[0]);
printf("成績2:"); scanf("%f",&stu->score[1]);
printf("成績3:"); scanf("%f",&stu->score[2]);
stu->average=(stu->score[0]+stu->score[1]+stu->score[2])/3;
stu->next=NULL;

Student *p1=(Student*)malloc(sizeof(Student));//temp
p1=p;
while(p1->next && ((p1->next)->average) >(stu->average))
p1=p1->next;
//p1=p1->next;
stu->next=p1->next;
p1->next=stu;
}
void Menu(Student *p)
{
int select;
printf("您好,歡迎使用學生成績管理系統!\n");
printf("1:輸入學生成績數據\n2:輸出全部學生信息\n3:按姓名查找學生記錄\n4:按平均成績進行排序\n5:按平均成績高低插入數據\n6:退出\n");
scanf("%d",&select);
while(select<=6 && select>0)
{
switch(select)
{
case 1: Input(p);break;
case 2: Output(p);break;
case 3: Find(p); break;
case 4: Sort(p); break;
case 5: Insert(p); break;
case 6: printf("成功退出,歡迎再次使用!\n"); return ; break;
}
printf("1:輸入學生成績數據\n2:輸出全部學生信息\n3:按姓名查找學生記錄\n4:按平均成績進行排序\n5:按平均成績高低插入數據\n6:退出\n");
scanf("%d",&select);
}

}
int main()
{
Student *head=(Student*)malloc(sizeof(Student));
Menu(head);
}

⑺ c語言編程成績管理

#include <stdio.h> /*標准輸入輸出庫*/
#include <string.h> /*字元串操作庫*/
#include <conio.h> /*控制台函數庫*/
#include <malloc.h> /*內存分配庫*/
#include <process.h> /*進程庫*/

#define INITSIZE 100 /*初始化學生記錄的條數*/
#define INCSIZE sizeof(student) /*初始化空間不足時,增加存儲空間的位元組數*/

typedef struct
{
long no; /*學生序號*/
int math; /*數學成績*/
int program; /*程序設計成績*/
int amount; /*總分*/
char name[30]; /*學生姓名*/
}student; /*學生結構體*/

int maxsize = INITSIZE; /*初始化記錄條數*/
int num =0; /*當前學生記錄條數*/
int dbnull = 1; /*資料庫是否存在的標志*/

enum /*查詢,排序方式,五種*/
{
Num, /*學號方式*/
Name, /*姓名方式*/
Math, /*數學成績方式*/
Program, /*程序設計成績方式*/
Amount /*總分方式*/
};

/*以下為所有函數的聲明*/
int createset(student **t);
void addnew(student *t);
void deletestu(student *t);
void stuselect(student *t,int mode);
void scoresort(student *t,int mode);
int findno(student *t,int no);
int findmath(student *t,int math);
int findprogram(student *t,int program);
int findamount(student *t,int amount);
int findname(student *t,const char *name);
void display(student *t,int no);
void mathsort(student *t);
void programsort(student *t);
void amountsort(student *t);
void swap(student *t, int i,int j);

/*以下為函數實現*/
int createset(student **t)/*創建數據記錄集*/

{
char ask ;

if (num!=0) /*存在學生記錄*/
{
printf("Exsist a data base ,recover it?(Y/N)?");
ask =getch(); /*是否覆蓋資料庫*/
if (ask == 'y'||ask=='Y')
{
free(*t); /*若選擇覆蓋,則釋放現存存儲空間,學生記錄個數清零*/
num =0;
}
else
{
return 0; /*不選擇覆蓋,則退出*/
}
}

*t =(student *)malloc(INITSIZE*sizeof(student)); /*分配INITSIZE個學生記錄所需空間*/

if (!t)
{
printf("Memory overflow program abort."); /*內存不足,退出程序*/
exit(0);
}

else
{
printf("New database have been created.\n"); /*分配成功,成功創建資料庫*/
dbnull = 0; /*資料庫存在標志設為0(表示存在)*/
return 1;
}

}

void addnew(student *t) /*向資料庫插入學生記錄*/
{
student temp;

if (dbnull) /*資料庫存在標志不為0,即無資料庫,操作失敗*/
{
printf("Not exsist database select menu 1 to create database...");
return;
}
if (num+1>maxsize) /*當前記錄個數大於初始化記錄條數,追加空間*/
{
t =(student *)realloc(t,maxsize+INCSIZE); /*追加一個記錄所需空間*/
if (!t) /*內存不足,追加失敗*/
{
printf("Memory overflow! program abort.\n");
exit(0);
}
}

printf("Input the student's No. , name, math score and program score that you want to add.\n");

if (scanf("%ld%s%d%d",&(temp.no), /*輸入學生數據*/
temp.name,
&(temp.math),
&(temp.program)))
{
if (findno(t,temp.no) == -1) /*查找輸入的學號是否與資料庫的重復*/
{
t[num].no = temp.no; /*學號不沖突,則把輸入的記錄存放到資料庫末端*/
strcpy(t[num].name,temp.name);

t[num].math = temp.math;
t[num].program = temp.program;

t[num].amount = t[num].math + t[num].program;
num++; /*當前記錄數加一*/

printf("Add sucess!\n");
}

else
{
printf("Exsist the student whom NO. is %d,add fail.\n",temp.no);/*輸入學號已經存在,添加記錄失敗*/
}
}

else
{
printf("Data format error,add fail.\n"); /*輸入函數出錯,表示輸入格式錯誤,添加失敗*/
}

}

void deletestu(student *t) /*從資料庫刪除某條學生記錄*/
{

long delno =0;

int index;

int i =0;

if (dbnull)
{
printf("Not exsist database select menu 1 to create database...");
return;
}

printf("Input the student NO. that you want to delete :\n");

scanf("%ld",&delno); /*輸入要刪除的學生的學號*/

index = findno(t,delno); /*按學號方式查找該學生是否存在*/

if (index != -1) /*該學生存在,則刪除他*/
{

for (i = index+1; i<= num; i++) /*資料庫記錄前移,完成'刪除'操作*/
{

t[i-1].no = t[i].no;
strcpy(t[i-1].name,t[i].name);
t[i-1].math = t[i].math;
t[i-1].program = t[i].program;
t[i-1].amount = t[i].amount;

}
num--; /*當前記錄數減一*/

printf("Delete success!\n");

}

else
{
printf("The NO. that you input not exsist delete fail\n"); /*無該學號的學生,刪除失敗*/
}

}

void stuselect(student *t,int mode) /*搜索資料庫*/
{
long tempno =0;
char tempname[30];
int tempmath;
int tempprogram;
int tempamount;
int count =0;

if (dbnull)
{
printf("Not exsist database select menu 1 to create database...");
return;
}

switch (mode) /*判斷查詢方式*/
{
case Num: /*按學號查詢*/
printf("Input the student NO. that you want to search.\n");
scanf("%ld",&tempno); /*輸入學號*/
tempno =findno(t,tempno); /*查找該學生*/

if ( tempno!= -1 )
{
printf("Search sucess!.\n");/*查詢成功,列印之*/
display(t,tempno);
}
else
{
printf("The NO. that you input not exsist search fail.\n"); /*查找失敗*/
}
break;
case Name: /*按姓名查詢*/
printf("Input the student name that you want to search.:\n");
*tempname ='\0';
scanf("%s",tempname);
count = findname(t,tempname); /*返回查詢姓名為name的學生記錄個數*/
printf("There are %d student have been searched.\n",count);
break;
case Math: /*按數學成績查詢*/
printf("Input the a score, program will search students which math scores are higher than it.\n");
scanf("%d",&tempmath);
count = findmath(t,tempmath);
printf("There are %d student have been searched.\n",count);
break;

case Program: /*按程序設計成績查詢*/

printf("Input the a score, program will search students which programming scores are higher than it.\n");
scanf("%d",&tempprogram);
count = findprogram(t,tempprogram);
printf("There are %d student have been searched.\n",count);
break;

case Amount: /*按總分查詢*/
printf("Input the a score, program will search students which sum scores are higher than it\n");
scanf("%d",&tempamount);
count = findamount(t,tempamount);
printf("There are %d student have been searched.\n",count);
break;
default:
break;

}

}

void scoresort(student *t,int mode) /*學生記錄排序*/
{
int count =0;

switch (mode) /*選擇不同排序方式進行成績排序*/
{
case Math:
mathsort(t); /*按數學成績排序*/
break;
case Program: /*按程序設計成績排序*/
programsort(t);
break;
case Amount: /*按總分排序*/
amountsort(t);
break;
}

printf("Sorting have been finished .flowing is the result:\n");
for (count =0;count< num; count++) /*排序完成後輸出排序結果*/
{
display(t,count);
}
}

int findno(student *t,int no)/*按學號查找學生記錄*/
{
int count =0;
for (count =0; count<num; count++)
{
if ((t+count)->no == no) /*逐個搜索,若該學生記錄的學號等於需要查找的學號,則返回該學號*/
{
return count;
}
}
return -1; /*搜索完畢,仍沒有匹配學號,則返回-1*/
}

int findmath(student *t,int math)
{
int count =0; /*按數學成績查找,這里查找的結果是大於指定數學分數的所有學生記錄*/
int i =0;
for (count =0; count<num; count++)
{
if ((t+count)->math > math)
{
display (t,count); /*顯示查找結果*/
i++;
}
}

return i; /*返回符合查詢條件的學生記錄數目*/
}

int findprogram(student *t,int program)/*按程序設計成績查找學生記錄,演算法類似上面的模塊*/
{
int count =0;
int i =0;
for (count =0; count<num; count++)
{
if ((t+count)->program > program)
{
display(t,count);
i++;
}
}

return i;
}

int findamount(student *t,int amount)/*類似上面的模塊*/
{
int count =0;
int i =0;
for (count =0; count<num; count++)
{
if ((t+count)->amount > amount)
{
display(t,count);
i++;
}
}

return i;
}

int findname(student *t,const char *name) /*類似上面的模塊*/
{
int count =0;
int i =0;
for (count =0; count<num; count++)
{
if (!strcmp((t+count)->name,name))
{
display(t,count);
i++;
}
}

return i;
}

void display(student *t,int no) /*列印指定學生記錄*/
{
printf("NO.: %2ld Name:%10s Math : %2d Programing: %2d Sum: %3d .\n",
t[no].no,
t[no].name,
t[no].math,
t[no].program,
t[no].amount);
}

void mathsort(student *t) /*數學成績排序,使用選擇排序演算法*/
{

int i;
int j;

for ( i =0; i< num-1; i++)
for ( j =i+1; j<num; j++)
{
if ( t[j].math > t[i].math )
{
swap(t,j,i);
}
}
}

void programsort(student *t) /*類似數學成績排序*/
{

int i;
int j;

for ( i =0; i< num-1; i++)
for ( j =i+1; j<num; j++)
{
if ( t[j].program > t[i].program )
{
swap(t,j,i);
}
}
}

void amountsort(student *t) /*類似數學成績排序*/
{

int i;
int j;

for ( i =0; i< num-1; i++)
for ( j =i+1; j<num; j++)
{
if ( t[j].amount > t[i].amount )
{
swap(t,j,i);
}
}
}

void swap(student *t, int i,int j) /*交換兩個學生的記錄內容*/
{
student temp; /*定義一個中間記錄*/

temp.no = t[j].no; /*逐個交換記錄的數據項*/
t[j].no = t[i].no;
t[i].no = temp.no;

strcpy(temp.name , t[j].name);
strcpy(t[j].name , t[i].name);
strcpy(t[i].name , temp.name);

temp.math = t[j].math;
t[j].math = t[i].math;
t[i].math = temp.math;

temp.program = t[j].program;
t[j].program = t[i].program;
t[i].program = temp.program;

temp.amount = t[j].amount;
t[j].amount = t[i].amount;
t[i].amount = temp.amount;
}

void main() /*Main mole 主控模塊*/
{

student *t; /*定義整個程序學生記錄數據塊,用指針t標識*/

int Menu =0,submenu =0;/*表示菜單項,主菜單,子菜單*/

printf("\n\t\t********Students information manage system.********\n");
while ( Menu!= '6' ) /*選擇菜單若為'6':(退出項),則退出菜單選擇*/
{

fflush(stdin); /*清除輸入緩沖區*/
submenu =0; /*重置子菜單的選中項*/
printf("\
\n\
1>.New database.\n\
2>.Add data record.\n\
3>.Delete data record.\n\
4>.Sort.\n\
5>.Search.\n\
6>.Exit\n");

printf("\nInput the menu's command...\n");
Menu = getchar(); /*選擇菜單*/

switch (Menu) /*按選擇的菜單項,執行相應模塊*/
{
case '1':
createset(&t);
break;
case '2':
addnew(t);
break;
case '3':
deletestu(t);
break;
case '4':
if (dbnull) /*資料庫不存在,不予以處理*/
{
printf("Not exsist database select menu 1 to create database...");
break;
}

while (submenu != '4' )/*進入排序方式的子菜單*/
{
fflush(stdin);
printf("\t****Score sort****\n\
1>.Math score sort.\n\
2>.Programming score sort.\n\
3>.Sum score sort.\n\
4>.Return to main menu.\n");
printf("\n\tInput the menu's command...\n");
submenu = getchar();

switch ( submenu )
{

case '1':
scoresort(t,Math);
break;
case '2':
scoresort(t,Program);
break;
case '3':
scoresort(t,Amount);
break;
case '4':
break;
default:
break;
}

}
break;
case '5':

if (dbnull)
{
printf("Not exsist database select menu 1 to create database...");
break;
}
while (submenu != '6') /*進入查詢子菜單*/
{
fflush(stdin);

printf("\t****Student search.*****\n\
1>NO. search.\n\
2>Name search.\n\
3>Math score search.\n\
4>Programming score search.\n\
5>Sum score search.\n\
6>Return to main menu.\n");

printf("\n\tInput the menu command...\n");
submenu = getchar();

switch (submenu)
{
case '1':
stuselect(t,Num);
break;
case '2':
stuselect(t,Name);
break;
case '3':
stuselect(t,Math);
break;
case '4':
stuselect(t,Program);
break;
case '5':
stuselect(t,Amount);
break;
case '6':
break;
default:
break;
}

}

case '6':
break;
default:
break;
}

}

printf("End ************Student information manage system*****\n");

printf("\t\t\t\t\t\tPress any key to exit...");
fflush(stdin);
getch(); /*按任意鍵返回*/
}

⑻ c語言學生成績管理系統

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

#define MAX 80 //學生最大人數

#define max 3 //科目數量

struct classname //科目結構體,科目名稱,該科目分數
{
char name[20];
float score;
};

struct student //學生結構體,學號,學生姓名,科目,平均分,總分
{
char no[20];
char std_name[20];
struct classname km[max];
float ave;
float sum;
int save; //檢驗數,沒有添加刪除函數,此變數沒有作用,可刪除,但是注意刪除要把初始函數里的初始語句也刪除
};

struct student stu[MAX];//全局變數,結構體數組

int nu=0;//全局變數 文件已存人數

void chushi()//程序初始化函數,對全局變數stu初始化
{
int i,j;
for(i=0;i<MAX;i++)
{
for(j=0;j<20;j++)
{
stu[i].no[j]='\0';
stu[i].std_name[j]='\0';
stu[i].km[j].name[j]='\0';
stu[i].km[j].score=0;
}
stu[i].ave=0;
stu[i].sum=0;
stu[i].save=0;
}
}

void av()/*求平均值*/
{
int i;
for(i=0;i<nu;i++)
{
stu[i].sum=stu[i].km[0].score+stu[i].km[1].score+stu[i].km[2].score;
stu[i].ave=stu[i].sum/3;
}
}

void first_check()
{
FILE *p;//文件指針
int i,j;
struct classname frist[max];//臨時變數,接收第一次輸入的科目名稱
for(i=0;i<max;i++)
{
for(j=0;j<20;j++)
frist[i].name[j]='\0';
frist[i].score=0;
}
if ((p=fopen("e:\\kemu.txt","r"))==NULL)//如果文件不存在,執行下面語句
{
printf("您好,歡迎使用學生成績管理系統\n\n因為您是第一次使用,請輸入科目名稱(三科)\n\n");
p=fopen("e:\\kemu.txt","w");//建立科目文件,保存c盤根目錄
printf("輸入課程1名稱:");
scanf("%s",frist[0].name);
fprintf(p,"%s\n",frist[0].name);//課程寫入文件
printf("輸入課程2名稱:");
scanf("%s",frist[1].name);
fprintf(p,"%s\n",frist[1].name);//同上
printf("輸入課程3名稱:");
scanf("%s",frist[2].name);
fprintf(p,"%s\n",frist[2].name);//同上
}
system("cls");//清屏函數
fclose(p);
}

void save_nu()//往人數文件寫入人數信息
{
FILE *p;
p=fopen("e:\\renshu.txt","w");
fprintf(p,"%d\n",nu);
fclose(p);
}

void Save_add(int n)//寫入成績信息,成績文件已存在,在文件內部末尾追加寫入
{
FILE * p;
int i;
p= fopen("e:\\chengji.txt","at");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i<n;i++)
if(stu[i].save==1)
{
stu[i].sum=stu[i].km[1].score+stu[i].km[2].score+stu[i].km[3].score;
stu[i].ave=stu[i].sum/3;
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}

void Save()//寫入成績信息,成績文件不存在,新建成績文件並寫入信息
{
FILE * p;
int i;
p= fopen("e:\\chengji.txt","w");
if (p == NULL)
{
printf("文件不存在!!\n");
exit(0);
}
save_nu();
for (i = 0;i<nu;i++)
if(stu[i].save==1)
{
av();
fprintf(p,"%s %s %2.1f %2.1f %2.1f %2.1f %2.1f \n",stu[i].no,stu[i].std_name,stu[i].km[0].score,stu[i].km[1].score,stu[i].km[2].score,stu[i].ave,stu[i].sum);
}
fclose(p);
}

int read_nu()//讀取人數文件中存在的人數信息
{
FILE *p;
char ch,s[10]={'\0'};
int i=0;
p=fopen("e:\\renshu.txt","r");
if(p==NULL)
{
save_nu();
return 0;
}
ch=fgetc(p);
while(ch!='\n')
{
s[i]=ch;
ch=fgetc(p);
i++;
}
nu=atoi(s);
fclose(p);
return 0;
}

int read_km()//讀取科目文件中存儲的科目信息
{
FILE *p;
int i,j=0;
char s[20]={'\0'};
chushi();
p=fopen("e:\\kemu.txt","r");
if(p==NULL)
{
printf("ERROR read_km");
return 0;
}
fgets(s,20,p);
while(strlen(s)!=0)
{
for(i=0;i<strlen(s);i++)
if(s[i]==10)
{
s[i]='\0';
break;
}
for(i=0;i<=nu;i++)
strcpy(stu[i].km[j].name,s);
for(i=0;i<20;i++)
s[i]='\0';
j++;
fgets(s,20,p);
}
return 0;
}

void read()//重要函數!讀取成績文件中以存儲的學生成績信息並存入內存
{
FILE *p;
int i,j,n,k,z=0;
char s[50]={'\0'};
char o[10]={'\0'};
p=fopen("e:\\chengji.txt","r");
if(p==NULL)
printf("ERROR_read");
chushi();
read_km();
fgets(s,50,p);
while(strlen(s)!=0)
{
j=0;
for(i=0;i<50;i++)
{
if(s[i]!='\n')
{
n=0;
while(j==0)
{
if(s[i]!=' ')
{
stu[z].no[n]=s[i];
n++;i++;
}
else
break;
}
while(j==1)
{
if(s[i]!=' ')
{
stu[z].std_name[n]=s[i];
n++;i++;
}
else
break;
}
while(j==2)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[0].score=atoi(o);
break;
}
}
while(j==3)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[1].score=atoi(o);
break;
}
}
while(j==4)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].km[2].score=atoi(o);
break;
}
}
while(j==5)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].ave=atoi(o);
break;
}
}
while(j==6)
{
if(s[i]!=' ')
{
o[n]=s[i];
n++;i++;
}
else
{
stu[z].sum=atoi(o);
break;
}
}
for(k=0;k<10;k++)
o[k]='\0';
}
else
break;
j++;
}
for(i=0;i<50;i++)
s[i]='\0';
fgets(s,50,p);
z++;
}
}

void putin()//功能函數,錄入學生成績信息
{
int n,i=0;
char ch;
read_km();
do
{
printf("\t\t\t\t錄入學生信息\n輸入第%d個學生的信息\n",i+1);
printf("\n輸入學生學號:");
scanf("%s",stu[i].no);
printf("\n輸入學員姓名:");
scanf("%s",stu[i].std_name);
printf("\n輸入語文%s的分數:",stu[0].km[0].name);
scanf("%f",&stu[i].km[0].score);
printf("\n輸入數學%s的分數:",stu[0].km[1].name);
scanf("%f",&stu[i].km[1].score);
printf("\n輸入英語%s的分數:",stu[0].km[2].name);
scanf("%f",&stu[i].km[2].score);
stu[i].save=1;
printf("\n\n");
i++;
n=i;
printf("是否繼續輸入?(Y/N)");
fflush(stdin);
ch=getch();
system("cls");
}
while(ch!='n'&&ch!='N');
system("cls");
if(nu==0)
{
nu=n;
Save();
}
else
{
nu=n+nu;
Save_add(n);
}
}

int putout()//功能函數,顯示學生信息
{
int i;char s;
if(nu==0)
{
printf("學生信息為零!請錄入...");
return 0;
}
read();
do
{
printf("學生成績信息:\n\n");
for(i=0;i<nu;i++)
printf("學號:%s 姓名:%s\n%s分數:%2.1f\t%s分數:%2.1f\t%s 分數:%2.1f\n平均分數:%2.1f\t總成績:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].km[0].name,stu[i].km[0].score,stu[i].km[1].name,stu[i].km[1].score,stu[i].km[2].name,stu[i].km[2].score,stu[i].ave,stu[i].sum);
printf("\t\t按任意鍵返回主菜單");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
return 0;
}

int sort()/*排序數據函數*/
{
struct student temp;
int i,j;
char s;
if(nu==0)
{
printf("學生信息為零!請錄入...");
return 0;
}
read();
for(i=1;i<nu;i++)
{
for(j=1;j<=nu-i;j++)
{
if(stu[j-1].ave<stu[j].ave)
{
temp=stu[j];
stu[j]=stu[j-1];
stu[j-1]=temp;
}
}
}
do
{
printf("學生成績信息:\n\n");
for(i=0;i<nu;i++)
printf("學號:%s 姓名:%s 平均成績:%2.1f\n\n",stu[i].no,stu[i].std_name,stu[i].ave);
printf("\t\t按任意鍵返回主菜單");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
return 0;
}

int find()/*查詢函數*/
{
int j,i=0;
int c=0;
char search[20]={'\0'};
char as;
if(nu==0)
{
printf("學生信息為零!請錄入...");
return 0;
}
read();
do
{
printf("輸入要查詢課程名稱:");
scanf("%s",search);
for(j=0;j<max;j++)
if(!strcmp(stu[i].km[j].name,search))
{
c=1;
printf("\n該課程不及格學生姓名:\n");
for(i=0;i<nu;i++)
if(stu[i].km[j].score<60)
printf("%s\n",stu[i].std_name);
}
if(c==0)
printf("無此課程!");
printf("\n\t\t按任意鍵返回主菜單");
fflush(stdin);
as=getch();
}
while(!as);
system("cls");
return 0;
}

int tongji()//功能函數,統計學生成績信息
{
int j,m,z,i=0;
char s;
if(nu==0)
{
printf("學生信息為零!請錄入...");
return 0;
}
read();
for(z=0;z<max;z++)
{
m=stu[i].km[z].score;j=0;
printf("%s 最高分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(m<stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
j=0;i=0;m=stu[i].km[z].score;
printf("%s 最低分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(m>stu[i].km[z].score)
{
m=stu[i].km[z].score;
j=i;
}
printf("%s\t",stu[j].std_name);
m=0;j=0;i=0;
printf("%s 平均分: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
m=m+stu[i].km[z].score;
printf("%d\n",m/nu);
m=0;i=0;
printf("%s 分數低於的60人數: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(stu[i].km[z].score<60)
m++;
printf("%d\t",m);
m=0;j=0;i=0;
printf("%s 分數高於60的人數: ",stu[i].km[z].name);
for(i=0;i<nu;i++)
if(stu[i].km[z].score>60)
m++;
printf("%d\n\n",m);
}
do
{
printf("\t\t按任意鍵返回主菜單");
fflush(stdin);
s=getch();
}
while(!s);
system("cls");
return 0;
}

void main()/*主函數*/
{
int as;
first_check();
start: printf("\n\t\t\t歡迎使用學生成績管理系統\n");
/*一下為功能選擇模塊*/
do
{
printf("\n\t\t\t\t1.錄入學生信息\n\t\t\t\t2.顯示學生信息\n\t\t\t\t3.成績排序信息\n\t\t\t\t4.查詢不及格學生\n\t\t\t\t5.統計信息\n\t\t\t\t6.退出\n");
printf("\t\t\t\t選擇功能選項:");
fflush(stdin);
read_nu();
scanf("%d",&as);
switch(as)
{
case 1:system("cls");putin();break;
case 2:system("cls");putout();break;
case 3:system("cls");sort();break;
case 4:system("cls");find();break;
case 5:system("cls");tongji();break;
case 6:system("exit");exit(0);
default:system("cls");goto start;
}
}
while(1);
/*至此功能選擇結束*/
}

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

要dos窗口的嗎?

⑽ c語言 學生成績管理程序

暈,這在一般課程設計的書里都能找到相似的...自己寫一次吧,對你編程有很大幫助的.

熱點內容
護網腳本 發布:2025-07-22 03:32:38 瀏覽:4
伺服器有多個網口怎麼查看地址 發布:2025-07-22 03:31:54 瀏覽:234
pda掃描服務密碼是多少 發布:2025-07-22 03:06:11 瀏覽:98
暗影精靈2代配置是什麼 發布:2025-07-22 03:02:07 瀏覽:432
密碼鎖恢復出廠設置後如何設置密碼 發布:2025-07-22 03:02:05 瀏覽:787
linux外網ip 發布:2025-07-22 02:49:23 瀏覽:888
內核和根文件系統的編譯與配置 發布:2025-07-22 02:45:00 瀏覽:589
ps存儲了文件但找不到 發布:2025-07-22 02:39:10 瀏覽:191
dcu反編譯 發布:2025-07-22 02:21:50 瀏覽:161
比亞迪車機安卓什麼版本 發布:2025-07-22 02:19:46 瀏覽:983