TIP: Click on subject to list as thread! ANSI
echo: c_plusplus
to: DARIN MCBRIDE
from: ALBERTO MONTEIRO
date: 1997-09-04 18:51:00
subject: Roman Numeral??? (cpp)

AM> ostream& operator<<(ostream& Out, Roman& R)
AM> {
AM> Out << R.str;
AM> return Out;
AM> }
DM>You may want to hide both str and n and provide operator char* and 
perator
DM>int instead...
I'm new to C++ (but experienced with C; a consequence of working
for years in a VAX/VMS that has C but doesn't have C++). How can
this be done? Overload the cast operator?
DM>What happens if you already have a Roman string created?  You lose 
memory...
DM>try deallocating the string, first.
But since I free the str at the destruction, isn't memory recovered?
DM>Better yet, use the string class rather
DM>than the char* with strdup.
Hmmm... Yes, I have to forget some C to learn C++ :-)
DM>I'm not convinced it works, but your test program tests my suspicions, so
DM>I'll just have to try it.  :->
DM>Yeah, I was worried about that.  First of all, you have a str[1000] that's
DM>never used in the .cpp portion.  :-)
Old nasty habbit :-)
DM>Second, a few other test cases:
DM>IL = 49  [core dumped!]
DM>IIC = 98
DM>VC = 95
Those numbers are illegal. I didn't check for illegality
DM>And, the slightly more obscure:
DM>IVC = 96
DM>These are a few that you fail on.  Your algorithm, I'm guessing, would 
ave
DM>to be completely reworked to accomodate these.  Especially if you want to 
no
DM>allow, say:
DM>IVCV ?? 101
But all those numbers are non-roman. I guess I just have to add
something that says that if there is any character left after
parsing the input string, then the number is not valid.
DM>This is why the Roman Numeral problem is difficult.  Not impossible - you
DM>still follow a straight-forward methodology to come up with the 
"conversion"
DM>- but it's got a lot of little quirks.  :-)
DM>Good luck!
I'll try to "purify" the program of the C-isms,  but I won't make it
understand those abnormal cases. Roman Numerals are *always* in
the order: thousands - hundreds - tens - ones. Combinations such as
IL, VC, or IXCM are wrong
Alberto Monteiro
---
 þ SLMR 2.1a þ Another Day, another Death, another sorrow, another breat
--- FMail/386 1.02
---------------
* Origin: CentroIn! +55-21-205-0281, 41 lines, 24h, RJ/Brazil (4:802/21)

SOURCE: echomail via exec-pc

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.