/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
/中文/
c語(yǔ)言學(xué)生成績(jī)管理系統(tǒng)是一款用C語(yǔ)言設(shè)計(jì)制作的成績(jī)管理系統(tǒng),它是由吾愛(ài)論壇網(wǎng)友分享提供的,旨在幫助學(xué)習(xí)C語(yǔ)言的朋友來(lái)進(jìn)行實(shí)戰(zhàn)運(yùn)用學(xué)習(xí),感興趣的朋友不要錯(cuò)過(guò)了,歡迎下載使用。
有許多朋友要求出一個(gè)比較難的程序,今天給大家分享一個(gè)C語(yǔ)言環(huán)境下開(kāi)發(fā)的學(xué)生成績(jī)管理系統(tǒng)
這個(gè)系統(tǒng)原理很簡(jiǎn)單:成績(jī)的錄入,輸出,修改,排序,刪除等等。
主要目的是幫大家溫習(xí)C語(yǔ)言的使用。
1.實(shí)現(xiàn)所有學(xué)生成績(jī)的錄入(利用結(jié)構(gòu)體數(shù)組),當(dāng)輸入字符為end時(shí)候,結(jié)束成績(jī)的錄入;
2.實(shí)現(xiàn)所有學(xué)生信息的輸出
3.輸入指定學(xué)生姓名,并能輸出這名學(xué)生的信息
4.將學(xué)生成績(jī)按照語(yǔ)文和數(shù)學(xué)成績(jī)排序
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<dos.h>
#include<string.h>
#define LEN sizeof(struct student)
#define FORMAT "%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n"
#define DATA stu.num,stu.name,stu.elec,stu.expe,stu.requ,stu.sum
//僅供學(xué)習(xí)使用,起切勿用作商業(yè)用途!
float Felec,Fexpe,Frequ;
struct student/*定義學(xué)生成績(jī)結(jié)構(gòu)體*/
{
int num;/*學(xué)號(hào)*/
char name[15];/*姓名*/
double elec;/*選修課*/
double expe;/*實(shí)驗(yàn)課*/
double requ;/*必修課*/
double sum;/*總分*/
};
struct student stu[50];/*定義結(jié)構(gòu)體數(shù)組*/
void in();/*錄入學(xué)生成績(jī)信息*/
void show();/*顯示學(xué)生信息*/
void order();/*按總分排序*/
void del();/*刪除學(xué)生成績(jī)信息*/
void modify();/*修改學(xué)生成績(jī)信息*/
void menu();/*主菜單*/
void insert();/*插入學(xué)生信息*/
void total();/*計(jì)算總?cè)藬?shù)*/
void search();/*查找學(xué)生信息*/
int main()/*主函數(shù)*/
{
int n;
menu();
scanf("%d",&n);/*輸入選擇功能的編號(hào)*/
while(n)
{
switch(n)
{
case 1:
in();
break;
case 2:
search();
break;
case 3:
del();
break;
case 4:
modify();
break;
case 5:
insert();
break;
case 6:
order();
break;
case 7:
total();
break;
default:break;
}
getch();
menu();/*執(zhí)行完功能再次顯示菜單界面*/
scanf("%d",&n);
}
}
void in()/*錄入學(xué)生信息*/
{
int i,m=0;/*m是記錄的條數(shù)*/
char ch[2];
FILE *fp;/*定義文件指針*/
if((fp=fopen("data","ab+"))==NULL)/*打開(kāi)指定文件*/
{
printf("can not open\n");
return;
}
while(!feof(fp))
{
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;/*統(tǒng)計(jì)當(dāng)前記錄條數(shù)*/
}
fclose(fp);
if(m==0)
printf("No record!\n");
else
{
system("cls");
show();/*調(diào)用show函數(shù),顯示原有信息*/
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(i=0;i<m;i++)
fwrite(&stu ,LEN,1,fp);/*向指定的磁盤(pán)文件寫(xiě)入信息*/
printf("please input(y/n):");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("please input per centum:");
printf("\nelective:");
scanf("%f",&Felec);
printf("\nexperiment:");
scanf("%f",&Fexpe);
printf("\nrequired course:");
scanf("%f",&Frequ);
}
while(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要錄入新信息*/
{
printf("number:");
scanf("%d",&stu[m].num);/*輸入學(xué)生學(xué)號(hào)*/
for(i=0;i<m;i++)
if(stu.num==stu[m].num)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("name:");
scanf("%s",stu[m].name);/*輸入學(xué)生姓名*/
printf("elective:");
scanf("%lf",&stu[m].elec);/*輸入選修課成績(jī)*/
printf("experiment:");
scanf("%lf",&stu[m].expe);/*輸入實(shí)驗(yàn)課成績(jī)*/
printf("required course:");
scanf("%lf",&stu[m].requ);/*輸入必修課成績(jī)*/
stu[m].sum=stu[m].elec*Felec+stu[m].expe*Fexpe+stu[m].requ*Frequ;/*計(jì)算出總成績(jī)*/
if(fwrite(&stu[m],LEN,1,fp)!=1)/*將新錄入的信息寫(xiě)入指定的磁盤(pán)文件*/
{
printf("can not save!");
getch();
}
else
{
printf("%s saved!\n",stu[m].name);
m++;
}
printf("continue?(y/n):");/*詢(xún)問(wèn)是否繼續(xù)*/
scanf("%s",ch);
}
fclose(fp);
printf("OK!\n");
}
void show()
{
FILE *fp;
int i,m=0;
fp=fopen("data","ab+");
while(!feof(fp))
{
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
printf("number name elective experiment required sum\t\n");
for(i=0;i<m;i++)
{
printf(FORMAT,DATA);/*將信息按指定格式打印*/
}
}
void menu()/*自定義函數(shù)實(shí)現(xiàn)菜單功能*/
{
system("cls");
printf("\n\n\n\n\n");
printf("\t\t|---------------------STUDENT-------------------|\n");
printf("\t\t|\t 0. exit |\n");
printf("\t\t|\t 1. input record |\n");
printf("\t\t|\t 2. search record |\n");
printf("\t\t|\t 3. delete record |\n");
printf("\t\t|\t 4. modify record |\n");
printf("\t\t|\t 5. insert record |\n");
printf("\t\t|\t 6. order |\n");
printf("\t\t|\t 7. number |\n");
printf("\t\t|--------該程序由吾愛(ài)破解bfgjjt提供-------------|\n\n");
printf("\t\t\tchoose(0-7):");
}
void order()/*自定義排序函數(shù)*/
{
FILE *fp;
struct student t;
int i=0,j=0,m=0;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open!\n");
return;
}
while(!feof(fp))
if(fread(&stu[m] ,LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
for(i=0;i<m-1;i++)
for(j=i+1;j<m;j++)/*雙重循環(huán)實(shí)現(xiàn)成績(jī)比較并交換*/
if(stu.sum<stu[j].sum)
{
t=stu;
stu=stu[j];
stu[j]=t;
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(i=0;i<m;i++)/*將重新排好序的內(nèi)容重新寫(xiě)入指定的磁盤(pán)文件中*/
if(fwrite(&stu ,LEN,1,fp)!=1)
{
printf("%s can not save!\n");
getch();
}
fclose(fp);
printf("save successfully\n");
}
void del()/*自定義刪除函數(shù)*/
{
FILE *fp;
int snum,i,j,m=0;
char ch[2];
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu.num)
break;
if(i==m)
{
printf("can not find");
getchar();
return;
}
printf("find the student,delete?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)/*判斷是否要進(jìn)行刪除*/
{
for(j=i;j<m;j++)
stu[j]=stu[j+1];/*將后一個(gè)記錄移到前一個(gè)記錄的位置*/
m--;/*記錄的總個(gè)數(shù)減1*/
printf("delete successfully!\n");
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(j=0;j<m;j++)/*將更改后的記錄重新寫(xiě)入指定的磁盤(pán)文件中*/
if(fwrite(&stu[j] ,LEN,1,fp)!=1)
{
printf("can not save!\n");
getch();
}
fclose(fp);
}
void search()/*自定義查找函數(shù)*/
{
FILE *fp;
int snum,i,m=0;
char ch[2];
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf("no record!\n");
return;
}
printf("please input the number:");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu.num)/*查找輸入的學(xué)號(hào)是否在記錄中*/
{
printf("find the student,show?(y/n)");
scanf("%s",ch);
if(strcmp(ch,"Y")==0||strcmp(ch,"y")==0)
{
printf("number name elective experiment required sum\t\n");
printf(FORMAT,DATA);/*將查找出的結(jié)果按指定格式輸出*/
break;
}
else
return;
}
if(i==m)
printf("can not find the student!\n");/*未找到要查找的信息*/
}
void modify()/*自定義修改函數(shù)*/
{
FILE *fp;
int i,j,m=0,snum;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
if(m==0)
{
printf("no record!\n");
fclose(fp);
return;
}
printf("please input the number of the student which do you want to modify!\n");
scanf("%d",&snum);
for(i=0;i<m;i++)
if(snum==stu.num)/*檢索記錄中是否有要修改的信息*/
break;
if(i<m)
{
printf("find the student!you can modify!\n");
printf("please input per centum:");
printf("\nelective:");
scanf("%f",&Felec);
printf("\nexperiment:");
scanf("%f",&Fexpe);
printf("\nrequired course:");
scanf("%f",&Frequ);
printf("name:\n");
scanf("%s",stu.name);/*輸入名字*/
printf("\nelective:");
scanf("%lf",&stu.elec);/*輸入選修課成績(jī)*/
printf("\nexperiment:");
scanf("%lf",&stu.expe);/*輸入實(shí)驗(yàn)課成績(jī)*/
printf("\nrequired course:");
scanf("%lf",&stu.requ);/*輸入必修課成績(jī)*/
stu.sum=stu.elec*Felec+stu.expe*Fexpe+stu.requ*Frequ;
}
else
{
printf("can not find!");
getchar();
return;
}
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(j=0;j<m;j++)/*將新修改的信息寫(xiě)入指定的磁盤(pán)文件中*/
if(fwrite(&stu[j] ,LEN,1,fp)!=1)
{
printf("can not save!");
getch();
}
fclose(fp);
}
void insert()/*自定義插入函數(shù)*/
{
FILE *fp;
int i,j,k,m=0,snum;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;
if(m==0)
{
printf("no record!\n");
fclose(fp);
return;
}
printf("please input position where do you want to insert!(input the number)\n");
scanf("%d",&snum);/*輸入要插入的位置*/
for(i=0;i<m;i++)
if(snum==stu.num)
break;
for(j=m-1;j>i;j--)
stu[j+1]=stu[j];/*從最后一條記錄開(kāi)始均向后移一位*/
printf("now please input the new information.\n");
printf("number:");
scanf("%d",&stu[i+1].num);
for(k=0;k<m;k++)
if(stu[k].num==stu[i+1].num&&k!=i+1)
{
printf("the number is existing,press any to continue!");
getch();
fclose(fp);
return;
}
printf("please input per centum:");
printf("\nelective:");
scanf("%f",&Felec);
printf("\nexperiment:");
scanf("%f",&Fexpe);
printf("\nrequired course:");
scanf("%f",&Frequ);
printf("name:\n");
scanf("%s",stu[i+1].name);
printf("\nelective:");
scanf("%lf",&stu[i+1].elec);
printf("\nexperiment:");
scanf("%lf",&stu[i+1].expe);
printf("\nrequired course:");
scanf("%lf",&stu[i+1].requ);
stu[i+1].sum=stu[i+1].elec*Felec+stu[i+1].expe*Fexpe+stu[i+1].requ*Frequ;
if((fp=fopen("data","wb"))==NULL)
{
printf("can not open\n");
return;
}
for(k=0;k<=m;k++)
if(fwrite(&stu[k] ,LEN,1,fp)!=1)/*將修改后的記錄寫(xiě)入磁盤(pán)文件中*/
{
printf("can not save!");
getch();
}
fclose(fp);
}
void total()
{
FILE *fp;
int m=0;
if((fp=fopen("data","ab+"))==NULL)
{
printf("can not open\n");
return;
}
while(!feof(fp))
if(fread(&stu[m],LEN,1,fp)==1)
m++;/*統(tǒng)計(jì)記錄個(gè)數(shù)即學(xué)生個(gè)數(shù)*/
if(m==0)
{
printf("no record!\n");
fclose(fp);
return;
}
printf("the class are %d students!\n",m);/*將統(tǒng)計(jì)的個(gè)數(shù)輸出*/
fclose(fp);
}
C語(yǔ)言編譯器哪個(gè)好?C語(yǔ)言編譯器主要分為C/C++兩大類(lèi),那么作為新手,剛接觸到C語(yǔ)言學(xué)習(xí),該如何選擇一款C語(yǔ)言編譯器呢?目前比較流行的C語(yǔ)言編譯器主要是GCC、MSC、TurboC等幾種,完美實(shí)現(xiàn)了ANSIC標(biāo)準(zhǔn),并且進(jìn)行了針
關(guān)于騰牛 | 聯(lián)系方式 | 發(fā)展歷程 | 版權(quán)聲明 | 下載幫助(?) | 廣告聯(lián)系 | 網(wǎng)站地圖 | 友情鏈接
Copyright 2005-2022 QQTN.com 【騰牛網(wǎng)】 版權(quán)所有 鄂ICP備2022005668號(hào)-1 | 鄂公網(wǎng)安備 42011102000260號(hào)
聲明:本站非騰訊QQ官方網(wǎng)站 所有軟件和文章來(lái)自互聯(lián)網(wǎng) 如有異議 請(qǐng)與本站聯(lián)系 本站為非贏利性網(wǎng)站 不接受任何贊助和廣告