大二c语言期末考试题及答案,大二C语言编程题

满意答案

dcebd7a0de6265b6ccae5ead692f1eab.png

mhdgfbb92n

2013.12.18

dcebd7a0de6265b6ccae5ead692f1eab.png

采纳率:48%    等级:12

已帮助:6748人

下面代码大部分与你那个相似,仅作参考!

/*为了调用FILE等函数 */

#include "stdio.h"

#include "conio.h"

/* 为了调用atof()等函数 */

#include "stdlib.h"

#define TRUE 1

/* 结构体声明 */

struct zhigong

{

int month;

float id;

float jbgz;

float jt;

float gt;

float bt;

float ft;

float jtbt;

float yfs;

float fz;

float cx;

float hf;

float grsds;

float yks;

float sfs;

};

/* 建立50个元素的结构体数组 */

struct zhigong zg[50];

/* 建立结构体变量 */

struct zhigong zgone;

/* 职员列表中的数量 */

int n=0;

/* 获得字符串 */

char numstr[50];

main()

{

char ch;

n=0;

/*rfile(); 使用后启动程序时系统会自动加载纪录*/

while(TRUE)

{

printf("\n");

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

printf("Welcome!Please choice(1-6) : +\n");

printf("1.Add one infomation +\n");

printf("2.Delete one infomation +\n");

printf("3.Modify one infomation +\n");

printf("4.Print out by id +\n");

printf("5.Print out all +\n");

printf("6.Save date +\n");

printf("7.Load date +\n");

printf("8.Exit +\n");

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

ch=getche();

switch(ch)

{

case '1':addone();break;

case '2':delone();break;

case '3':modone();break;

case '4':idone();break;

case '5':listall();break;

case '6':wfile();break;

case '7':rfile();break;

case '8':return;

default:printf("Sorry,please choice again!\n");

}

}

}

/*计算个人所得税*/

float tgrsds(float m)

{

float sui1,sui2,sui3;

float tmp;

sui1=0;sui2=0;sui3=0;

if(m>=5000)

{

sui1=(m-5000)*0.2;

sui2=(5000-1000)*0.1;

sui3=(1000-800)*0.05;

}

else if(m>=1000 && m<5000)

{

sui2=(m-1000)*0.1;

sui3=(1000-800)*0.05;

}

else if(m>=800 && m<1000)

{

sui3=(m-800)*0.05;

}

tmp=sui1+sui2+sui3;

return(tmp);

}

/* 添加职工的工资信息 */

addone(void)

{

printf("\n");

printf("Record NO. %d \n",n+1);

printf("Please put in month: \n");

gets(numstr);

zg[n].month=atoi(numstr);

printf("Please put in zhigongbianhao: \n");

gets(numstr);

zg[n].id=atof(numstr);

printf("Please put in jibengongzi: \n");

gets(numstr);

zg[n].jbgz=atof(numstr);

printf("Please put in jintie: \n");

gets(numstr);

zg[n].jt=atof(numstr);

printf("Please put in gangtie: \n");

gets(numstr);

zg[n].gt=atof(numstr);

printf("Please put in butie: \n");

gets(numstr);

zg[n].bt=atof(numstr);

printf("Please put in fangtie: \n");

gets(numstr);

zg[n].ft=atof(numstr);

printf("Please put in jiaotongbutie: \n");

gets(numstr);

zg[n].jtbt=atof(numstr);

zg[n].yfs=(zg[n].jbgz)+(zg[n].jt)+(zg[n].gt)+(zg[n].bt)+(zg[n].ft)+(zg[n].jtbt);

printf("Please put in fangzu: \n");

gets(numstr);

zg[n].fz=atof(numstr);

printf("Please put in chuxu: \n");

gets(numstr);

zg[n].cx=atof(numstr);

printf("Please put in huifei: \n");

gets(numstr);

zg[n].hf=atof(numstr);

zg[n].grsds=tgrsds(zg[n].yfs);

zg[n].yks=(zg[n].fz)+(zg[n].cx)+(zg[n].hf)+(zg[n].grsds);

zg[n].sfs=(zg[n].yfs)-(zg[n].yks);

n++;

}

/*删除个人纪录*/

delone(void)

{

struct zhigong tmp[50];

float zhigongid;

int j,k;

int flagfind;

flagfind=0;

k=0;

printf("\n Please put in zhigongbianhao: \n");

gets(numstr);

zhigongid=atof(numstr);

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

{

if(zg[j].id==zhigongid)

{

flagfind=1;

}

else

{

tmp[k]=zg[j];

k++;

}

}

if(flagfind==1)

{

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

{

zg[j]=tmp[j];

}

printf("\n Record deleted! \n");

n=n-1;

}

else

{

printf("\n Record not found! \n");

}

return;

}

/*修改个人纪录*/

modone(void)

{

float zhigongid;

int j;

int flagfind;

flagfind=0;

printf("\n Please put in zhigongbianhao: \n");

gets(numstr);

zhigongid=atof(numstr);

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

{

if(zg[j].id==zhigongid)

{

printf("NO.:%d\n",j);

printf("month:%d\n",zg[j].month);

printf("zhigongbianhao%10.0f\n",zg[j].id);

printf("jibengongzi:%10.2f\n",zg[j].jbgz);

printf("Please put in jibengongzi: \n");

gets(numstr);

zg[j].jbgz=atof(numstr);

printf("jintie:%10.2f\n",zg[j].jt);

printf("Please put in jintie: \n");

gets(numstr);

zg[j].jt=atof(numstr);

printf("gangtie:%10.2f\n",zg[j].gt);

printf("Please put in gangtie: \n");

gets(numstr);

zg[j].gt=atof(numstr);

printf("butie:%10.2f\n",zg[j].bt);

printf("Please put in butie: \n");

gets(numstr);

zg[j].bt=atof(numstr);

printf("fangtie:%10.2f\n",zg[j].ft);

printf("Please put in fangtie: \n");

gets(numstr);

zg[j].ft=atof(numstr);

printf("jiaotongbutie:%10.2f\n",zg[j].jtbt);

printf("Please put in jiaotongbutie: \n");

gets(numstr);

zg[j].jtbt=atof(numstr);

zg[j].yfs=(zg[j].jbgz)+(zg[j].jt)+(zg[j].gt)+(zg[j].bt)+(zg[j].ft)+(zg[j].jtbt);

printf("fangzu:%10.2f\n",zg[j].fz);

printf("Please put in fangzu: \n");

gets(numstr);

zg[j].fz=atof(numstr);

printf("chuxu:%10.2f\n",zg[j].cx);

printf("Please put in chuxu: \n");

gets(numstr);

zg[j].cx=atof(numstr);

printf("huifei:%10.2f\n",zg[j].hf);

printf("Please put in huifei: \n");

gets(numstr);

zg[j].hf=atof(numstr);

zg[j].grsds=tgrsds(zg[j].yfs);

zg[j].yks=(zg[j].fz)+(zg[j].cx)+(zg[j].hf)+(zg[j].grsds);

zg[j].sfs=(zg[j].yfs)-(zg[j].yks);

flagfind=1;

}

else

{

flagfind=0;

}

}

if(flagfind==0)printf("\n Can not find record! \n");

return;

}

/*随机从内存中查找纪录根据id*/

idone(void)

{

float zhigongid;

int j;

int flagfind;

flagfind=0;

printf("\n Please put in zhigongbianhao: \n");

gets(numstr);

zhigongid=atof(numstr);

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

{

if(zg[j].id==zhigongid)

{

printf("\n %d record found! \n |",j+1);

printf("month:%d |",zg[j].month);

printf("zhigongbianhao%10.0f |",zg[j].id);

printf("jibengongzi:%10.2f |",zg[j].jbgz);

printf("jintie:%10.2f |",zg[j].jt);

printf("gangtie:%10.2f |",zg[j].gt);

printf("butie:%10.2f |",zg[j].bt);

printf("fangtie:%10.2f |",zg[j].ft);

printf("jiaotongbutie:%10.2f |",zg[j].jtbt);

printf("yingfashu:%10.2f |",zg[j].yfs);

printf("fangzu:%10.2f |",zg[j].fz);

printf("chuxu:%10.2f |",zg[j].cx);

printf("huifei:%10.2f |",zg[j].hf);

printf("gerensuodeshui:%10.2f |",zg[j].grsds);

printf("yingkoushu:%10.2f |",zg[j].yks);

printf("shifashu:%10.2f\n",zg[j].sfs);

flagfind=1;

}

else

{

flagfind=0;

}

}

if(flagfind==0)printf("\n Can not find record! \n");

return;

}

/* 输出当月全体职工的工资信息 */

listall(void)

{

int j;

if(n<1)

{

printf("\n No record! \n");

}

else

{

for(j=0;j

{

printf("\n NO:%d |",j+1);

printf("month:%d |",zg[j].month);

printf("zhigongbianhao%10.0f |",zg[j].id);

printf("jibengongzi:%10.2f |",zg[j].jbgz);

printf("jintie:%10.2f |",zg[j].jt);

printf("gangtie:%10.2f |",zg[j].gt);

printf("butie:%10.2f |",zg[j].bt);

printf("fangtie:%10.2f |",zg[j].ft);

printf("jiaotongbutie:%10.2f |",zg[j].jtbt);

printf("yingfashu:%10.2f |",zg[j].yfs);

printf("fangzu:%10.2f |",zg[j].fz);

printf("chuxu:%10.2f |",zg[j].cx);

printf("huifei:%10.2f |",zg[j].hf);

printf("gerensuodeshui:%10.2f |",zg[j].grsds);

printf("yingkoushu:%10.2f |",zg[j].yks);

printf("shifashu:%10.2f\n",zg[j].sfs);

}

}

}

/* 把所有纪录从内存中写到磁盘gongzi.rec中 */

wfile(void)

{

FILE *fptr;

printf("\n Saving date... \n");

if(n<1)

{

printf("\n No record! \n");

return;

}

if((fptr=fopen("gongzi.rec","wb"))==NULL)

printf("Can not open file gongzi.rec! \n");

else

{

fwrite(zg,sizeof(zg[0]),n,fptr);

fclose(fptr);

printf("File of %d records written! \n",n );

}

}

/* 把所有纪录从磁盘gongzi.rec读到数组gz中 */

rfile(void)

{

FILE *fptr;

n=0;

printf("\n Loading date... \n");

if((fptr=fopen("gongzi.rec","rb"))==NULL)

printf("Can not open file gongzi.rec! \n");

else

{

while(fread(&zg[n],sizeof(zg[n]),1,fptr)==1)

n++;

fclose(fptr);

printf(" Total %d records read! \n",n);

}

}

00分享举报

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值