|
|
||||||||||||||
![]() 渥太华华人网上社区 |
|
| 注册账号 | Blog | 论坛帮助 | 会员列表 | 搜索 | 今日新帖 | 标记版面已读 | 用户相册 |
![]() |
> c++ problems |
![]() |
|
|
主题工具 | 显示模式 |
|
[普通会员]
ID: 79833
|
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 开始就有点不知道了! ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() 非常感谢谢!!! ![]() ![]() ![]() ![]() ![]() ![]()
|
|
|
|
[中级会员]
ID: 79404
|
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. } } 引用:
|
|
|
|