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

 -=> Quoting Alberto Monteiro to James Norman
 AM> ostream& operator<<(ostream& Out, Roman& R)
 AM> {
 AM> Out << R.str;
 AM> return Out;
 AM> }
You may want to hide both str and n and provide operator char* and operator
int instead...
 AM> //
 AM> // Roman input
 AM> //
 AM> istream& operator>>(istream& Inpu, Roman& R)
 AM> {
 AM> char str0[50];
 AM> Inpu >> str0;
 AM> R = Roman(str0);
 AM> return Inpu;
 AM> }
What happens if you already have a Roman string created?  You lose memory...
try deallocating the string, first.  Better yet, use the string class rather
than the char* with strdup.
I'm not convinced it works, but your test program tests my suspicions, so
I'll just have to try it.  :->
Yeah, I was worried about that.  First of all, you have a str[1000] that's
never used in the .cpp portion.  :-)
Second, a few other test cases:
IL = 49  [core dumped!]
IIC = 98
VC = 95
And, the slightly more obscure:
IVC = 96
These are a few that you fail on.  Your algorithm, I'm guessing, would have
to be completely reworked to accomodate these.  Especially if you want to not
allow, say:
IVCV ?? 101
This is why the Roman Numeral problem is difficult.  Not impossible - you
still follow a straight-forward methodology to come up with the "conversion"
- but it's got a lot of little quirks.  :-)
Good luck!
... RAM = Rarely Adequate Memory
--- FastEcho 1.46
---------------
* Origin: House of Fire BBS - Toronto - (416)601-0085 - v.34 (1:250/536)

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™.