| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 434 人关注过本帖
标题:哪位精通c++与c语言的高手、、帮我把这c语言改成c++、、
只看楼主 加入收藏
shinelin09
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:9
专家分:20
注 册:2010-5-17
结帖率:0
收藏
 问题点数:0 回复次数:0 
哪位精通c++与c语言的高手、、帮我把这c语言改成c++、、
/*************************************************************************/
#include <stdio.h>                                         //标准输入输出
#include <stdlib.h>                                       //处理杂乱  
#include <windows.h>                                     //Sleep()                                          
#include <string.h>                                     //字符串操作  
#include <conio.h>                                     //系统输入输出
#include <time.h>                                     //时间相关
/**********************下面是对用到的全局常量声明*************************/
#define NAME 10                                     //职工职工姓名长度
int shuru=0;                                      //全局变量标记当前录入职工个数
FILE *fp;                                        //声明一个文件指针
/**************************结构体定义************************************/
struct person{                                 //职工工资的结构体
    char name[NAME];                          //职工职工姓名
    int   num;                               //职工编号
    float paid;                             //职工基本工资
    float discount;                        //扣款
    float extra;                          //奖金
    float realpaid;                      //实发工资
    float sum;                          //总工资
}*pp;                                  //声明一个结构指针
/**********************下面是对用到的函数声明*****************************/

void Save(struct person per[]);        //保存信息函数
void Inputper(struct person per[]);    //录入信息函数
void Modifyper(struct person per[]);   //修改信息函数
void Findper(struct person per[]);     //查找信息函数
void Listper(struct person per[]);     //显示职工信息
void Menu();
void Help();
//**************************程序主体**************************************
void main()                              //程序入口
{
    system("color 012");               //设置当前窗口的背景色和前景色   
 
    Help();                          //调用系统信息函数
    Menu();                         //调用菜单函数
}
void Inputper(struct person per[])                         //录入职工工资函数原形
{   
    pp=per;                                               //指针指向结构
    system("cls");                      //清屏
    int i;
    printf("请问你要输入几个职工的信息:");
    scanf("%d",&shuru);
    if((fp=fopen("inputdata.doc","wb+"))==NULL)            //当前目录下是否存在INPUTDATA文件
    {                                                 //"wb+":读写打开或建立一个二进制文件,允许读和写
        printf("Cannot open file strike any key exit!");
        getch();
        exit(1);
    }
    fprintf(fp,"职工编号    职工姓名   基本工资    扣款    奖金    实发工资   总工资\n");
    for(i=0;i<shuru;i++)
    {
            printf("输入职工编号:");                       //输入职工编号
            fflush(stdin);
            scanf("%d",&per[i].num);
            printf("输入职工姓名:");                       //输入职工姓名
            fflush(stdin);
            gets(per[i].name);                                            
            printf("输入职工的工资信息\n");
            printf("------------------------------\n");
            printf("\n基本工资: ");                       //基本工资
            fflush(stdin);
            scanf("%f",&per[i].paid);                    
            printf("\n扣款: ");                           //扣款
            fflush(stdin);
            scanf("%f",&per[i].discount);            
            printf("\n奖金: ");                           //奖金
            fflush(stdin);
            scanf("%f",&per[i].extra);
            printf("------------------------------\n");
            per[i].sum=per[i].paid-per[i].discount+per[i].extra;
            per[i].realpaid=per[i].paid-per[i].discount;
            fprintf(fp," %6d  %8s      %7.1f     %5.1f    %5.1f    %5.1f   %6.1f\n",per[i].num,per[i].name,per[i].paid,per[i].discount,per[i].extra,per[i].realpaid,per[i].sum);
    }
}
void Modifyper(struct person per[])                      //修改职工工资信息
{
    pp=per;
    int id,i=0;                                           //id为接收用户输入的职工编号
    if((fp=fopen("modifydata.doc","wb+"))==NULL)            
    {
        printf("Cannot open file strike any key exit!");
        getch();
        exit(1);
    }
    fprintf(fp,"职工编号    职工姓名    基本工资   扣款    奖金    实发工资    总工资\n");
    printf("\n请输入你要修改的职工的编号:");
    scanf("%d",&id);
    Sleep(200);
    printf("\n\t查找相关数据.");
        for(i=0;i<=15;i++)
            {
                Sleep(200);
                printf(".");
            }
    for(i=0;i<shuru;i++)
    {
        if(per[i].num==id)             //如果找到了就执行下面语句 ,找不到直接回主界面
            {
                printf("\n输入新职工编号:");                      //输入职工编号
                fflush(stdin);
                scanf("%d",&per[i].num);
                printf("\n输入新职工姓名:");                      //输入职工姓名
                fflush(stdin);
                gets(per[i].name);                                            
                printf("输入职工的工资信息\n");
                printf("------------------------------\n");
                printf("\n基本工资: ");
                scanf("%f",&per[i].paid);
                fflush(stdin);
                printf("\n扣款: ");
                scanf("%f",&per[i].discount);
                fflush(stdin);
                printf("\n 奖金: ");
                scanf("%f",&per[i].extra);
                printf("------------------------------\n");
                per[i].sum=per[i].paid-per[i].discount+per[i].extra;
                per[i].realpaid=per[i].paid-per[i].discount;
                fprintf(fp," %6d  %8s      %7.1f      %5.1f    %5.1f   %5.1f   %6.1f\n",per[i].num,per[i].name,per[i].paid,per[i].discount,per[i].extra,per[i].realpaid,per[i].sum);
            }
    }
}
void Findper(struct person per[])                          //查询职工工资信息
{
    int i=0,id;                                             //循环变量和用于接收职工编号   
        printf("请输入你要查询的职工编号:");
        scanf("%d",&id);
        for(i=0;i<shuru;i++)
            {
            if (per[i].num==id)                             //如果找到你查询的数据就执行下面语句                                            
                {                                            //如果找不到。直接回程序主界面
                    per[i].sum=per[i].paid-per[i].discount+per[i].extra;
                    per[i].realpaid=per[i].paid-per[i].discount;
                    printf("\n职工编号   职工姓名    基本工资    扣款    奖金   实发工资    总工资 \n");
                    printf("\n%6d  %8s      %7.1f      %5.1f     %5.1f    %5.1f    %6.1f \n\n",per[i].num,per[i].name,per[i].paid,per[i].discount,per[i].extra,per[i].realpaid,per[i].sum);
                    system("pause");
                }
            }        
}

void Listper(struct person per[])                        //浏览所有职工工资
{               
    int i=0;
    for(i=0;i<shuru;i++)
    {
        per[i].sum=per[i].paid-per[i].discount+per[i].extra;
        per[i].realpaid=per[i].paid-per[i].discount;
    }
   
    printf("\n职工编号    职工姓名    基本工资   扣款    奖金    实发工资   总工资\n");
    for(i=0;i<shuru;i++)
    {
        printf("\n %6d  %8s      %7.1f     %5.1f   %5.1f   %5.1f   %6.1f",per[i].num,per[i].name,per[i].paid,per[i].discount,per[i].extra,per[i].realpaid, per[i].sum);   
    }
    getch();
}


void Menu()
{
    struct person per[50];             //最大职工人数
    struct person *p;                  //声明一个结构指针
    p=per;                             //指针指向结构变量per
    int  i,in;                           //接收用户的选择
    char ch;                           //用于判断是否继续                     
    do
    {
        system("cls");
        printf("\n\n");
        printf("\t\t =============================================\n");
        printf("\t\t *                          *\n");
        printf("\t\t *===========================================*\n");
        printf("\t\t *          1.  录入职工工资        *\n");
        printf("\t\t *                       *\n");
        printf("\t\t *         2. 修改职工工资        *\n");
        printf("\t\t *                       *\n");
        printf("\t\t *         3. 查询职工工资        *\n");
        printf("\t\t *                       *\n");
        printf("\t\t *         4. 浏览职工工资         *\n");
        printf("\t\t *                       *\n");
        printf("\t\t *         5.  保存职工工资         *\n");
        printf("\t\t *                       *\n");
        printf("\t\t *         6. 安全退出系统        *\n");
        printf("\t\t =============================================\n");
        printf("\t\t  请您正确选择: ");
        if(!(scanf("%d",&in)==1))
        {
            while((ch=getchar())!='\n')
            putchar(ch);
            printf(" 没有此选项,请正确选择!");
            getch();
            continue;
        }
        fflush(stdin);
        switch(in)
        {
            case 1:
                Inputper(per);                              //调用录入职工工资函数
                break;
            case 2:
                Modifyper(per);                             //调用修改职工工资函函数
                break;
            case 3:
                Findper(per);                               //调用查询职工工资函数
                break;
            case 4:
                Listper(per);                               //调用浏览职工工资函数
                break;
            case 5:
                Save(per);                                  //保存职工工资函数
                break;
            case 6:                                         //退出系统
                break;
            default:
                printf("没有此选项,请正确选择!");
                getch();
                break;
        }
    }while(in!=6);
    system("cls");
    printf("\n\n\n\n\n\n\n\n\t\t\t");
    printf("谢    使          !\n\n");
    printf("\n\n\t\t\t\t\tEnding");
            for(i=0;i<=30;i++)
            {
                Sleep(200);
                printf(".");
            }
    printf("\n");
}
void Help()
{  
    printf("====================================================================\n");
    printf("\n\n\t\t\t\t系 统 信 息\n");
    printf("====================================================================\n");
    printf("\n\n\t\t本系统是职工工资管理系统,在职工的姓名栏可以输入汉字");
    printf("\n\t\t如果在输入中没看到任何信息则是因为输入错误或无信息");
    printf("\n\t\t系统中的 :实发工资 = 基本工资 - 扣款 ,不需要输入");
    printf("\n\t\t实发工资 , 就可以直接输出实发工资,系统中的 : ");
    printf("\n\t\t总工资 = 基本工资 - 扣款 + 奖金.\n");
    printf("===================================================================\n");
    printf("\n\n\t\t\t\t按<Enter>进入");
    getchar();
}
void Save(struct person per[])                                //职工工资保存函数
{
    int i,j;
    pp=per;                                                    //指针指向结构
    system("cls");
    printf("\n\n\n\t\t正在保存信息,请耐心等候!!\n");
    printf("\n\n\t\t\tSaving");
    for(j=0;j<20;j++)
    {
        Sleep(200);
        printf(".");
    }   
    if((fp=fopen("per_list2.doc","wb+"))==NULL)              
    {                                                         
        printf("Cannot open file strike any key exit!");
        getch();
        exit(1);
    }
    fprintf(fp,"职工编号    职工姓名   基本工资   扣款   奖金   实发工资   总工资\n");
    for(i=0;i<shuru;i++)
        {
          per[i].sum=per[i].paid-per[i].discount+per[i].extra;
          per[i].realpaid=per[i].paid-per[i].discount;
          fprintf(fp," %6d  %8s     %7.1f     %5.1f    %5.1f   %5.1f   %6.1f\n",per[i].num,per[i].name,per[i].paid,per[i].discount,per[i].extra,per[i].realpaid,per[i].sum);   
        }
}


搜索更多相关主题的帖子: c语言 
2010-05-18 16:13
快速回复:哪位精通c++与c语言的高手、、帮我把这c语言改成c++、、
数据加载中...
 
   



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

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