高手进!!!!!!!!

apm80 2007-08-20 08:43:08
没写完,不知道错在什么地方?

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
class moneyChange
{
private:
char *cMoney;
char *money;
char *dot;
public:
moneyChange(char *tMoney);
void moneyGet();
void moneyGet(char *tMoney);
void moneyPut();
void run();
char *comChange();
char *intChange();
char *floChange();
};
moneyChange::moneyChange(char *tMoney)
{
money=tMoney;
}
void moneyChange::moneyGet()
{
cout<<"请输入钱的数目:";
cin>>money;
}
void moneyChange::moneyGet(char *tMoney)
{
money=tMoney;
}
void moneyChange::moneyPut()
{
cout<<"转换后的结果是:"<<cMoney<<endl;
}
void moneyChange::run()
{
while(*money=='0'&&*(money+1)!='.')
money=money+1;
if(dot=strchr(money,'.'))
if(*(dot-1)=='0'&&*money=='0')
cMoney=floChange();
else
cMoney=comChange();
else
cMoney=intChange();
}
char *moneyChange::comChange()
{
int fig;
char *sig;
fig=strlen(money)-3;
free(cMoney);
for(int i=0;cMoney[i]!='元';i++)
{
switch(money[i])
{
case '1': cMoney[i]='壹';break;
case '2': cMoney[i]='贰';break;
case '3': cMoney[i]='叁';break;
case '4': cMoney[i]='肆';break;
case '5': cMoney[i]='伍';break;
case '6': cMoney[i]='陆';break;
case '7': cMoney[i]='柒';break;
case '8': cMoney[i]='捌';break;
case '9': cMoney[i]='玖';break;
case '0': cMoney[i]='零';break;
}
switch(fig--)
{
case 1:
cMoney[++i]='元';break;
case 2: case 6: case 10:
cMoney[++i]='拾';break;
case 3: case 7: case 11:
cMoney[++i]='佰';break;
case 4: case 12: case 8:
cMoney[++i]='仟';break;
case 5:
cMoney[++i]='万';break;
case 9:
cMoney[++i]='亿';break;
case 13:
cMoney[++i]='兆';break;
}
}
if(*cMoney=='壹'&&*(cMoney+1)=='拾')
cMoney=cMoney+1;
sig=strchr(cMoney,'元')+1;
for(int j=0;j<strlen(dot)-1;j++)
{
switch(dot[j])
{
case '1': sig[j]='壹';break;
case '2': sig[j]='贰';break;
case '3': sig[j]='叁';break;
case '4': sig[j]='肆';break;
case '5': sig[j]='伍';break;
case '6': sig[j]='陆';break;
case '7': sig[j]='柒';break;
case '8': sig[j]='捌';break;
case '9': sig[j]='玖';break;
case '0': sig[j]='零';break;
}
switch(j)
{
case 0: sig[j]='角';sig[j+1]='\0';break;
case 1: sig[j]='分';sig[j+1]='\0';break;
}
}
if(*sig=='零'&&*(sig+1)=='角')
{
*(sig+1)=*(sig+2);
*(sig+2)=*(sig+3);
*(sig+3)='\0';
}
return cMoney;
}
char *moneyChange::intChange()
{


}
char *moneyChange::floChange()
{


}
void main()
{
moneyChange red;
red.moneyGet();
red.moneyPut();
}
...全文
265 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
kei_lin 2007-08-25
  • 打赏
  • 举报
回复
void moneyChange::moneyGet()
{
cout<<"请输入钱的数目:";
cin>>money;
}
不能这样写吧...
money 指向哪..
abc277908375 2007-08-25
  • 打赏
  • 举报
回复
你具体要表达一个什么意思?
abc277908375 2007-08-25
  • 打赏
  • 举报
回复
上面的  数组中  汉字是占用的2个字节   所以 你那里用的应该用  2维数组
  • 打赏
  • 举报
回复
char *money;
while(*money=='0'&&*(money+1)!='.')
money=money+1;

我看的不错的话 money就是输入的数字是一个char* 那是一个字符串
就像如果输入的是1234 那么money就是1234
我不知道这个while里面的判断语句管不管用
(我也是新手,大家一起学习!)
  • 打赏
  • 举报
回复
大概是要把阿拉伯数字转换成 汉字的格式~~ '壹' 是字符串所以要加双引号 “壹”
额~~~比较难懂~~特别是 小数点后面那段~~
linfengc 2007-08-20
  • 打赏
  • 举报
回复
编的什么玩意阿。。。
fzqr100 2007-08-20
  • 打赏
  • 举报
回复
正在编译...
main.cpp
d:\tmp\test\test\main.cpp(54) : warning C4267: '=' : conversion from 'size_t' to 'int', possible loss of data
d:\tmp\test\test\main.cpp(60) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(60) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(61) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(61) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(62) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(62) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(63) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(63) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(64) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(64) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(65) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(65) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(66) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(66) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(67) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(67) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(68) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(68) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(69) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(69) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(74) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(74) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(76) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(76) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(78) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(78) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(80) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(80) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(82) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(82) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(84) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(84) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(86) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(86) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(92) : warning C4018: '<' : signed/unsigned mismatch
d:\tmp\test\test\main.cpp(96) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(96) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(97) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(97) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(98) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(98) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(99) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(99) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(100) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(100) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(101) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(101) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(102) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(102) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(103) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(103) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(104) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(104) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(105) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(105) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(109) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(109) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(110) : warning C4305: '=' : truncation from 'int' to 'char'
d:\tmp\test\test\main.cpp(110) : warning C4309: '=' : truncation of constant value
d:\tmp\test\test\main.cpp(133) : error C2512: 'moneyChange' : no appropriate default constructor available
生成日志保存在“file://d:\tmp\test\test\Debug\BuildLog.htm”
test - 1 个错误,60 个警告
========== 生成: 0 已成功, 1 已失败, 0 最新, 0 已跳过 ==========

vs 2005说的... ^_^
ybtianyu 2007-08-20
  • 打赏
  • 举报
回复
问题确实有点多,比如
1. case '1': cMoney[i]='壹';break; (CMoney是一字符指针,不能容纳一个汉字的ASCII值.)

2.构造函数moneyChange有一参数,而你在main函数中定义一个moneyChange对象red时,并没有指定构造参数.
3.moneyChange类中并没有为成员指针正确赋值.成员指针指向的内存区域并没有实际在类对象的构造或运行过程中分配. 同样是内存分配的问题,程序中用了free,却没有用malloc.这个错误是显而易见的
认真改吧.
ochinchina 2007-08-20
  • 打赏
  • 举报
回复
比如你的cMoney,dot, money没有分配空间
中文字符不能当作英文的字符,只能当作字符串
看了一下你的程序不知你想干啥
ochinchina 2007-08-20
  • 打赏
  • 举报
回复
你的代码问题很多哟

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧