| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2956 人关注过本帖
标题:[求助]设计一个能实现把小写金额转换为大写金额的类。比如5002.30,转换为“ ...
只看楼主 加入收藏
daluqiang
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-5-14
收藏
 问题点数:0 回复次数:6 
[求助]设计一个能实现把小写金额转换为大写金额的类。比如5002.30,转换为“伍仟零
设计一个能实现把小写金额转换为大写金额的类。比如5002.30,转换为“伍仟零贰元叁角整”。并设计完整的程序进行演示。
搜索更多相关主题的帖子: 金额 小写 设计 演示 
2007-05-14 23:26
listonline
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2008-1-4
收藏
得分:0 
读取后用字符串替换操作函数Replace(),

C++Builder学习交流www.欢迎交换连接~
2008-01-04 23:44
FireG
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-1-21
收藏
得分:0 
貌似很好玩  我试着写一下~
2008-01-21 16:36
yuki
Rank: 2
等 级:新手上路
威 望:5
帖 子:508
专家分:0
注 册:2005-2-4
收藏
得分:0 
希望LZ大人能先把我口袋中的钱小写变为大写的,我可以考虑一下帮您实现

我们都在命运湖上荡舟划桨,波浪起伏使我们无法逃离孤行;如果我们迷失方向,波浪将指引我们穿过另一天曙光
2008-02-04 14:58
←…○…→
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-10-18
收藏
得分:0 
写了个,这题有点意思
#include <iostream.h>
#include <string.h>
#include <alloc.h>

static char* num[]={
    "零","一","二","三","四",
    "五","六","七","八","九"
};

class money{
    float number;
 public:
    money(float m){number=m;}
    ~money(){};
    void set(float m){number=m;}
    void get();
    float get(int i){return number;}
};

void money::get (){
    float temp=number;
    char str[100],tmp[3];
    long i;
    int Nrest,Nint;

    Nint=(int)temp;
    //Nrest=temp-Nint;
    if(Nint/1000000000>0){ cout<<"\n多于拾亿,自己换算!"; return; }

    for(i=1000000000;Nint/i==0;i=i/10);
    //cout<<"\ni="<<i<<"\n整数="<<Nint<<"\t小数="<<Nrest<<"temp="<<temp;
    

    while(Nint%i){
        Nint=Nint/i;
        strcpy(tmp,num[Nint/i]);
        strcat(tmp,str);
        switch(i){
            case 1000000000:strcat("拾亿",str);break;
            case  100000000:strcat(  "亿",str);break;
            case   10000000:strcat("仟万",str);break;
            case    1000000:strcat("佰万",str);break;
            case     100000:strcat("拾万",str);break;
            case      10000:strcat(  "万",str);break;
            case       1000:strcat(  "仟",str);break;
            case        100:strcat(  "佰",str);break;
            case         10:strcat(  "拾",str);break;
            case          1:strcat(  "圆",str);break;
        }
        i/=10;
    }
    cout<<endl<<str<<endl;
    /*处理小数*/
    temp=temp-(int)temp;
    if((int(temp*100))!=0){
            strcat(num[(int(temp*10))],str);
            strcat(  "角",str);
    }

        if((int(temp*10))!=0){
            strcat(num[(int(temp*10))],str);
            strcat(  "分",str);
        }
    cout<<endl<<str<<endl;
}

int main()
{
    money m(0);
    float y;

    cout<<"输入金额:¥";
    cin>>y;
    //cout<<"\ny="<<y<<endl;
    m.set(y);
    //cout<<"number="<<m.get(1);
    m.get();
    //cout<<endl<<str<<endl;

    return 0;
}
2008-10-19 08:59
←…○…→
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-10-18
收藏
得分:0 
啊,发错了
...
2008-10-19 09:01
←…○…→
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2008-10-18
收藏
得分:0 
#include <iostream.h>

static char* num[]={
    "零","壹","贰","叁","肆",
    "伍","陆","柒","捌","玖"
};

class money{
    double number;
 public:
    money(float m){number=m;}
    ~money(){};
    void set(float m){number=m;}
    void get();
    double get(int i){return number;}
};

void money::get (){
    double temp=number,Nrest;
    long i;
    int Nint;

    Nint=(int)temp;
    Nrest=temp-Nint;
    if(Nint/1000000000>0){ cout<<"\n多于拾亿,自己换算!"; return; }
    for(i=1000000000;Nint/i==0;i=i/10);
    //cout<<"\ni="<<i<<"\n整数="<<Nint<<"\t小数="<<Nrest<<"\ttemp="<<temp<<endl;
    

    while(Nint){
        if(Nint/i==0){
            cout<<num[Nint/i];
            for(;Nint/i==0;i=i/10);
        }
        cout<<num[Nint/i];
        
        switch(i){
            case 1000000000:cout<<"拾亿";break;
            case  100000000:cout<<  "亿";break;
            case   10000000:cout<<"仟万";break;
            case    1000000:cout<<"佰万";break;
            case     100000:cout<<"拾万";break;
            case      10000:cout<<  "万";break;
            case       1000:cout<<  "仟";break;
            case        100:cout<<  "佰";break;
            case         10:cout<<  "拾";break;
        }
        Nint=Nint-Nint/i*i;
        i/=10;
        if(!Nint) cout<<"圆";
    }
    
    
    /*处理小数*/
    Nint=Nrest*100;
    if(Nint/10){
            cout<<num[Nint/10]<<"角";
            Nint=Nint-Nint/10*10;
    }
    if(Nint)
            cout<<num[Nint]<<"分";
}

int main()
{
    money m(0);
    double y;

    cout<<"输入金额:¥";
    cin>>y;
    //cout<<"\ny="<<y<<endl;
    m.set(y);
    cout<<"大写金额:";
    m.get();
    //cout<<endl<<str<<endl;

    return 0;
}
2008-10-19 09:01
快速回复:[求助]设计一个能实现把小写金额转换为大写金额的类。比如5002.30,转 ...
数据加载中...
 
   



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

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