| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 346 人关注过本帖
标题:大家看看如何在该程序中加个
只看楼主 加入收藏
seyeboy
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2011-6-26
结帖率:100%
收藏
 问题点数:0 回复次数:3 
大家看看如何在该程序中加个
#include <stdio.h>

[ 本帖最后由 seyeboy 于 2011-7-2 09:30 编辑 ]
搜索更多相关主题的帖子: include 如何 
2011-07-02 09:12
loveshuang
Rank: 9Rank: 9Rank: 9
来 自:湖北武汉
等 级:蜘蛛侠
帖 子:270
专家分:1198
注 册:2010-11-14
收藏
得分:0 
         #include <stdio.h>???加个什么呢?楼主表达清楚点
2011-07-02 09:33
seyeboy
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2011-6-26
收藏
得分:0 
回复 2楼 loveshuang
在这个程序中加个:按工资排序输出所有职工工资报表的程序
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

struct woker      //定义一个woker结构类型
{
     char name[30];     //定义woker的姓名为字符型
     char ID[10];       //定义woker的ID号为字符型
     int base_pay;    //定义woker的工资
     double pit;      //定义税金
};

int read(struct woker staff[]);       //申明读取文件函数
void start();                         //申明开始菜单函数
void save(struct woker staff[]);      //申明保存文件函数
void add();                           //申明增加记录函数
void see();                           //申明查看记录函数
void search();                        //申明查找记录函数
void search_ID();                     //按ID号查找
void search_name();                   //按姓名查找
void del();                           //删除记录
void name_del();                      //按姓名删除
void ID_del();                        //按ID号删除
void modify();                        //修改信息
void ID_modify();                     //按ID号修改
void name_modify();                   //按姓名修改
void reserve();                       //保存所有信息
void count();                         //计算税金
void back();                          //返回到主菜单
struct woker staff[100];              //保存所有的职工信息
int total_staff=0;                    //记录总的职工人数

void main()
{
     int choose=0;    //定义用户选择项目
     while(1)
     {
         start();      //显示主菜单      
         printf("\t请选择您需要的操作: ");
         scanf("%d",&choose);
         system("cls");   //清除屏幕
         switch(choose)   //根据用户选择执行相应的功能模块
         {
             case 0: exit(0); //退出
             break;
             case 1: add();    //输入信息
             back();   
             break;
             case 2: see();    //显示信息
             back();
             break;
             case 3: modify(); //修改信息
             back();
             break;
             case 4: search(); //查找信息
             back();
             break;
             case 5: del(); //删除信息
             back();
             break;
             case 6: reserve(); //保存数据
             back();
             break;
             case 7: count(); //计算税金
             back();
             break;
             default:printf("\t输入有误!\n"); //错误的输入
             back();
             break;
         }
     fflush(stdin);    //清空输入缓冲区
     getchar();        //消除输入残留垃圾
     system("cls");    //清除屏幕
     }
}


/**********************
      读取文件数据
**********************/
int read(struct woker staff[])   
{
     FILE *fp=NULL;
     int i=0;
     fp=fopen("C://woker.dat","rb");   //打开文件
     while(fread(&staff[i],sizeof(struct woker),1,fp))
     i++;
     fclose(fp);
     return i;
}


/********************
      开始主菜单
********************/
void start()
{
printf("\n");
printf("\t***********************************\n");
printf("\t    欢迎您来到职工工资纳税系统\n");
printf("\t-----------------------------------\n");
printf("\t\t [1] 输 入 信 息\n\n");
printf("\t\t [2] 显 示 信 息\n\n");
printf("\t\t [3] 修 改 信 息\n\n");
printf("\t\t [4] 查 找 信 息\n\n");
printf("\t\t [5] 删 除 信 息\n\n");
printf("\t\t [6] 保 存 数 据\n\n");
printf("\t\t [7] 计 算 税 金\n\n");
printf("\t\t [0] 退 出 系 统\n\n");
printf("\t***********************************\n\n");
}


/*********************
       保存信息
*********************/
void save(struct woker *staff)  
{
FILE *fp=NULL;
fp=fopen("C://woker.dat","ab+");
fwrite(staff,sizeof(struct woker),1,fp);
fclose(fp);
}


/*********************
      添加职员信息
*********************/
void add()
{
     int numberTemp=0;
     int i=0;
     struct woker temp;
     int q;
     printf("----------添加职工信息----------\n");
     printf("请输入您要添加职工个数:");
     scanf("%d",&numberTemp);
for(i=0;i<numberTemp;i++)
     {
         printf("输入第%d个职工信息\n",i+1);
         printf("姓名:");
         scanf("%s",temp.name);
         printf("工号:");
         scanf("%s",temp.ID);
         printf("工资:");
         scanf("%d",&temp.base_pay);
         staff[total_staff++]=temp; //写入到数组
         q=staff[i].base_pay-1600;         
         if(q<=0){
             staff[i].pit=0;}
         else
         {
             if(q<=500){
                 staff[i].pit=q*0.05;}
             else
             {
                 if(q>500&&q<=2000){
                     staff[i].pit=25+(q-500)*0.1;}
                 else
                 {
                     if(q>2000&&q<=5000){
                         staff[i].pit=25+150+(q-2000)*0.15;}
                     else
                     {
                         if(q>5000&&q<=20000){
                             staff[i].pit=25+150+450+(q-5000)*0.2;}
                         else
                         {
                             if(q>20000&&q<=40000){
                                 staff[i].pit=25+150+450+3000+(q-20000)*0.25;}
                             else
                             {
                                 if(q>40000&&q<=60000){
                                     staff[i].pit=25+150+450+3000+5000+(q-40000)*0.3;}
                                 else
                                 {
                                     if(q>60000&&q<=80000){
                                         staff[i].pit=25+150+450+3000+5000+6000+(q-60000)*0.35;}
                                     else
                                     {
                                         if(q>80000&&q<=100000){
                                             staff[i].pit=25+150+450+3000+5000+6000+7000+(q-80000)*0.40;}
                                         else
                                         {
                                             if(q>100000){
                                                 staff[i].pit=25+150+450+3000+5000+6000+7000+8000+(q-100000)*0.45;}
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }  
      
      
     }save(&temp); //写入到文件
     printf("--------------------------------\n");
     printf("添加成功!\n");
}

/**********************
      查看职员信息
**********************/
void see()
{
     int i=0;
     printf("-------全部职工信息-------\n");
     printf("姓名   工号      工资      纳税金额\n");
     for (i=0;i<total_staff; i++)
     printf("%s\t%s\t%d\t%lf\t\n",staff[i].name,staff[i].ID,staff[i].base_pay,staff[i].pit);
}


/***********************
查找职员信息
***********************/
void search()
{
     int n=0;
     printf("------查找职工信息-------\n");
     printf("[1] 按姓名查找\n");
     printf("[2] 按工号查找\n");
     scanf("%d",&n);
     switch(n)
     {
         case 1: search_name();
         break;
         case 2: search_ID();
         break;
         default: printf("输入错误!\n");
         break;
     }
}
void search_name()   //按姓名查找
{
     char name[30];
     int i=0;
     printf("请输入要查找职工姓名:");
     scanf("%s",name);
     system("cls");
     printf("-------全部职工信息-------\n");
     printf("姓名   工号      工资      纳税金额\n");
     for (i=0;i<total_staff;i++)
     {
         if (strcmp(name,staff[i].name)==0)
         {
             printf("%s\t%s\t%d\t%lf\t\n",staff[i].name,staff[i].ID,staff[i].base_pay,staff[i].pit);
         }
     }
     printf("-------------------------\n");
}
void search_ID()//按工号查找
{
     char id[10];
     int i=0;
     printf("请输入要查找职工工号:");
     scanf("%s",id);
     system("cls");
     printf("-------全部职工信息-------\n");
     printf("姓名   工号      工资      纳税金额\n");
     for (i=0;i<total_staff;i++)
     {
         if (strcmp(id,staff[i].ID)!=0)
         {
             printf("%s\t%s\t%d\t%lf\t\n",staff[i].name,staff[i].ID,staff[i].base_pay,staff[i].pit);
         }
     }
printf("-------------------------------------------------------------\n");
}


/********************
     删除职员信息
********************/
void del()
{
     int n=0;
     printf("------删除职工信息-------\n");
     printf("[1] 按姓名删除\n");
     printf("[2] 按工号删除\n");
     scanf("%d",&n);
     switch(n)
     {
         case 1: name_del();
         break;
         case 2: ID_del();
         break;
     }
}
void name_del() //按姓名删除
{
     FILE *fp=NULL;
     char name[30];
     int i=0;
     int j=0;
     printf("请输入要删除的职工姓名:");
     scanf("%s",name);
     for(i=0;i<total_staff;i++)
     {
         if (strcmp(name,staff[i].name)==0)
         {
             for (j=i;j<total_staff-1;j++)
             {
                 staff[j]=staff[j+1];
             }
             total_staff--;
         }
     }


     //更新数据
     fp=fopen("C://woker.dat","wb");
     for (i=0;i<total_staff;i++)
     {
         fwrite(&staff[i],sizeof(struct woker),1,fp);
     }
     fclose(fp);
     printf("删除成功!\n");

}
void ID_del() //按工号删除
{
     FILE *fp=NULL;
     char id[60];
     int i=0;
     int j=0;
     printf("请输入要删除的职工工号:");
     scanf("%s",id);
     for(i=0;i<total_staff;i++)
     {
         if (strcmp(id,staff[i].ID)==0)
         {
             for (j=i;j<total_staff-1;j++)
             {
staff[j]=staff[j+1];
             }
             total_staff--;
         }
     }

     //更新数据
     fp=fopen("C://woker.dat","wb");
     for (i=0;i<total_staff;i++)
     {
         fwrite(&staff[i],sizeof(struct woker),1,fp);
     }
     fclose(fp);
     printf("删除成功!\n");
}
/***********************
      修改职工信息
***********************/
void modify()
{
     int mode=0;
     printf("==========修改职工信息===========\n");
     printf("请选择修改查找方式\n");
     printf("[1] 按姓名查找修改\n");
     printf("[2] 按工号查找修改\n");
     scanf("%d",&mode);
     switch(mode)
     {
         case 1: name_modify();
         break;
         case 2: ID_modify();
         break;
         default: printf("输入错误!\n");
         break;
     }
}
void name_modify()//按姓名修改
{
     FILE *fp=NULL;
     char name[30];
     int i=0;
     printf("请输入要修改的职工姓名:");
     scanf("%s",name);
     for (i=0;i<total_staff;i++)
     {
         if (strcmp(name,staff[i].name));
         else
         break;
     }
     printf("---------------------------\n");
     printf("姓名   工号      工资      纳税金额\n");
     printf("%s\t%s\t%d\t%lf\t\n",staff[i].name,staff[i].ID,staff[i].base_pay,staff[i].pit);
     printf("-----------------------------------------------------\n");
     printf("请重新输入该职工信息:\n");
     printf("姓名:");
     scanf("%s",staff[i].name);
     printf("工号:");
     scanf("%s",staff[i].ID);
printf("工资:");
     scanf("%d",&staff[i].base_pay);
         //更新数据
     fp=fopen("C://woker.dat","wb");
     for (i=0;i<total_staff;i++)
     {
         fwrite(&staff[i],sizeof(struct woker),1,fp);
     }
     fclose(fp);
     printf("---------------------------------\n");
     printf("修改成功!\n");
}
void ID_modify()//按工号修改
{
     FILE *fp=NULL;
     char id[30];
     int i=0;
     printf("请输入要修改的职工工号:");
     scanf("%s",id);
     for (i=0;i<total_staff;i++)
     {
     if (strcmp(id,staff[i].ID));
     else
     break;
     }
     printf("--------------------------\n");
     printf("姓名   工号      工资      纳税金额\n");
     printf("%s\t%s\t%d\t%lf\t\n",staff[i].name,staff[i].ID,staff[i].base_pay,staff[i].pit);
     printf("-----------------------------------------------------\n");
     printf("请重新输入该职工信息:\n");
     printf("姓名:");
     scanf("%s",staff[i].name);
     printf("工号:");
     scanf("%s",staff[i].ID);
     printf("工资:");
     //更新数据
     fp=fopen("C://woker.dat","wb");
     for (i=0;i<total_staff;i++)
     {
     fwrite(&staff[i],sizeof(struct woker),1,fp);
     }
     fclose(fp);
     printf("---------------------------------\n");
     printf("修改成功!\n");
}


/*********************
       保存数据
*********************/
void reserve()
{   
     FILE *fp=NULL;
     char name[30];
     int i=0;
     printf("\t--------------保存数据--------------\n\n");
     printf("\t          正在保存数据......请稍等\n\n\n\n\n");
     fp=fopen("C://woker.dat","wb");
     for (i=0;i<total_staff;i++)
     {
         fwrite(&staff[i],sizeof(struct woker),1,fp);
     }
     fclose(fp);
     printf("\t           ^_^恭喜您 数据已保存成功!\n\n\n\n");
}
void count()
    {
    double q,salary, ns=0;
    printf("请输入您的工资:\n");
    scanf("%lf", &salary);
    q=salary-1600;
    if(q<=0){
        ns=0;}
    else
    {
        if(q<=500){
            ns=q*0.05;}
        else
        {
            if(q>500&&q<=2000){
                ns=25+(q-500)*0.1;}
            else
            {
                if(q>2000&&q<=5000){
                    ns=25+150+(q-2000)*0.15;}
                else
                {
                    if(q>5000&&q<=20000){
                        ns=25+150+450+(q-5000)*0.2;}
                    else
                    {
                        if(q>20000&&q<=40000){
                            ns=25+150+450+3000+(q-20000)*0.25;}
                        else
                        {
                            if(q>40000&&q<=60000){
                                ns=25+150+450+3000+5000+(q-40000)*0.3;}
                            else
                            {
                                if(q>60000&&q<=80000){
                                    ns=25+150+450+3000+5000+6000+(q-60000)*0.35;}
                                else
                                {
                                    if(q>80000&&q<=100000){
                                        ns=25+150+450+3000+5000+6000+7000+(q-80000)*0.4;}
                                    else
                                    {
                                        if(q>100000){
                                            ns=25+150+450+3000+5000+6000+7000+8000+(q-100000)*0.45;}
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    printf("您应缴纳的税金为:\n");
    printf("%lf",ns);
}

/*******************
      返回主菜单
*******************/
void back()
{
     printf("\n\t请按Enter键返回主菜单");
}


2011-07-02 09:41
lz1091914999
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:四川
等 级:贵宾
威 望:37
帖 子:2011
专家分:5959
注 册:2010-11-1
收藏
得分:0 

My life is brilliant
2011-07-02 10:47
快速回复:大家看看如何在该程序中加个
数据加载中...
 
   



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

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