首页 | 中文黄页 | 图片共享

渥太华华人网上社区
注册账号 Blog 论坛帮助 会员列表 搜索 今日新帖 标记版面已读 用户相册
返回   CFC加拿大中文论坛 > 科技时代 > 电脑技术 > c++ problems
回复
 
主题工具 显示模式
[普通会员]
ID: 79833
type="text" 的头像
type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦
声望: 18115 声望力: 190
帖子: 98
家族: rain&wind
来自: 湖南
金钱: 3,224
注册: 2008-03-05
c++ problems

www.comefromchina.com
Write a class (ROMANNUMERAL) which has as its data member a pointer to a char
(char * romanNumeral_ptr) which will (eventually) hold a roman numeral. The
ONLY data member will be this one. You must write the following methods:
Default constructor
• Initial constructors which allow a char array as input or an int number. In each of these
constructors you will need to insure that the input data is converted to the format of the
roman numeral you are keeping in the class.
• Destructor
• inputRoman – to read a roman numeral from a source (could be cin, could be a file)
• displayRoman – to display roman numeral to cout
• calcfromInteger – accepts an int parameter and stores the corresponding roman
numeral string into the object
• calcIntValue which returns through return value the int value of the roman numeral string in the object

有高手能告诉我写这个作业吗??我不知道写了!从inputRoman 开始就有点不知道了!

非常感谢谢!!!
type="text" 当前离线  
回复时引用此帖
旧 2008-07-06, 20:18 #1
[中级会员]
ID: 79404
blueray 的头像
blueray 是普普通通的会员blueray 是普普通通的会员blueray 是普普通通的会员blueray 是普普通通的会员
声望: 360 声望力: 13
帖子: 120
家族:
来自:
金钱: 5,901
注册: 2008-02-03

I did not finish the code for you. You need to complete the code.
Pay attention to the assignment of the data to your member pointer.
Each time clear this pointer first and make a deep copy. Initialize
the pointer in the constructors as follows:
RomanNumeral::RomanNumeral( const char * const romanNumeral_ptr ) :
rn_ptr( 0 )
{
make a deep copy of romanNumeral_ptr;
you can not do: rn_ptr = romanNumeral_ptr;
You need to know why.
}

RomanNumeral::RomanNumeral( const int roman_num ) :
rn_ptr( 0 )
{
}

RomanNumeral::~RomanNumeral
{
delete[] rn_ptr; rn_ptr = 0;
}

void RomanNumeral::inputRoman()
{
string input_str( "" );
cout << "
Read a roman numeral from a file[yes/no]?";
cin << read input_str;
if ( input_str == string( "yes" ) ) //yes case
{
string file_name;
cout << "Please give the file name:"
cin << read file name here;
open file
read data and deep copy it.
close file
}
else //no case
{
int num_rn;
cout << "Input the
corresponding integer of a roman
numerical from keyboard:"
cin << num_rn;
convert num_rn to char * and save it to the data
member.
}
}

引用:
作者: type="text" 查看帖子
Write a class (ROMANNUMERAL) which has as its data member a pointer to a char
(char * romanNumeral_ptr) which will (eventually) hold a roman numeral. The
ONLY data member will be this one. You must write the following methods:
Default constructor
• Initial constructors which allow a char array as input or an int number. In each of these
constructors you will need to insure that the input data is converted to the format of the
roman numeral you are keeping in the class.
• Destructor
• inputRoman – to read a roman numeral from a source (could be cin, could be a file)

• displayRoman – to display roman numeral to cout
• calcfromInteger – accepts an int parameter and stores the corresponding roman
numeral string into the object
• calcIntValue which returns through return value the int value of the roman numeral string in the object

有高手能告诉我写这个作业吗??我不知道写了!从inputRoman 开始就有点不知道了!

非常感谢谢!!!
blueray 当前离线  
回复时引用此帖
旧 2008-07-07, 23:08 #2
[白银长老]
ID: 560
mooncake 的头像
mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展mooncake 正向着好的方向发展
声望: 2640 声望力: 108
帖子: 1,531
家族:
来自:
金钱: 3,099
注册: 2002-03-02

change the inputRomanNumeral function to
void RomanNumeral::inputRoman(istream s)

I guess you are asked to apply "polymorphism" in such case.
mooncake 当前离线  
回复时引用此帖
旧 2008-07-08, 00:00 #3
[普通会员]
ID: 79833
type="text" 的头像
type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦type="text" 身上有一圈迷人的光环哦
声望: 18115 声望力: 190
帖子: 98
家族: rain&wind
来自: 湖南
金钱: 3,224
注册: 2008-03-05



恩!知道了!谢谢!!
后面还有一部分要求!呵呵


我去慢慢写了!
type="text" 当前离线  
回复时引用此帖
旧 2008-07-08, 02:17 #4
回复


主题工具
显示模式




所有时间均为格林尼治时间 -5。现在的时间是 10:41

论坛内容均为网友自由上传, 不代表本网观点。
comefromchina.com does not represent or guarantee the truthfulness, accuracy, or reliability of any of communications posted by other users.


Powered by vBulletin® 版本 3.6.8
版权所有 ©2000 - 2008,Jelsoft Enterprises Ltd.
Copyright @ comefromchina.com 2007

SEO by vBSEO 3.1.0 ©2007, Crawlability, Inc.