本文目錄一覽:
- 1、用c語言製作學生檔案管理系統
- 2、c語言課程設計–班級檔案管理系統
- 3、用C語言設計學生檔案管理
- 4、求C語言學生檔案管理界面的源代碼
- 5、c語言學生檔案管理系統要全面的,無錯的
- 6、編寫一個c語言程序,實現錄入學生學號和姓名信息的功能
用c語言製作學生檔案管理系統
我以前做的
給你了
#includestdio.h
#includestdlib.h
#includestring.h
struct student
{char name[30];
char number[20];
char sex[10];
char nation[10];
char address[60];
char born[20];
char family[60];
char course[60];
int sign;
struct student *next;
}record;
struct student *head;
static int n;
int menu_select(),i;
void enter();
void delete();
void search();
void group();
void change();
void savefile();
void openfile();
main()
{char s[80],choice;
head=NULL;
for(;;)
switch(menu_select())
{case 1:enter();break;
case 2:delete();break;
case 3:search();break;
case 4:change();break;
case 5:group();break;
case 6:savefile();break;
case 7:openfile();break;
case 8:exit(0);
}
}
void group()
{struct student *p,*p1;
int j=1;
p1=head;
printf(“\nyou can know every student’s main information from this\n”);
do
{printf(“Sign number:%4d. Name:%10s. Number:%8s. Sex:%4s. Nation:%4s. Born:%6s\n”,p1-sign,p1-name,p1-number,p1-sex,p1-nation,p1-born);
p1=p1-next;j++;
}while(p1-name!=0);
}
int menu_select()
{char s[80];
int n;
printf(“1—-Enter a name\n”);
printf(“2—-Delete arecord\n”);
printf(“3—-Search\n”);
printf(“4—-Change\n”);
printf(“5—-Group\n”);
printf(“6—-savefile\n”);
printf(“7—-openfile\n”);
printf(“8—-Quit\n”);
do
{printf(“please input you choice:\n”);
gets(s);
n=atoi(s);
}
while(n1||n8);
return(n);
}
void enter()
{struct student *info;
void circle();
float a;
for(n=0;;n++)
{info=(struct student *)malloc(sizeof(record));
if(info==NULL)
{printf(“\n Out of memory”);
return;
}
getchar();
printf(“enter name:”);
gets(info-name);
if(info-name[0]==’0′)
{info-next=0;break; }
else
{
printf(“enter number:”);
gets(info-number);
printf(“enter Sex:”);
gets(info-sex);
printf(“enter nation:”);
gets(info-nation);
printf(“enter Address:”);
gets(info-address);
printf(“enter Born date:”);
gets(info-born);
printf(“enter Family:”);
gets(info-family);
printf(“enter Course:”);
gets(info-course);
printf(“enter Sign number:”);
scanf(“%d”,info-sign);
circle(info);
}
}
}
void circle(struct student *info)
{ struct student *p2,*p1,*p0;
p1=head;
p0=info;
if(head==NULL)
{head=p0;p0-next=NULL;}
else
{while((p0-signp1-sign)(p1-next!=NULL))
{p2=p1;
p1=p1-next;}
if(p0-signp1-sign)
{if(head==p1)head=p0;
else p2-next=p0;
p0-next=p1;}
else
{p1-next=p0;p0-next=NULL;}
}
}
void display(info)
struct student *info;
{printf(“Name:%s\n”,info-name);
printf(“Number:%s\n”,info-number);
printf(“Sex:%s\n”,info-sex);
printf(“Nation:%s\n”,info-nation);
printf(“Address:%s\n”,info-address);
printf(“Born date:%s\n”,info-born);
printf(“Family:%s\n”,info-family);
printf(“Course:%s\n”,info-course);
printf(“Sign number:%d\n”,info-sign);
printf(“\n\n”);
}
void search()
{char name[40],street[30],s[30],t[30];
struct student *info,*find();
printf(“you want by what to find name? number? sign(_number)?”);
gets(t);
printf(“\n input please:”);
gets(s);
if((info=find(s))==NULL)
printf(“not found\n”);
else display(info);
}
struct student *find(char *s)
{
struct student *info;
info=head;
while(info)
{if((!strcmp(s,info-name))||(!strcmp(s,info-number))||(!strcmp(s,info-sign)))
return(info);
else
info=info-next;
}
return(info);
}
void delete()
{char s[80];
struct student *p1,*p2,*info;
printf(“enter name:”);
gets(s);
info=find(s);
if(info!=NULL)
{
if(head==info)
{
head=info-next;
printf(“delete:%s\n”,info-name);
free(info);
}
else
{p2=head;
p1=head-next;
while(info!=p1)
{p2=p1;p1=p1-next;}
p2-next=p1-next;
printf(“delete:%s\n”,info-name);
free(info);
}
}else
printf(“%s not found!\n”,info-name);
}
void change()
{char s[30],a[30];
float sum,b;
int i;
struct student *p;
printf(“enter name:”);
gets(s);
p=find(s);
if(p!=NULL)
{printf(“what you want to change:\n name? number? sex? nation? born? family? course?”);
gets(a);
printf(“please enter %s:”,a);
if(strcmp(a,”name”)==0)
scanf(“%s”,p-name);
if(strcmp(a,”number”)==0)
scanf(“%s”,p-number);
if(strcmp(a,”sex”)==0)
scanf(“%s”,p-sex);
if(strcmp(a,”nation”)==0)
scanf(“%s”,p-nation);
if(strcmp(a,”born”)==0)
scanf(“%s”,p-born);
if(strcmp(a,”family”)==0)
scanf(“%s”,p-family);
if(strcmp(a,”course”)==0)
scanf(“%s”,p-course);
circle(p);
}
}
void savefile()
{struct student *p;
FILE *fp;
p=head;
fp=fopen(“xue.c”,”wb”);
printf(“saving …”);
while(head)
{
fwrite(head,sizeof(record)-2,1,fp);
head=head-next;
}
fclose(fp);
printf(“\n the file has been saved\n”);
}
void openfile()
{FILE *fp;
struct student *back,*next;
fp=fopen(“xue.c”,”rb”);
printf(“loading …”);
head=back=next=(struct student *)malloc(sizeof(record));
while(fread(next,sizeof(record)-2,1,fp)==1)
{
back=next;
next=(struct student *)malloc(sizeof(record));
back-next=next;
}
free(next);
back-next=NULL;
printf(“\nfile has been opened\n”);
}
c語言課程設計–班級檔案管理系統
//****************************************************************************
//**** 說明:密碼所在的文件位於c盤,文件名為1.txt。
//**** 學生基本信息最好保存在C盤,文件名為student.txt。
//****************************************************************************
#include stdio.h
#include stdlib.h
#include string.h
#include conio.h
#define N 3
struct student
{
char name[10];
char no[10];
char sex;
int age;
char bnote[100];
};
void print(bool menu)//打印基本信息
{
if (!menu)
{
printf(“學生基本信息錄入 ,press 1\n”);
}
else
{
printf(“學生基本信息顯示 ,press 2\n”);
printf(“學生基本信息保存 ,press 3\n”);
printf(“學生基本信息刪除 ,press 4\n”);
printf(“學生基本信息修改 ,press 5\n”);
printf(“學生基本信息查詢 ,press 6\n”);
}
printf(“退出學生信息系統 ,press 7\n”);
}
bool Check(char pas[6])//密碼驗證
{
FILE *fp;
char ch;
char a[7]={” “};
int i = 0;
if ((fp=fopen(“c:\\1.txt”,”r”))==NULL)
{
printf(“打開文件失敗!\n”);
exit(0);
}
ch=fgetc(fp);
while (ch!=EOFi6)
{
a[i] = ch;
ch=fgetc(fp);
i++;
}
a[6] = ‘\0’;
if (!strcmp(pas,a))
{
return true;
}
else
{
printf(“密碼錯誤\n”);
return false;
}
fclose(fp);
}
void GetInfo(struct student *arr,int n)//學生基本信息錄入
{
for (int i = 0;in;i++)
{
printf(“輸入學生的基本信息:name no sex age bnote\n”);
scanf(“%s %s %c %d %s”,arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
}
}
void Display(struct student* arr,int n)//學生基本信息顯示
{
printf(“學生信息: Name NO Sex age Note\n”);
for (int i = 0;in;i++)
{
printf(“%15s%15s%15c%15d%15s\n”,arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
}
}
void Save(struct student* arr,int n)//學生基本信息保存,保存在c:\\student.txt
{
FILE * fp;
fp= fopen(“c:\\student.txt”,”w+”);
if (fp == NULL)
{
printf(“文件不存在!\n”);
exit(0);
}
fwrite(arr,sizeof(struct student)*n,n,fp);
fclose(fp);
}
void Modfiy(struct student* arr,int n)//學生基本信息修改
{
char number[10];
bool flag=false;
char pass[6];
printf(“請輸入密碼:\n”);
scanf(“%s”,pass);
if (Check(pass))
{
printf(“修改學生信息:\n”);
printf(“請輸入學號:\n”);
scanf(“%s”,number);
for (int i =0;in;i++)
{
if (!strcmp(number,arr[i].no))
{
printf(“infor: name no sex age note\n”);
printf(“%12s%12s%12c%12d%12s\n”,arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
printf(“please input information:\n”);
scanf(“%s%s%c%d%s”,arr[i].name,arr[i].no,arr[i].sex,arr[i].age,arr[i].bnote);
Save(arr,n);
flag = true;
}
}
if (flag == false)
{
printf(“該學生不存在!:\n”);
}
}
}
void Delete(struct student* arr,int n)//學生基本信息刪除
{
char number[10];
bool flag=false;
printf(“Delete information:\n”);
printf(“please input the no:\n”);
scanf(“%s”,number);
for (int i =0;in;i++)
{
if (!strcmp(number,arr[i].no))
{
strcpy(arr[i].name,” “);
strcpy(arr[i].no,” “);
strcpy(arr[i].bnote,” “);
arr[i].sex = ‘ ‘;
arr[i].age = 0;
Save(arr,n);
flag = true;
}
}
if (flag == true)
{
printf(“該學生不存在!:\n”);
}
}
void Search(struct student* arr,int n)//學生基本信息查詢
{
int temp,i;
bool flag=false;
printf(“—————通過學號查詢,press 1————-\n”);
printf(“—————通過姓名查詢,press 2———–\n”);
printf(“—————通過性別查詢,press 3————\n”);
printf(“—————通過年齡查詢,press 4————\n”);
printf(“—————退出,press 5 ————\n”);
scanf(“%d”,temp);
switch (temp)
{
case 1://按照學號查詢
{
char num[10];
printf(“請輸入學號:\n”);
scanf(“%s”,num);
for ( i =0;in;i++)
{
if (!strcmp(num,arr[i].no))
{
printf(“%12s%12s%12c%12d%12s\n”,arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf(“該學生不存在.\n”);
}
}
break;
case 2://按照名字查詢
{
char num[10];
printf(“please input name:\n”);
scanf(“%s”,num);
for ( i =0;in;i++)
{
if (!strcmp(num,arr[i].name))
{
printf(“%12s%12s%12c%12d%12s”,arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf(“該學生不存在.\n”);
}
}
break;
case 3://按照性別查詢
{
char ch;
printf(“請輸入性別:\n”);
//scanf(“%c”,ch);
ch = getch();
for ( i =0;in;i++)
{
if (ch == arr[i].sex)
{
printf(“%12s%12s%12c%12d%12s\n”,arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf(“t該學生不存在.\n”);
}
}
break;
case 4://按照年齡查詢
{
char num_age;
printf(“請輸入年齡:\n”);
scanf(“%d”,num_age);
for ( i =0;in;i++)
{
if (num_age == arr[i].age)
{
printf(“%12s%12s%12c%12d%12s\n”,arr[i].name,arr[i].no,
arr[i].sex,arr[i].age,arr[i].bnote);
flag = true;
}
}
if (!flag)
{
printf(“該學生不存在.\n”);
}
}
break;
default:
break;
}
}
void main()
{
struct student arr[N];
char ps[6];
bool flag =false;
printf(“請輸入密碼:\n”);
scanf(“%s”,ps);
flag = Check(ps);
if (flag)
{
int select;
print(false);
scanf(“%d”,select);
while (0select select 7 )
{
switch (select)
{
case 1:
GetInfo(arr,N);
print(true);
break;
case 2:
Display(arr,N);
print(true);
break;
case 3:
Save(arr,N);
print(true);
break;
case 4:
Delete(arr,N);
print(true);
break;
case 5:
Modfiy(arr,N);
print(true);
break;
case 6:
Search(arr,N);
print(true);
break;
default:
break;
}
printf(“請選擇:\n”);
scanf(“%d”,select);
}
}
}
用C語言設計學生檔案管理
/*用C語言設計學生檔案管理
1. 題目描述
編寫一個程序來管理學生檔案,系統能實現以下功能:
輸入信息:學生信息的輸入;
修改信息:對學生信息進行添加、刪除與修改;
查詢:能夠根據學號或姓名查詢某個學生的信息;
輸出:輸出所有學生信息或查詢學生信息的結果。
2. 設計提示
1)先確定學生檔案管理的數據結構。如每個學生信息:學號、姓名、性別、年齡、地址 ……等,每個數據項各用什麼數據類型;
2)劃分實現學生檔案管理的功能模塊:如主菜單、輸入數據、修改、查詢、輸出等功能,並確定各功能模塊的實現算法。
3)畫出各模塊的流程圖或S-R圖;
4)選擇C語言的技術:普通數組、結構體數組、函數、指針、單鏈表或文件等。
5)編寫程序代碼。*/
#includestdio.h
#includestdlib.h
#includestring
typedef struct student{
char ID[10];
char name[10];
char sex[3];
int age;
char addr[30];
struct student *next;
}stu;
void Input(stu *head)
{
stu *temp,*current;
temp=(stu *)malloc(sizeof(stu));
printf(“輸入學生信息:\n”);
printf(“學號\t姓名\t性別\t年齡\t地址\t\n”);
fflush(stdin);
scanf(“%s%s%s%d%s”,temp-ID,temp-name,temp-sex,temp-age,temp-addr);
temp-next=NULL;
if(head==NULL)
{head=(stu *)malloc(sizeof(stu));head-next=temp;}
else
{
current=head-next;
while(current-next)
current=current-next;
current-next=temp;}
printf(“添加成功\n”);
system(“pause”);
}
void FindByID(stu *head)
{
if(head==NULL)
{printf(“數據為空\n”);
system(“pause”);return ;}
else
{stu *current =head-next;
bool flag=0;
char a[10];
printf(“輸入要查詢的學號:\n”);
fflush(stdin);
scanf(“%s”,a);
do
{
if(strcmp(current-ID,a)==0)
{flag=1;break;}
current=current-next;
}while(current!=NULL);
if(flag)
{
printf(“學號:%s 姓名:%s 性別:%s 年齡:%d 地址:%s\n”,current-ID,current-name,current-sex,current-age,current-addr);
system(“pause”);
}
else
{
printf(“沒有找到\n”);
system(“pause”);
}
}
}
void FindByName(stu *head)
{
if(head==NULL)
{printf(“數據為空\n”);
system(“pause”);return ;}
else
{
stu *current =head-next;
bool flag=0;
char a[10];
printf(“輸入要查詢的姓名:\n”);
fflush(stdin);
scanf(“%s”,a);
do
{
if(strcmp(current-name,a)==0)
{flag=1;break;}
current=current-next;
}while(current!=NULL);
if(flag)
{
printf(“學號:%s 姓名:%s 性別:%s 年齡:%d 地址:%s\n”,current-ID,current-name,current-sex,current-age,current-addr);
system(“pause”);
}
else
{
printf(“沒有找到\n”);
system(“pause”);
}
}
}
void Delete(stu *head)
{
if(head==NULL)
{printf(“數據為空\n”);
system(“pause”);return ;}
else
{ stu *current =head-next;
stu *prev=NULL;
char a[10];
printf(“輸入要刪除的學號:\n”);
fflush(stdin);
scanf(“%s”,a);
while(current!=NULL)
{
if(strcmp(current-ID,a)==0)break;
prev=current;
current=current-next;
}
if(prev==NULL)
{head-next=current-next;free(current);}
else
{prev-next=current-next;
free(current);}
printf(“刪除成功\n”);
system(“pause”);
}
}
void Show(stu *head)
{
stu *current =head-next;
if(current==NULL)
{printf(“數據為空\n”);
system(“pause”);return ;}
printf(“學號\t姓名\t性別\t年齡\t地址\t\n”);
while(current!=NULL)
{
printf(“%s\t%s\t%s\t%d\t%s\n”,current-ID,current-name,current-sex,current-age,current-addr);
current=current-next;
}
system(“pause”);
}
void Modify(stu *head)
{
if(head==NULL)
{printf(“數據為空\n”);
system(“pause”);return ;}
bool flag=0;
char a[10];
printf(“輸入要查詢的學號:\n”);
fflush(stdin);
scanf(“%s”,a);
stu *current=head-next;
do
{
if(strcmp(current-ID,a)==0)
{flag=1;break;}
current=current-next;
}while(current!=NULL);
if(flag)
{
printf(“學號:%s 姓名:%s 性別:%s 年齡:%d 地址:%s\n”,current-ID,current-name,current-sex,current-age,current-addr);
printf(“請重新輸入該學生信息:\n”);
printf(“學號\t姓名\t性別\t年齡\t地址\t\n”);
scanf(“%s%s%s%d%s”,current-ID,current-name,current-sex,current-age,current-addr);
printf(“修改成功\n”);
printf(“pause”);
}
else
{
printf(“沒有找到\n”);
system(“pause”);
}
}
void Print()
{
system(“cls”);
printf(” 請選擇功能(按0退出)\n”);
printf(” 1——添加學生\n”);
printf(” 2——通過學號查詢學生\n”);
printf(” 3——通過姓名查詢學生\n”);
printf(” 4——刪除學生\n”);
printf(” 5——修改學生\n”);
printf(” 6——顯示所有學生\n”);
}
int main()
{
char ch;
stu *head=NULL;
do
{
Print();
fflush(stdin);
ch=getchar();
//system(“cls”);
switch(ch)
{
case ‘1’:Input(head);break;
case ‘2’:FindByID(head);break;
case ‘3’:FindByName(head);break;
case ‘4’:Delete(head);break;
case ‘5’:Modify(head);break;
case ‘6’:Show(head);break;
}
}while(ch!=’0′);
}
求C語言學生檔案管理界面的源代碼
# includeiostream.h
# includestring.h
# includestdio.h
# includestdlib.h
# includefstream.h
//*****定義一個學生原子的的數據結構*****//
struct stuatom
{
char *name;
int id;
char sex;
float math, eng, comp, totll, aver;
void show();
void setup();
};
//*********定義一系列對學生的操作**********//
class student
{
private:
stuatom ob[100];
int stulen;
public:
student();
void input();
void order();
void save();
void Query();
void read();
void add();
void del();
};
//********對學生數據的初始化(類的構造函數)**********//
student::student()
{
//用for循環對全部數組中的數據初始化
for(int i=0;i100;i++)
{
ob[i].math=ob[i].eng=ob[i].comp =ob[i].totll =ob[i].aver =0;
ob[i].id =0;
ob[i].sex =’ ‘;
ob[i].name =NULL;
}
this-stulen =0;
}
//********輸入學生的數據,並判斷是否在規定數據域內*******//
void stuatom::setup()
{
char n[20]; char s;
int b;
//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
do {
cout” 學號: “;
cinb;
if(b1020||b1001)
cout”Bad data input!!”endlendl;
}while (b1001||b1020);
id=b;
//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
do{
name=new char[strlen(n)+1];
cout” 姓名: “;
cinn;
if( strlen(n)6 || strlen(n)4 )
cout”Bad data input!!”endlendl;
}while ( strlen(n)6 strlen(n)4 );
strcpy(name,n);
cout” 性別(m/f):” ;
cins;
//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (s!=’m’ s!=’f’)
{
cout”Bad data input!!”endlendl;
cout” 性別(m/f):”;
cins;
}
sex=s;
float m, e, co;
cout” 數學: “;
cinm;
//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (m0 || m100)
{
cout”Bad data input!!”endlendl;
cout” 數學: “;
cinm;
}
math=m;
cout” 英語: “;
cine;
//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (e0 || e100)
{
cout”Bad data input!!”endlendl;
cout” 英語: “;
cine;
}
eng=e;
cout” 計算機: “;
cinco;
//如果輸入學好在數據域內,跳出循環並且賦值。
//如果不再數據域內,一直循環到輸入數據符合數據域為止
while (co0 || co100)
{
cout”Bad data input!!”endlendl;
cout” 計算機: “;
cinco;
}
comp=co;
totll=math+eng+comp;
aver=(math+eng+comp)/3;
}
//*******按照規定格式把該學生的數據顯示在屏幕上******//
void stuatom::show()
{
cout.setf(ios::left);
cout.width(6);
cout””id” “;
cout.width(8);
coutname;
cout.width(10);
coutsex;
cout.width(9);
coutmath;
cout.width(9);
couteng;
cout.width(11);
coutcomp;
cout.width(10);
couttotllaverendl;
}
//**************輸入學生的數據***********************//
void student::input()
{
int n;
coutendl”輸入將要錄入的學生數目: “;
cinn;
int j;
//通過循環輸入要求輸入學生個數的學生的數據。
for(j=0; jn; j++)
{
cout” 輸入學生信息 “jendl;
ob[j].setup();
}
this-stulen=n; //學生個數賦值
//學生數據顯示格式
system(“cls”);
coutendl”—————————– 學生信息表 ————————————“endl;
coutendl” 學號 姓名 性別 數學 英語 計算機 總分 平均分”endl;
//通過循環輸出所有學生數據。
for(j=0; jn; j++)
{
ob[j].show();
}
coutendl;
cout” 是否保存? (Y/N): “;
char Y;
cinY;
system(“cls”);
}
//**************按照一定格式顯示所要查詢學生的信息。**************//
void student::Query()
{
int x , i;
coutendl” 輸入要查詢學生的學號: “;
cinx;
coutendl” 學號 姓名 性別 數學 英語 計算機 總分 平均分”endl;
for(i=0;i=this-stulen ;i++)
{ if (x==ob[i].id)
{
cout.setf(ios::left);
cout.width(6);
cout””ob[i].id” “;
cout.width(8);
coutob[i].name;
cout.width(10);
coutob[i].sex;
cout.width(9);
coutob[i].math;
cout.width(9);
coutob[i].eng;
cout.width(11);
coutob[i].comp;
cout.width(10);
coutob[i].totllob[i].averendl;
}
}
getchar();
}
//*******************保存學生數據**************************//
void student::save()
{
int i;
ofstream outfile;
outfile.open(“list.txt”,ios::trunc);
if(!outfile)
{
cout”Cannot open output file!\n,”;
}
//通過循環把所有的學生數據保存在list.txt裡邊。
for(i=0; ithis-stulen; i++)
{
outfileob[i].id” “ob[i].name” “ob[i].sex” “
ob[i].math” “ob[i].eng” “ob[i].comp” “ob[i].totll” “ob[i].averendl;
}
outfile.close();
}
//*************顯示所有學生數據*********************//
void student::read()
{
int i;
system(“cls”);
coutendl”—————————– 學生信息表 ————————————“endl;
coutendl” 學號 姓名 性別 數學 英語 計算機 總分 平均分”endl;
for(i=0; ithis-stulen; i++)
{
ob[i].show();
}
getchar();
}
//*******************一個學生的數據****************//
void student::add()
{
int i, d=this-stulen ;
cout”輸入要添加學生的信息:”endl;
ob[d].setup();
coutendl”—————————– 學生信息表 ————————————“endl;
coutendl” 學號 姓名 性別 數學 英語 計算機 總分 平均分”endl;
for(i=0; i=d; i++)
{
ob[i].show();
}
ofstream fout(“list.txt”,ios::app);
if(!fout)
{
cout”Cannot open output file!\n,”;
}
//把添加的學生數據添加到list.txt裡邊去。
foutob[d].id” “ob[d].name” “ob[d].sex” “
ob[d].math” “ob[d].eng” “ob[d].comp” “ob[d].totll” “ob[d].averendl;
fout.close();
getchar();
}
//*********************刪除指定名字學生的數據*******************//
void student::del()
{
int i,p; char x[8];
cout” 輸入要刪除學生名字:”endl;
cinx;
//通過for循環查找要刪除學生的姓名
for(i=0; istulen; i++)
{
if(strcmp(ob[i].name,x)==0)
{
p=i;
coutendl”學號 姓名 性別 數學 英語 計算機 總成績 平均成績”endl;
coutob[i].id” “ob[i].name” “ob[i].sex” “ob[i].math” “ob[i].eng” “ob[i].comp” “ob[i].totll” “ob[i].averendl;
break;
}
else
continue;
}
coutendl”—————————– 學生信息表 ————————————“endl;
coutendl” 學號 姓名 性別 數學 英語 計算機 總分 平均分”endl;
//刪除了之後,應該把後面的數據往前移,把要刪除的數據覆蓋,並且學生長度減1
stulen–;
for(i;istulen;i++)
{
ob[i]=ob[i+1];
}
this-read ();
cout” 刪除成功!”endl;
getchar();
}
//***********把學生成績排序******************//
void student::order()
{
int k,j;
float t; char n[20];
//排序算法。
for(j = 0; j=(2-1); j++)
{
for(k=1; k=(2-j); k++)
{
if(ob[k].totll ob[k + 1].totll)
{
t = ob[k].totll;
ob[k].totll = ob[k+1].totll;
ob[k+1].totll = t;
strcpy(n, ob[k].name);
strcpy(ob[k].name, ob[k+1].name);
strcpy(ob[k+1].name, n);
}
cout” 成績排名:”endl;
cout” 姓名 總成績 名次”endl;
for(k=0; k=stulen; k++)
{
cout” “;
cout.setf(ios::left);
cout.width(9);
coutob[k].name;
cout.width(9);
coutob[k].totllkendl;
}
getchar();
}
}
}
//********************選擇菜單。*****************//
void menu()
{
cout”\n\n”;
cout”—————— 學生成績系統 —————–“endlendl;
cout”\t\t1.錄入與保存學生信息.\n”;
cout”\t\t2.讀取學生信息.\n”;
cout”\t\t3.刪除學生信息.\n”;
cout”\t\t4.追加學生信息.\n”;
cout”\t\t5.查詢學生信息.\n”;
cout”\t\t6.顯示成績名次.\n”;
cout”\t\t7.退出系統……\n\n\n”;
cout”\t\t請選擇功能項: “;
}
//—————————————————————————————
void main()
{
student a;
while(1)
{
int SEL;
system(“cls”);
menu();
cinSEL;
switch(SEL)
{
case 1:
system(“cls”); a.input();a.save();break;
case 2:
system(“cls”); a.read(); break;
case 3:
system(“cls”); a.del(); break;
case 4:
system(“cls”); a.add();break;
case 5:
system(“cls”); a.Query();break;
case 6:
system(“cls”); a.order();break;
case 7:
coutendl” 按任意鍵退出…. “endl;
getchar();
exit(0);
default:
cout”Bad input!!\n”;
break;
}
}
} 我比較忙,沒有親自幫你寫,你自己改改吧,框架出來了。
c語言學生檔案管理系統要全面的,無錯的
#includestdio.h
#includestdlib.h
#includeconio.h
#includedos.h
#includestring.h
#define LEN sizeof(struct student)
#define FORMAT “%-8d%-15s%-12.1lf%-12.1lf%-12.1lf%-12.1lf\n”
#define DATA stu[i].num,stu[i].name,stu[i].elec,stu[i].expe,stu[i].requ,stu[i].sum
struct student/*定義學生成績結構體*/
{ int num;/*學號*/
char name[15];/*姓名*/
double elec;/*選修課*/
double expe;/*實驗課*/
double requ;/*必修課*/
double sum;/*總分*/
};
struct student stu[50];/*定義結構體數組*/
void in();/*錄入學生成績信息*/
void show();/*顯示學生信息*/
void order();/*按總分排序*/
void del();/*刪除學生成績信息*/
void modify();/*修改學生成績信息*/
void menu();/*主菜單*/
void insert();/*插入學生信息*/
void total();/*計算總人數*/
void search();/*查找學生信息*/
void save();/*保存函數*/
void open();/*打開函數*/
void main()/*主函數*/
{ int n;
menu();
scanf(“%d”,n);/*輸入選擇功能的編號*/
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;
case 8: save();break;
case 9: open();break;
default:break;
}
getch();
menu();/*執行完功能再次顯示菜單界面*/
scanf(“%d”,n);
}
}
void in()/*錄入學生信息*/
{ int i,m=0;/*m是記錄的條數*/
char ch[2];
FILE *fp;/*定義文件指針*/
if((fp=fopen(“data.txt”,”a+”))==NULL)/*打開指定文件*/
{ printf(“無法打開\n”);return;}
while(!feof(fp)) {
if(fread(stu[m] ,LEN,1,fp)==1)
m++;/*統計當前記錄條數*/
}
fclose(fp);
if(m==0)
printf(“沒有記錄!\n”);
else
{
system(“cls”);
show();/*調用show函數,顯示原有信息*/
}
if((fp=fopen(“data.txt”,”wb”))==NULL)
{ printf(“無法打開\n”);return;}
for(i=0;im;i++) fwrite(stu[i] ,LEN,1,fp);/*向指定的磁盤文件寫入信息*/
printf(“確認輸入:(Y/N):”);
scanf(“%s”,ch);
while(strcmp(ch,”Y”)==0||strcmp(ch,”y”)==0)/*判斷是否要錄入新信息*/
{
printf(“學號:”);scanf(“%d”,stu[m].num);/*輸入學生學號*/
for(i=0;im;i++)
if(stu[i].num==stu[m].num)
{
printf(“學號存在,輸入任意鍵繼續!”);
getch();
fclose(fp);
return;
}
printf(“姓名:”);scanf(“%s”,stu[m].name);/*輸入學生姓名*/
printf(“選修課:”);scanf(“%lf”,stu[m].elec);/*輸入選修課成績*/
printf(“實驗課:”);scanf(“%lf”,stu[m].expe);/*輸入實驗課成績*/
printf(“必修課:”);scanf(“%lf”,stu[m].requ);/*輸入必修課成績*/
stu[m].sum=stu[m].elec+stu[m].expe+stu[m].requ;/*計算出總成績*/
if(fwrite(stu[m],LEN,1,fp)!=1)/*將新錄入的信息寫入指定的磁盤文件*/
{ printf(“無法保存!”); getch(); }
else { printf(“%s 保持成功!\n”,stu[m].name);m++;}
printf(“繼續?(Y/N):”);/*詢問是否繼續*/
scanf(“%s”,ch);
}
fclose(fp);
printf(“OK!\n”);
}
void show()
{ FILE *fp;
int i,m=0;
fp=fopen(“data.txt”,”rb”);
while(!feof(fp))
{
if(fread(stu[m] ,LEN,1,fp)==1)
m++;
}
fclose(fp);
printf(“學號 姓名 選修課 實驗課 必修課 總成績\t\n”);
for(i=0;im;i++)
{
printf(FORMAT,DATA);/*將信息按指定格式打印*/
}
}
void menu()/*自定義函數實現菜單功能*/
{
system(“cls”);
printf(“\n\n\n\n\n”);
printf(“\t\t|————-學生信息管理系統———–by:zxl|\n”);
printf(“\t\t|\t 0. 退出 |\n”);
printf(“\t\t|\t 1. 錄入學生基本信息 |\n”);
printf(“\t\t|\t 2. 尋找某位學生信息 |\n”);
printf(“\t\t|\t 3. 刪除學生基本信息 |\n”);
printf(“\t\t|\t 4. 修改學生基本信息 |\n”);
printf(“\t\t|\t 5. 插入新生基本信息 |\n”);
printf(“\t\t|\t 6. 排序學生基本信息 |\n”);
printf(“\t\t|\t 7. 瀏覽全班學生信息 |\n”);
printf(“\t\t|\t 8. 保存學生信息到磁盤 |\n”);
printf(“\t\t|\t 9. 打開學生信息從磁盤 |\n”);
printf(“\t\t|———————————————–|\n\n”);
printf(“\t\t\t選擇(0-9):”);
}
void order()/*自定義排序函數*/
{ FILE *fp;
struct student t;
int i=0,j=0,m=0;
if((fp=fopen(“data.txt”,”r+”))==NULL)
{
printf(“無法打開!\n”);
return;
}
while(!feof(fp))
if(fread(stu[m] ,LEN,1,fp)==1)
m++;
fclose(fp);
if(m==0)
{
printf(“沒有記錄!\n”);
return;
}
if((fp=fopen(“data.txt”,”wb”))==NULL)
{
printf(“無法打開\n”);
return;}
for(i=0;im-1;i++)
for(j=i+1;jm;j++)/*雙重循環實現成績比較並交換*/
if(stu[i].sumstu[j].sum)
{ t=stu[i];stu[i]=stu[j];stu[j]=t;}
if((fp=fopen(“data.txt”,”wb”))==NULL)
{ printf(“無法打開\n”);return;}
for(i=0;im;i++)/*將重新排好序的內容重新寫入指定的磁盤文件中*/
if(fwrite(stu[i] ,LEN,1,fp)!=1)
{
printf(“%s 無法保存!\n”);
getch();
}
fclose(fp);
printf(“保存成功!”);
getch();
}
void del()/*自定義刪除函數*/
{FILE *fp;
int snum,i,j,m=0;
char ch[2];
if((fp=fopen(“data.txt”,”r+”))==NULL)
{ printf(“無法打開\n”);return;}
while(!feof(fp)) if(fread(stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0)
{
printf(“沒有記錄!\n”);
return;
}
printf(“請輸入學號:”);
scanf(“%d”,snum);
for(i=0;im;i++)
if(snum==stu[i].num)
break;
printf(“找到學號,刪除?(Y/N)”);
scanf(“%s”,ch);
if(strcmp(ch,”Y”)==0||strcmp(ch,”y”)==0)/*判斷是否要進行刪除*/
for(j=i;jm;j++)
stu[j]=stu[j+1];/*將後一個記錄移到前一個記錄的位置*/
m–;/*記錄的總個數減1*/
if((fp=fopen(“data.txt”,”wb”))==NULL)
{ printf(“無法打開\n”);return;}
for(j=0;jm;j++)/*將更改後的記錄重新寫入指定的磁盤文件中*/
if(fwrite(stu[j] ,LEN,1,fp)!=1)
{ printf(“無法保存!\n”);
getch();}
fclose(fp);
printf(“刪除成功!\n”);
getch();
}
void search()/*自定義查找函數*/
{ FILE *fp;
int snum,i,m=0;
char ch[2];
if((fp=fopen(“data.txt”,”rb”))==NULL)
{ printf(“無法打開\n”);return;}
while(!feof(fp)) if(fread(stu[m],LEN,1,fp)==1) m++;
fclose(fp);
if(m==0) {printf(“沒有記錄!\n”);return;}
printf(“請輸入學號:”);
scanf(“%d”,snum);
for(i=0;im;i++)
if(snum==stu[i].num)/*查找輸入的學號是否在記錄中*/
{ printf(“找到學號,顯示?(Y/N)”);
scanf(“%s”,ch);
if(strcmp(ch,”Y”)==0||strcmp(ch,”y”)==0)
{
printf(“學號 姓名 選修課 實驗課 必修課 總成績\t\n”);
printf(FORMAT,DATA);/*將查找出的結果按指定格式輸出*/
getch();
}break;
}
if(i==m) printf(“無法找到該學生!\n”);/*未找到要查找的信息*/
}
void modify()/*自定義修改函數*/
{ FILE *fp;
int i,j,m=0,snum;
if((fp=fopen(“data.txt”,”r+”))==NULL)
{ printf(“無法打開\n”);return;}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf(“無記錄!\n”);
fclose(fp);
return;
}
printf(“請輸入您要修改信息的學生的學號!\n”);
scanf(“%d”,snum);
for(i=0;im;i++)
if(snum==stu[i].num)/*檢索記錄中是否有要修改的信息*/
break;
printf(“找到學號,您可以修改!\n”);
printf(“姓名:”);
scanf(“%s”,stu[i].name);/*輸入名字*/
printf(“選修課:”);
scanf(“%lf”,stu[i].elec);/*輸入選修課成績*/
printf(“實驗課:”);
scanf(“%lf”,stu[i].expe);/*輸入實驗課成績*/
printf(“必修課:”);
scanf(“%lf”,stu[i].requ);/*輸入必修課成績*/
stu[i].sum=stu[i].elec+stu[i].expe+stu[i].requ;
if((fp=fopen(“data.txt”,”wb”))==NULL)
{ printf(“無法打開\n”);return;}
for(j=0;jm;j++)/*將新修改的信息寫入指定的磁盤文件中*/
if(fwrite(stu[j] ,LEN,1,fp)!=1)
{ printf(“無法保存!”); getch(); }
fclose(fp);
printf(“修改成功!”);
getch();
}
void insert()/*自定義插入函數*/
{ FILE *fp;
int i,j,k,m=0,snum;
if((fp=fopen(“data.txt”,”r+”))==NULL)
{ printf(“無法打開\n”);return;}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1) m++;
if(m==0) {printf(“無記錄!\n”);
fclose(fp);
getch();
return;
}
printf(“輸入要插入的位置(學號):”);
scanf(“%d”,snum);/*輸入要插入的位置*/
for(i=0;im;i++)
if(snum==stu[i].num)
break;
for(j=m-1;ji;j–)
stu[j+1]=stu[j];/*從最後一條記錄開始均向後移一位*/
printf(“現在請輸入新信息.\n”);
printf(“學號:”);
scanf(“%d”,stu[i+1].num);
for(k=0;km;k++)
if(stu[k].num==stu[i+1].num)
{
printf(“學號存在,按任意鍵繼續!”);
getch();
fclose(fp);
return;
}
printf(“姓名:”);
scanf(“%s”,stu[i+1].name);
printf(“選修課:”);
scanf(“%lf”,stu[i+1].elec);
printf(“實驗課:”);
scanf(“%lf”,stu[i+1].expe);
printf(“必修課:”);
scanf(“%lf”,stu[i+1].requ);
stu[i+1].sum=stu[i+1].elec+stu[i+1].expe+stu[i+1].requ;
if((fp=fopen(“data.txt”,”wb”))==NULL)
{ printf(“無法打開\n”);return;}
for(k=0;k=m;k++)
if(fwrite(stu[k] ,LEN,1,fp)!=1)/*將修改後的記錄寫入磁盤文件中*/
{ printf(“無法保存!”); getch(); }
fclose(fp);
printf(“插入成功!”);
getch();
}
void total()
{ FILE *fp;
int m=0;
if((fp=fopen(“data.txt”,”r+”))==NULL)
{ printf(“無法打開\n”);return;}
while(!feof(fp))
if(fread(stu[m],LEN,1,fp)==1)
m++;/*統計記錄個數即學生個數*/
if(m==0) {printf(“無記錄!\n”);fclose(fp);return;}
printf(“本班有%d個學生!\n”,m);/*將統計的個數輸出*/
show();
getch();
fclose(fp);
}
這個是成績管理系統,可行?不過都差不多,課程設計這東西很簡單的
編寫一個c語言程序,實現錄入學生學號和姓名信息的功能
1、首先創建一個c語言項目。然後右鍵頭文件,創建一個Stu的頭文件。
2、然後編寫頭文件的代碼。再將數據結構的增刪改查和結構體寫入頭文件。
3、然後在源文件中創建main源文件和Stu源文件。再main文件中寫入int mian()代碼。
4、然後在mian主函數中,寫入while語句無限循環。再寫入Init函數。
5、然後在Stu源文件的Init函數用printf語句,將學生管理系統輸出。再創建鏈表的頭節點head。
6、然後用switch函數對操作進行判斷。再執行數據結構的增刪改查功能。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/200259.html