| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 667 人关注过本帖
标题:各位大虾好``
只看楼主 加入收藏
chandy
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2005-6-20
收藏
 问题点数:0 回复次数:0 
各位大虾好``

我是刚学数据库的,近来对职工管理系统总是看不懂.非常困惑,希望那位高手给我做下解释.小弟感激不尽! #include <stdio.h> #include <conio.h> #include <string.h> #include <stdlib.h> #define N sizeof(struct teacher) FILE*fp;

struct teacher { char name[20]; char num[10]; char sex; char part[10]; char zhicheng[10]; float salary; float cost; float YF; float tax; float SF; struct teacher *next; };

struct teacher *head=NULL;

static void enforcefloat(float *p) { float f=*p; enforcefloat(&f); } void dummyFunction() { float dummyFloat; scanf("%f",&dummyFloat); printf("%f",dummyFloat); }

struct teacher *YFcount( float salary,float cost,struct teacher *p1) {

float YF; YF=salary-cost; p1->YF=YF; return (p1); };

struct teacher *taxcount(float YF,struct teacher *p1) { float tax; if(YF<1000) tax=0; else if(YF<2000) tax=(YF-1000)*0.05; else tax=(YF-2000)*0.1; p1->tax=tax; return (p1); };

struct teacher *SFcount(float YF,float tax,struct teacher *p1) { float SF; SF=YF-tax; p1->SF=SF; return (p1); };

struct teacher *create_message() { struct teacher *p1,*p2; int i; int k; printf("input the teacher's sum:"); scanf("%d",&k); head=NULL; if(k>0) ; { head=p1=p2=(struct teacher *)malloc(N); printf("input the teachers' name,cardnum,sex,part,zhicheng,salary,cost:\n"); scanf("%s %s %c %s %s %f %f", p1->name,p1->num,&p1->sex,p1->part, p1->zhicheng,&p1->salary,&p1->cost); YFcount(p1->salary,p1->cost,p1); taxcount(p1->YF,p1); SFcount(p1->YF,p1->tax,p1);

for(i=1;i<k;i++) { p1=(struct teacher *)malloc(N); fflush(stdin); scanf("%s %s %c %s %s %f %f", p1->name,p1->num,&p1->sex, p1->part,p1->zhicheng,&p1->salary,&p1->cost); YFcount(p1->salary,p1->cost,p1); taxcount(p1->YF,p1); SFcount(p1->YF,p1->tax,p1); p2->next=p1; p2=p1; } p1->next=NULL; printf("finish input!"); } return (head); }

struct teacher *output_message() { struct teacher *p1; if(head==NULL) return; else printf("\nname cardnum sex part zhicheng salary cost YF tax SF:\n"); p1=head; do { printf("%s %s %c %s %s %f %f %f %f %f\n", p1->name,p1->num,p1->sex, p1->part,p1->zhicheng, p1->salary,p1->cost,p1->YF,p1->tax,p1->SF );

p1=p1->next; }while(p1!=NULL);

printf("press any key!!"); getch(); }

struct teacher *delete_message() { struct teacher *p1,*p2; int x; char del_num[10]; char del_name[20]; char del_part[10]; char del[10]; char cpy1[10],cpy2[20]; system("cls"); system("cls"); if(head==NULL) return(NULL); else do { do { system("cls"); printf("input the teacher's messages:\n" ); printf(" *1.the teacher's card number\n" ); printf(" *2.the teacher's name and part\n" ); printf(" choice the number between 1 and2:"); fflush(stdin); scanf("%d" ,&x); switch(x) { case 1:printf("input the teacher's card number:\n" ); fflush(stdin); scanf("%s" ,del_num);break; case 2:printf("input teacher's name and part:\n" ); fflush(stdin); scanf("%s%s" ,del_name,del_part);break; } }while(x!=1&&x!=2); p2=p1=head; if(x==1) while(p1!=NULL) { strcpy(cpy1,p1->num); if(!strcmp(cpy1,del_num)) { if(p1==head) head=p1->next; else p2->next=p1->next; printf("delete successful!\n" ); free(p1); free(p1); break; } p2=p1; p1=p1->next; }

else while(p1!=NULL) { strcpy(cpy2,p1->name); strcpy(cpy1,p1->part); if(!strcmp(cpy2,del_name)&&!strcmp(cpy1,del_part)) { if(p1==head) head=p1->next; else p2->next=p1->next; printf("delete successful!\n" ); free(p1); break; } p2=p1; p1=p1->next; }

if(p1==NULL) printf("\n donot find it\n\n" ); printf ("are you continues?\n input yes or n\n"); scanf("%s",del); }while(!strcmp(del,"yes")); system("cls"); printf("delete successful!\n please press any key!:\n"); getch (); return head; }

struct teacher *insert_message() { struct teacher *p1, *p2,*p; char answer[5]; char cpy1[10],cpy2[10]; system("cls"); /*fp=fopen("teacher.txt","wb"); if(head==NULL) return(NULL); else */ do { system("cls"); p=(struct teacher *)malloc(N); printf("input name,card number,part,zhicheng,salary,cost \n"); scanf("%s %s %c %s %s %f %f", p->name,p->num,&p->sex,p->part, p->zhicheng,&p->salary,&p->cost); YFcount(p->salary,p->cost,p); taxcount(p->YF,p); SFcount(p->YF,p->tax,p);

if(head==NULL) { head=p; p->next=NULL; return ; } else { p1=p2=head; strcpy(cpy1,p1->num); strcpy(cpy2,p->num); while(strcmp(p1->num,cpy2)<0) {

p2=p1; p1=p1->next; if (p1==NULL) { break; } strcpy(cpy1,p1->num); } if(strcmp(cpy1,cpy2)>=0) { if(p1==head) { head=p; p->next=p1; } else { p2->next=p; p->next=p1; } } if(p1==NULL) { p2->next=p; p->next=NULL; } } printf("insert successful! are you continues?\n input yes or n\n"); fflush(stdin); scanf("%s",answer); system("cls"); }while(!strcmp(answer,"yes")); printf("insert successful! please press any key!:\n"); getch (); return; }

struct teacher *inquire_message() { struct teacher *p1; int x; char cpy1[10],cpy2[20]; char name_[20]; char num_[10]; char part_[10]; char answer[5]; system("cls"); printf("input the teacher's messages:\n");

system("cls"); fp=fopen("teacher.txt","wb"); if(head==NULL); else do { do { system("cls"); printf("choose the inquire form:\n"); printf(" *1.the teacher's card number \n"); printf(" *2.the teacher's name and part \n"); printf(" choice the number between 1 and 2:"); scanf("%d",&x); switch(x) { case 1:printf("input the teacher's card number:\n"); scanf("%s",num_);break; case 2:printf("input teacher's name and part:\n"); scanf("%s %s",name_,part_);break; } }while(x!=1&&x!=2); p1=head; if(x==1) while(p1!=NULL) { strcpy(cpy1,p1->num); if(!strcmp(cpy1,num_)) break; p1=p1->next; }

else while(p1!=NULL) { strcpy(cpy2,p1->name); strcpy(cpy1,p1->part); if(!strcmp(cpy2,name_)&&!strcmp(cpy1,part_)) break; p1=p1->next; } if(p1!=NULL) { printf("\n inquire teacher's messages successful!:\n"); printf("name,card number,part,zhicheng,salary,cost,YF,tax,SF:\n"); printf("%s %s %c %s %s %f %f %f %f %f",p1->name,p1->num,p1->sex,p1->part, p1->zhicheng,p1->salary,p1->cost,p1->YF,p1->tax,p1->SF) ; } else printf("\n donot find it\n\n"); printf("are you continues?\n input yes or n\n"); scanf("%s",answer); }while(!strcmp(answer,"yes")); system("cls"); printf (" please press any key!:"); getch (); return (head); }

struct teacher *revise_message() { struct teacher *p1, *p2; int x; int y; char cpy1[10],cpy2[20]; char name_[20]; char num_[10]; char part_[10]; char answer[5]; system("cls"); printf("input the teacher's messages:\n"); system("cls"); /*fp=fopen("teacher.txt","wb");*/ if(head==NULL); else do { do { system("cls"); printf("choose the inquire form:\n"); printf(" *1.the teacher's card number:\n"); printf(" *2.the teacher's name and part:\n"); printf(" choice the number between 1 and 2:"); scanf("%d",&x); switch(x) { case 1:printf("input the teacher's card number:\n"); scanf("%s",num_);break; case 2:printf("input teacher's name and part:\n"); scanf("%s%s",name_,part_);break; } }while(x!=1&&x!=2); p1=head; if(x==1) while(p1!=NULL) { strcpy(cpy1,p1->num); if(!strcmp(cpy1,num_)) break; p1=p1->next; }

else while(p1!=NULL) { strcpy(cpy2,p1->name); strcpy(cpy1,p1->part); if(!strcmp(cpy2,name_)&&!strcmp(cpy1,part_)) break; p1=p1->next; } if(p1!=NULL) { printf("\n find teacher's messages:"); printf("\n 3.name\n"); printf("\n 4.card number\n"); printf("\n 5.zhicheng\n"); printf("\n 6salary\n"); printf("\n 7.cost\n"); printf("\n choose the number between 3 and 7:\n"); scanf("%d",&y); switch(y) { case 3:printf("revise name:\n"); scanf("%s",p1->name);break;

case 4:printf("revise number:\n"); scanf("%s",p1->num);break; case 5:printf("revise zhicheng:\n"); scanf("%s",p1->zhicheng); case 6:printf("revise salary:\n"); scanf("%f",p1->salary);break; case 7:printf("revise cost:\n"); scanf("%f",p1->cost);break; } YFcount(p1->salary,p1->cost,p1); taxcount(p1->YF,p1); SFcount(p1->YF,p1->tax,p1); printf("\n reviser successful! \n") ; } else printf("\n donot find it\n\n"); printf ("are you continues?input yes or n\n"); scanf("%s",answer); }while(!strcmp(answer,"yes")); system("cls"); printf (" please press any key!:\n"); getch (); return head; }

part_income() { struct teacher *p1; float sum=0; float av=0; int i=0; char part_[10]; p1=head; printf("the part's name:\n"); scanf("%s",part_); do { if(!strcmp(p1->part,part_)) { sum+=p1->SF; i++; } p1=p1->next; }while(p1!=NULL); av=sum/i; printf( "sum=%f",sum); printf("av=%f",av); return; }

all_income() { struct teacher *p1; float sum=0; float av=0; int j=0; p1=head; do{ sum+=p1->SF; j++; p1=p1->next; }while(p1!=NULL); av=sum/j; printf( "sum=%f",sum); printf("av=%f",av); return; }

struct teacher *income_message() { int choice; clrscr(); printf(" 1.the part SF sum\n"); printf(" 2.the all SF sum\n"); printf(" choose the number between 1 and 2:"); scanf("%d",&choice); switch(choice) { case 1:part_income();break; case 2:all_income();break; } }

save_message() { struct teacher *p1=head; clrscr(); fp=fopen("teacher.txt","wb"); if(fp==NULL) { printf("building fail!\n "); getch(); return; } while(p1!=NULL) { if(fwrite(p1,sizeof(struct teacher),1,fp)!=1) { printf("write wrong!\n"); return; } p1=p1->next; } fclose(fp); printf("save successful!\n press any key!:\n"); getch(); }

openfile() { struct teacher *p1, *p2; int n=1; if((fp=fopen("teacher.txt","rb"))==NULL) { printf("donot have the teacher's messages!\n press any key:\n"); getch(); return(NULL); } p1=p2=(struct teacher *)malloc(N); if(p1==NULL) { printf("the room donot enough!!\n press any key:\n"); getch(); return(NULL); }

if(fread(p1,sizeof(struct teacher),1,fp)!=1) { printf("please create the teacher's date before!!\n press any key :\n"); getch(); return(NULL); }

if(p1->next==NULL) head=p1; else { do { if(n==1) head=p1; else p2->next=p1; n=n+1; p2=p1; if((p1=(struct teacher*)malloc(N))==NULL) { printf("the room donot enough!!\n press any key:\n"); getch(); return(NULL); } if(fread(p1,sizeof(struct teacher),1,fp)!=1) { printf("out put the messages fail!!\n press any key:\n"); getch(); return(NULL); } }while(p1->next!=NULL); p2->next =p1; } fclose(fp); return(NULL); }

main() { int choice; system("cls"); openfile(); do { printf("\n\n ****jiaoshigongziguanlixitong****\n\n"); printf(" 1.create teacher's message\n\n"); printf(" 2.output teacher's message\n\n"); printf(" 3.delete teacher's message\n\n"); printf(" 4.insert teacher's message\n\n"); printf(" 5.inquire teacher's message\n\n"); printf(" 6.revise teacher's message\n\n"); printf(" 7.count teacher's message\n\n"); printf(" 0.exit system\n"); printf(" choice the number between 0 and 7:"); fflush(stdin); scanf("%d", &choice);

switch(choice) { case 1: create_message();break; case 2: output_message();break; case 3: delete_message();break; case 4: insert_message();break; case 5: inquire_message();break; case 6: revise_message();break; case 7: income_message();break; case 0: break; } }while(choice!=0); save_message(); printf("\n jiaoshigongziyichucong!\n"); }

搜索更多相关主题的帖子: float 数据库 teacher char 
2005-06-26 15:45
快速回复:各位大虾好``
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015855 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved