當前位置:編程學習大全網 - 腳本源碼 - 急求c++通訊錄管理系統!限期三天!真急!

急求c++通訊錄管理系統!限期三天!真急!

這是我寫的壹個程序 麻煩妳看壹下 看能不能幫上妳的忙

#include<stdio.h>

#include<string.h>

#include<ctype.h>

#define YN {do {yes_no=getch();printf("%c",yes_no);}while(yes_no!='y'&&yes_no!='Y'&&yes_no!='n'&&yes_no!='N');}

/*判斷學號是否為空*/

#define XH {do {gets(temp.xh);}while(strcmp(temp.xh," ")==0);}

/*錄入學生的學號、班級、姓名、性別、生日、籍貫、學院*/

#define SEX {do{printf("xingbie(w for woman,m for man):\n");gets(temp.xb);}while(temp.xb[0]!='w'&&temp.xb[0]!='m');}

#define LR {printf("banji:");gets(temp.bj);printf("xingming:");gets(temp.xm); SEX printf("shengri:");gets(temp.sr);printf("jiguan:");gets(temp.jg);printf("xueyuan:");gets(temp.xy);}

/*判斷文件是否打開*/

#define PDW {if(fp==NULL) {printf("\n The file can't be opened\n");return;}}

#define PD {while(temp.xh[0]!='#'&&temp.bj[0]!='#'&&temp.xm[0]!='#'&&temp.xb[0]!='#'&&temp.sr[0]!='#'&&temp.jg[0]!='#'&&temp.xy[0]!='#');}

/*將學生的檔案放進文件fp中*/

#define GS0 {fprintf(fp,"%10s%10s%10s%10s%10s%10s%10s\n",temp.xh,temp.bj,temp.xm,temp.xb,temp.sr,temp.jg,temp.xy);}

/*如果學生的信息不為空,則將該學生的信息輸入文件fp中*/

#define PD1 {if(temp.xh[0]!='#'&&temp.bj[0]!='#'&&temp.xm[0]!='#'&&temp.xb[0]!='#'&&temp.sr[0]!='#'&&temp.jg[0]!='#'&&temp.xy[0]!='#') GS0}

/*從文件fp中接收學生的檔案信息*/

#define GS {fscanf(fp,"%10s%10s%10s%10s%10s%10s%10s\n",temp.xh,temp.bj,temp.xm,temp.xb,temp.sr,temp.jg,temp.xy);}

/*通過結構體數組接收文件fp中的學生檔案信息*/

#define GS1 {fscanf(fp,"%10s%10s%10s%10s%10s%10s%10s\n",stu[i].xh,stu[i].bj,stu[i].xm,stu[i].xb,stu[i].sr,stu[i].jg,stu[i].xy);}

/*通過結構體數組將學生信息傳送到文件fp中*/

#define GS2 {fprintf(fp,"%10s%10s%10s%10s%10s%10s%10s\n",stu[i].xh,stu[i].bj,stu[i].xm,stu[i].xb,stu[i].sr,stu[i].jg,stu[i].xy);}

#define SRW {while(feof(fp)==0){GS1 i++;n++;}} /*判斷是否已執行到文件尾,並用i,n記錄學生人數*/

#define PT {printf("%c",choose);} /*回顯所選數*/

#define PTF {printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",temp.xh,temp.bj,temp.xm,temp.xb,temp.sr,temp.jg,temp.xy);}

#define PTF1 {printf("%-10s%-10s%-10s%-10s%-10s%-10s%-10s\n",stu[i].xh,stu[i].bj,stu[i].xm,stu[i].xb,stu[i].sr,stu[i].jg,stu[i].xy);}

#define GS3 {printf("\nxuehao banji xingming xingbie shengri jiguan xueyuan \n");}

#define N 100

struct student

{char xh[10];

char bj[10];

char xm[10];

char xb[2];

char sr[10];

char jg[10];

char xy[10];

};

void menu(); /*函數聲明*/

void creat();

void refert();

void delete();

void add();

void modify();

void show();

void tongji();

void order();

void password();

main()

{ char choose,yes_no;

do

{ menu(); /*調用菜單函數*/

printf("\n\t\t please choose(1-9):");

choose=getch();

switch(choose)

{case '1':PT creat();break;

case '2':PT refert();break;

case '3':PT password();

delete();break;

case '4':PT add();break;

case '5':PT password();

modify();break;

case '6':PT show();break;

case '7':PT tongji();break;

case '8':PT order();break;

case '9':PT break;

default:printf("\n %c choose wrong!\n",choose);

}

if(choose=='9')

break;

printf("do you want to cotinue?(y/n)\n");

YN

}while(yes_no=='y'||yes_no=='Y');

}

/*制作菜單*/

void menu()

{clrscr(); /*清屏*/

printf("\n\n\n");

printf("\t\tWelcome to the student information manage system!\n");

printf("\t\t the designer--------yourname \n");

printf("\t\t *********************************\n");

printf("\t\t * please input order number *\n");

printf("\t\t * 1----------------creat *\n"); /*錄入學生檔案*/

printf("\t\t * 2----------------refer to *\n"); /*查詢學生檔案*/

printf("\t\t * 3----------------delete *\n"); /*刪除學生檔案*/

printf("\t\t * 4----------------add *\n"); /*添加學生檔案*/

printf("\t\t * 5----------------modify *\n"); /*修改學生檔案*/

printf("\t\t * 6----------------show *\n"); /*顯示學生檔案*/

printf("\t\t * 7----------------tongji *\n"); /*統計同壹個學院的學生人數*/

printf("\t\t * 8----------------order *\n"); /*學生檔案的排序*/

printf("\t\t * 9----------------exit *\n"); /*退出*/

printf("\t\t *********************************\n");

}

/*錄入學生檔案*/

void creat()

{int i=1;

struct student temp;

FILE *fp;

fp=fopen("f:\\123.txt","w"); /*以只寫方式打開文件,且測試*/

PDW

do{ clrscr();

printf(" every pace end with '#'\n ");

printf(" please input number %d information:\n",i);

printf(" xuehao:");

XH /*判斷學號是否為空*/

LR /*錄入學生的學號、班級、姓名、性別、生日、籍貫、學院*/

PD1 /*判斷學生信息是否為空,並放進文件fp中*/

i++;

} while(temp.xh[0]!='#'&&temp.bj[0]!='#'&&temp.xm[0]!='#'&&temp.xb[0]!='#'&&temp.sr[0]!='#'&&temp.jg[0]!='#'&&temp.xy[0]!='#');

fclose(fp); /*關閉文件*/

}

/*查詢學生檔案*/

void refert()

{char c,mid[10],b[10];

FILE *fp;

int flag=0,n=0;

struct student temp;

fp=fopen("f:\\123.txt","r"); /*打開文件*/

PDW

clrscr();

printf("\n which way to refetr to ?number(1) or name(2)?choose(1-2):\n");

c=getch();

if(c=='2') /*按姓名查詢*/

{ printf("\nPlease input the student's name\n");

gets(mid);

}

else if(c=='1') /*按學號查詢*/

{ printf("\nPlease input number\n");

gets(mid);

}

else { printf("Error!");

return;

}

while(feof(fp)==0)

{ GS

if(c=='1')

strcpy(b,temp.xh); /*將學生的學號復制到b中*/

else

strcpy(b,temp.xm); /*將學生的姓名復制到b中*/

if(strcmp(mid,b)==0) /*比較大小函數*/

{ if(flag==0)

{ GS3

PTF

}

flag=1;

}

n++;

}

if(n==0) printf("no list!\n"); /*已經到文件尾*/

else if(flag==0)

printf("no find\n"); /*沒有到文件尾,但沒有此人*/

}

void delete() /*刪除函數*/

{ char c,mid[10],b[10];

int n=0,i=0,k;

FILE *fp;

struct student stu[N];

fp=fopen("f:\\123.txt","r"); /*打開並測試文件*/

PDW /*判斷文件是否打開*/

SRW /*判斷是否已執行到文件尾,並用i,n記錄學生人數*/

fclose(fp);

clrscr();

printf("\nPlease input the deleting student's way\n");

printf("\n1----number,2----name please choose(1-2):");

c=getch();

if(c=='1')

{ printf("\nplease input the student's number:");

gets(mid);

}

else if(c=='2')

{ printf("\nplease input name:");

gets(mid);

}

else {printf("Error!");return;}

for(i=0;i<n;i++)

{ if(c=='1')

strcpy(b,stu[i].xh); /*將學生的學號復制到b中*/

else

strcpy(b,stu[i].xm); /*將學生的姓名復制到b中*/

if(strcmp(mid,b)==0) break; /*將要刪除的學生信息和原有的信息作比較*/

}

if(i<n)

for(k=i;k<n;k++)

stu[k]=stu[k+1];

else {printf("No the student!\n");return; }

fp=fopen("f:\\123.txt","w");

PDW

for(i=0;i<n-1;i++)

GS2 /*將學生信息傳送到文件fp中*/

fclose(fp);

}

void add() /*添加學生信息函數*/

{

char c,yes_no;

int n=0,i=0;

struct student temp,stu[N];

FILE *fp;

fp=fopen("f:\\123.txt","r");

PDW /*判斷文件是否打開*/

SRW /*判斷是否已執行到文件尾,並用i,n記錄學生人數*/

clrscr();

for(i=0;i<n;i++)

PTF1

do{ printf("\nplease input the new information:\n");

printf("xuehao:");

XH

LR

for(i=0;i<n;i++)

if(strcmp(temp.xh,stu[i].xh)==0) /*將要添加的學生學號和原有的學生學號做比較*/

{ printf("\nThe number is repeat do you want to input again(y/n)?:");

YN

putchar('\n');

break;

}

if(i==n) {stu[i]=temp;break;}

}while(yes_no=='y'||yes_no=='Y');

if(i<n&&yes_no=='n'){return;}

fp=fopen("f:\\123.txt","w");

PDW

for(i=0;i<=n;i++)

GS2 /*將學生信息傳送到文件fp中*/

fclose(fp);

}

void modify() /* 修改學生信息函數*/

{char c,yes_no;

int n=0,i=0;

struct student *find,temp,stu[N],*p;

FILE *fp;

fp=fopen("f:\\123.txt","rb"); /*打開文件*/

PDW

SRW

fclose(fp);

if(n==0)

{ printf("\n No the information!\n");return;}

clrscr();

printf("\nPlease input the number of the modifying student:");

gets(temp.xh);

for(p=stu;p<stu+n;p++)

if(strcmp(temp.xh,p->xh)==0)

{ find=p;break;} /*用find記錄要修改的學生學號*/

if(p==stu+n)

{ printf("No the person!\n");return;}

do

{ printf("\nPlease input the new student's information:\n");

printf("xuehao:");

gets(temp.xh);

XH /*判斷學號是否為空*/

LR /*錄入學生的學號、班級、姓名、性別、生日、籍貫、學院*/

for(p=stu;p<stu+n;p++)

if(strcmp(temp.xh,p->xh)==0&&p!=find)

{ printf("\nThe number is repeat, do you want to cotinue(y/n)?");

YN

putchar('\n');

break;

}

if(p==stu+n)

{ *find=temp; /*將新的學生信息賦給被修改的學生*/

break;

}

}while(yes_no=='y'||yes_no=='Y');

fp=fopen("f:\\123.txt","w");

PDW

for(i=0;i<n;i++)

GS2

fclose(fp);

}

void show() /*顯示學生信息函數*/

{int n=0,i=0;

struct student stu[N];

FILE *fp;

fp=fopen("f:\\123.txt","r");

PDW

clrscr();

GS3

SRW /*判斷是否已執行到文件尾,並用i,n記錄學生人數*/

if(n==0)

{

printf("No the student");

return;

}

else

{ for(i=0;i<n;i++)

PTF1

}

printf("\nHave %d information",n);

fclose(fp);

}

void tongji() /*統計在同壹個學院的學生人數*/

{int i=0,n=0,k=0;

char mid[10];

FILE *fp;

struct student stu[N];

fp=fopen("f:\\123.txt","r");

PDW

SRW

fclose(fp);

clrscr();

printf("\nplease input xueyuan name:");

gets(mid);

GS3

for(i=0;i<n;i++)

if(strcmp(mid,stu[i].xy)==0)

{ PTF1

k++; /*記錄符合條件的學生人數*/

}

printf("\nThere are %d students in the same university!\n",k);

}

void order() /*排序函數*/

{int i=0,n=0;

struct student stu[N],*p,*q,temp;

FILE *fp;

char c;

fp=fopen("f:\\123.txt","r");

PDW

SRW

if(n==0)

{ printf("no the student!\n");return; }

else {clrscr();

printf("\nWhich way to order ?number(1) or name(2):\n");

printf("\nPlease choose(1-2):");

c=getch();

putchar(c);

if(c=='1')

{ for(p=stu;p<stu+n-1;p++)

for(q=p+1;q<stu+n;q++)

if(strcmp(p->xh,q->xh)>0)

{ temp=*p;

*p=*q;

*q=temp;

}

}

else if(c=='2')

{

for(p=stu;p<stu+n-1;p++)

for(q=p+1;q<stu+n;q++)

if(tolower(p->xm[0])>tolower(q->xm[0])) /*按字母排序*/

{temp=*p;

*p=*q;

*q=temp;

}

}

else {printf("Error");return;}

}

printf("\n higher(1) or lower(2) order?\n"); /*按升序排(1)還是降序(2)*/

printf("\nplease choose(1-2):\n");

c=getch();

putchar(c);

if(c=='1')

{GS3

for(i=0;i<n;i++)

{PTF1

GS2 /*將學生信息傳送到文件fp中*/

}

}

else if(c=='2')

{GS3

for(i=n-1;i>=0;i--)

{PTF1

GS2

}

}

else {printf("Error");return;}

fclose(fp);

}

void password()

{char password[11]="123456",*p;

int count=0;

do

{if(count>0)

printf("Error!input again\n");

printf("please input password\n");

gets(p);

count++;

}while(strcmp(password,p)!=0&&count<3);

if(count>=3)

exit(1);

}

  • 上一篇:失戀33天 電影劇情 講的是什麽故事
  • 下一篇:冒險島 能買到的補藍藥都是多少藍的
  • copyright 2024編程學習大全網