日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

c语言在管理系统中的应用,C语言应用——学生管理系统的制作

發(fā)布時間:2025/3/15 windows 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c语言在管理系统中的应用,C语言应用——学生管理系统的制作 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

該樓層疑似違規(guī)已被系統(tǒng)折疊?隱藏此樓查看此樓

問題描述:

在文件studd.txt中存放學生信息,學生信息包含學號、姓名和成績。要求采用菜單形式實現(xiàn)學生記錄的創(chuàng)建、添加、查找(按學號進行)、修改(按學號進行)和刪除(按學號進行)、顯示所有信息等功能。用戶可以循環(huán)操作直到選擇退出為止。

分析:

本題是對文件的綜合應用,采用菜單形式可以方便地實現(xiàn)程序模塊的設計方法,這樣可以使程序顯得簡潔明了。設計時可以逐個完成各模塊功能,并調試好每個模塊,然后再整合各模塊。

參考代碼:

#include

#include

#include

#include

struct student

{ char no[10];

char name[20];

int score;

};

char filename[100]="studd.txt"; /*設置文件名*/

FILE *fp;

void create(); /*創(chuàng)建函數(shù)聲明*/

void append(); /*添加函數(shù)聲明*/

void search(); /*查找函數(shù)聲明*/

void del(); /*刪除函數(shù)聲明*/

void modify(); /*修改函數(shù)聲明*/

void output(); /*顯示函數(shù)聲明*/

int main(void)

{

int num;

while(1)

{

printf(" ***學生成績系統(tǒng)*** ");

printf(" 1.創(chuàng)建記錄 ");

printf(" 2.添加記錄 ");

printf(" 3.查找記錄 ");

printf(" 4.修改記錄 ");

printf(" 5.刪除記錄 ");

printf(" 6.顯示記錄 ");

printf(" 0.退出系統(tǒng) ");

printf(" 選擇序號0-6:" );

scanf("%d",&num);

if(num>=0&&num<=6)

{

switch(num)

{ case 1:create();break;

case 2:append();break;

case 3:search();break;

case 4:modify();break;

case 5:del();break;

case 6:output();break;

case 0:exit(1);

}

printf(" 操作完畢,請再次選擇! ");

}

else

printf(" 選擇錯誤,請再次選擇! ");

}

getch();

return 0;

}

/*創(chuàng)建記錄*/

void create()

{

struct student stu;

if((fp=fopen(filename,"w"))==NULL)

{

printf("Cannot Open File! ");

exit(0);

}

fprintf(fp,"%-10s%-20s%-50s ","學號","姓名","成績");

printf(" 請輸入學號、姓名及成績(以0結束) ");

scanf("%s",stu.no);

while(strcmp(stu.no,"0"))

{

scanf("%s %d",stu.name,&stu.score);

fprintf(fp,"%-10s%-20s%-50d ",stu.no,stu.name,stu.score);

scanf("%s",stu.no);

}

fclose(fp);

}

/*添加記錄*/

void append()

{

struct student stu;

if((fp=fopen(filename,"a"))==NULL)

{

printf(" Cannot Open File!");

exit(0);

}

printf(" 請輸入要添加的學號、姓名及成績 ");

scanf("%s%s%d",stu.no,stu.name,&stu.score);

fprintf(fp,"%-10s%-20s%-50d ",stu.no,stu.name,stu.score);

fclose(fp);

}

/*查找記錄*/

void search()

{

int k=0;

char nokey[10];

struct student stu;

printf(" 請輸入學號:");

scanf("%s",nokey);

if((fp=fopen(filename,"r"))==NULL)

{

printf(" Cannot Open File!");

exit(0);

}

fseek(fp,1L*sizeof(struct student),0);

while(!feof(fp))

{

fscanf(fp,"%s%s%d",stu.no,stu.name,&stu.score);

if(strcmp(nokey,stu.no)==0)

{

printf(" 已查找到,該記錄為: ");

printf("%-10s%-20s%-50s","學號","姓名","成績");

printf("%-10s%-20s%-50d",stu.no,stu.name,stu.score);

k=1;

}

}

if(!k)

printf(" 文件中無此人的記錄。");

fclose(fp);

}

/*修改記錄*/

void modify()

{

int k=0;

long position;

char nokey[10];

struct student stu;

printf(" 請輸入學號:");

scanf("%s",nokey);

if((fp=fopen(filename,"r+"))==NULL)

{

printf(" Cannot Open File!");

exit(0);

}

fseek(fp,1L*sizeof(struct student),0);

while(!feof(fp))

{

fscanf(fp,"%s%s%d",stu.no,stu.name,&stu.score);

if(strcmp(nokey,stu.no)==0)

{ position=ftell(fp);

k=1;

break;

}

}

if(k)

{

printf(" 已查找到,該記錄為: ");

printf("%-10s%-20s%-50s","學號","姓名","成績");

printf("%-10s%-20s%-50d",stu.no,stu.name,stu.score);

printf(" 請輸入新的學號、姓名及成績:");

scanf("%s%s%d",stu.no,stu.name,&stu.score);

fseek(fp,position-1L*sizeof(struct student),SEEK_SET);

fprintf(fp," %-10s%-20s%-50d",stu.no,stu.name,stu.score);

}

else

printf(" 文件中無此人的記錄。");

fclose(fp);

}

/*刪除記錄*/

void del()

{

int m,k=0;

long position;

char nokey[10];

struct student stu;

printf(" 請輸入學號:");

scanf("%s",nokey);

if((fp=fopen(filename,"r+"))==NULL)

{

printf(" Cannot Open File!");

exit(0);

}

fseek(fp,1L*sizeof(struct student),0);

while(!feof(fp))

{

fscanf(fp,"%s%s%d",stu.no,stu.name,&stu.score);

if(strcmp(nokey,stu.no)==0)

{ position=ftell(fp);

k=1;

break;

}

}

if(k)

{

printf(" 已查找到,該記錄為: ");

printf("%-10s%-20s%-50s","學號","姓名","成績");

printf("%-10s%-20s%-50d",stu.no,stu.name,stu.score);

printf(" 確實要刪除記錄,請按1;不刪除記錄,請按0:");

scanf("%d",&m);

if(m)

{

fseek(fp,position-1L*sizeof(struct student),SEEK_SET);

fprintf(fp,"%-10s%-20s%-50s","","","");

}

}

else

printf(" 文件中無此人的記錄。");

fclose(fp);

}

/*顯示記錄*/

void output()

{

struct student stu;

if((fp=fopen(filename,"r"))==NULL)

{

printf(" Cannot Open File!");

exit(0);

}

printf(" 文件內容為: ");

fseek(fp,1L*sizeof(struct student),0);

while(!feof(fp))

{

fscanf(fp,"%s%s%d ",stu.no,stu.name,&stu.score);

printf("%-10s%-20s%-50d",stu.no,stu.name,stu.score);

}

fclose(fp);

}

總結

以上是生活随笔為你收集整理的c语言在管理系统中的应用,C语言应用——学生管理系统的制作的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。