![]() |
|
#1
|
|||
|
|||
help writing a roman numeral to decimal programHi guys! okay, so I must write a program that converts a number that was entered in Roman numerals to normal numbers. The program has to impliment a class that should do the following: 1. store the number as a roman numeral, 2. convert and store the number into a decimal, and 3. print the number as a roman numeral or normal number, as requested by the user.
and just as bg info, im using the microsoft visual C++ 6.0 compiler... and just as a reminder on roman numerals (for ppl who are rusty like me and dont remember the roman numerals, lol): M=1000, D=500, C=100, L=50, X=10, V=5, I=1 CPP / C++ / C Code:
|
|||
|
#2
|
|||
|
|||
Re: help writing a roman numeral to decimal programQuote:
I wrote a bit to help get you started. Please note that it works "some what," but doesn't (yet) contain the necessary logic for properly processing Roman numerals when a "smaller" is between two largers. EG: MCM = 1900 (not 2100, which is what my code will produce!) I figured that I can put forth a bit of code and you can add the simple hack needed to figure this out. Let me know if you have troubles with it. Also, I didn't test my code with VC++, as I'm using Linux and GCC. CPP / C++ / C Code:
...note that I made some fairly "radical" design changes to your code. Also, I added the ability to convert decimal to Roman, which seemed natural for the class. Notice also that some functionality is "stubbed out," in that I didn't implement "setDecimal," which would need a refactoring of the ctors to call a protected init operation that would "dynamically" re-initialize the class members based on the calls, setDecimal and/or setRoman, which, the latter, I didn't even stub out...as I started to reach my ~10-minute threshold for responses Of some interest, you should note that I modified all of the silly private members MDCLXVI to const static ints, which is strongly preferred. HTH... :davis: |
|
#3
|
|||
|
|||
Re: help writing a roman numeral to decimal programaahhh, thank you very much!
i am having one strange problem though, it says for the const static ints: "illegal pure syntax, must be '=0' " and "pure specifier can only be specified for functions" |
|
#4
|
|||
|
|||
Re: help writing a roman numeral to decimal programQuote:
That is a problem with VC++ 6.0. Just move the initialization of the members out of the class and into global scope: CPP / C++ / C Code:
...you'll also need to fix the following: Code:
...note that MCM = 1900 and even though MDCCCC does equal 1900, MCM is the "proper" way to use Roman numerals. It is the whole VIIII versus IX thing or IIII versus IV. The "convention" is that if there is no larger number in front, then to use the "more verbose" method. VIIII would be preferable to IX, but VIV would be preferrable to VIIII. It is the "smaller between two largers" issue. The convention basically states use the fewest symbols to convey the final number such that: VII = 7 ...is preferred over: VIIIV = 7 ...both are "mathematically" correct if implemented, but in reality, if someone enters a 7 in decimal, it should spit out VII and not VIIIV. You should never find a smaller starting out with a larger after it. CD = illegal (400?) CCCC = 400 (proper) ...even though CD is two symbols compared to the four. You ought to have some fun working out that algorithm :davis: |
Recent GIDBlog
Toyota - 2009 May Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Need help writing a program that reads from a file and converts it to binary. | edd_y_123 | C Programming Language | 3 | 18-Dec-2005 11:21 |
| Frustration...Roman Numeral Program | SpyD3r | C++ Forum | 14 | 13-Nov-2005 21:02 |
| ROMAN Numeral Pt. 2, Floating Point Exception | SpyD3r | C++ Forum | 1 | 13-Nov-2005 01:02 |
| Roman to decimal to roman | SpudNuts | C++ Forum | 2 | 16-Feb-2005 20:44 |
| Hex Result giving strange answers. | Rosdahale | C Programming Language | 6 | 07-Dec-2004 21:28 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The