c++ problems

type="text"

新手上路
VIP
注册
2008-03-05
消息
102
荣誉分数
31
声望点数
0
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 开始就有点不知道了!
:cool::cool::cool::cool::cool::cool::cool::cool::cool:
非常感谢谢!!!:blowzy::blowzy::blowzy::blowzy::blowzy::blowzy::blowzy:
 
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.
}
}

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 开始就有点不知道了!
:cool::cool::cool::cool::cool::cool::cool::cool::cool:
非常感谢谢!!!:blowzy::blowzy::blowzy::blowzy::blowzy::blowzy::blowzy:
 
change the inputRomanNumeral function to
void RomanNumeral::inputRoman(istream s)

I guess you are asked to apply "polymorphism" in such case.
 
:p:p:p:p:p:p:p:p:D:D:D:D:D:D:D

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


我去慢慢写了!
 
后退
顶部