#include<stdio.h>
#include<iostream.h>
#define N 10
using namespace std;
struct stud
{
char sno[12];
char name[10];
char home[20];
char sc[20];
int bCome;
float score;
};
stud temp[N];
int number=0;
///////////////////////////////////////
int input()
{
stud temp;
FILE *fp;
printf("輸入學生信息:(輸入結束在學號處輸over)\n");
if((fp=fopen("stud.dat","wb"))==NULL)
{
printf("文件打開失敗!");
exit(0);
}
while(1)
{
printf("輸入學生雪號:");
scanf("%s",temp.sno);
if(!strcmp(temp.sno,"over"))
{fclose(fp);return 0;}
printf("輸入學生姓名:");
scanf("%s",temp.name);
printf("輸入學生住址:");
scanf("%s",temp.home);
printf("輸入學生專業:");
scanf("%s",temp.sc);
printf("輸入高考分數:");
scanf("%f",&temp.score);
temp.bCome=0;
fwrite(&temp,sizeof(temp),1,fp);
}
fclose(fp);
}
//////////////////////////////////////
/////////////////////////////////////
void write()
{
int i=0;
FILE *fp;
if((fp=fopen("stud.dat","wb"))==NULL)
{
printf("文件打開失敗!");
exit(0);
}
while(temp[i].sno!=NULL)
{
fwrite(&temp[i],sizeof(temp),1,fp);
i++ ;
}
}
/////////////////////////////////////
int change()
{
printf("輸入新到學生的學生號:");
char buffer_no[12];
char buffer_sc[20];
scanf("%s",buffer_no);
int i=0;
while(strcmp(buffer_no,temp[i].sno)==0) i++;
cout<<i<<endl;
if(i>=N) {printf("沒有要找的學號");return 0;}
else
{
printf("you");
printf("所換專業:");
scanf("%s",buffer_sc);
strcpy(temp[i].sc,buffer_sc);
}
}
/////////////////////////////////////
void search()
{}
//////////////////////////////////////
void set()
{
}
////////////////////////////////////////
void showStu()
{
FILE *fp;
int i=0;
if((fp=fopen("stud.dat","rb"))==NULL){printf("文件打開失敗!");exit(0);}
printf("學號 姓名 住址 專業 分數 到校否\n");
while(fread(&temp[i],sizeof(stud),1,fp)!=0)
{
printf("%s %s %s %s %.2f %d\n",temp[i].sno,temp[i].name,
temp[i].home,temp[i].sc,temp[i].score,temp[i].bCome);
i++;
}
}
////////////////////////////////////////
void server(int menu)
{
switch(menu)
{
case 1:input();break;
case 2:set();break;
case 3:search();break;
case 4:change();break;
case 5:showStu();break;
case 0:exit(0);break;
}
}
////////////////////////////////////////
void showWND()
{ int menu=-1;
while(1)
{
printf("新生報道系統\n");
printf("1、錄入新生信息\n");
printf("2、新生報道\n");
printf("3、查詢未到新生\n");
printf("4、學生轉專業\n");
printf("5、按學號顯示學生信息\n");
printf("0、退出\n");
printf("輸入服務類型:");
scanf("%d",&menu);
server(menu);
}
}
void main()
{
showWND();
}