( Index )


Brief Information about the November '16 CSIG Meeting

Roman.exe - An application to calculate Roman Numerials

by Bruce Arnold .


Random Screen Shot

Welcome to the CSIG, a Special Interest Group of the ACGNJ. This is an exciting time for the C Language programming since Microsoft now has 4 different language compilers: C++, C++ Express, C-Sharp, and C-Sharp Express. These are all capable of creating Windows (tm) programs. (Some are FREE!)  During the meeting there will be time for Random Access Questions as well as other discussions. Since this is a complex subject, the presentation will continue during the October meeting.

Here's a brief synopsis of the coming meeting:

A conversion application for Roman Numerials will be presented along with design considerations for a graphical interface.

Here's a brief explaination from Wikipedia

Roman numeric system

The numbers 1 to 10 are usually expressed in Roman numerals as follows:


Numbers are formed by combining symbols and adding the values, so II is two (two ones) and XIII is thirteen (a ten and three ones). Because each numeral has a fixed value rather than representing multiples of ten, one hundred and so on, according to position, there is no need for "place keeping" zeros, as in numbers like 207 or 1066; those numbers are written as CCVII (two hundreds, a five and two ones) and MLXVI (a thousand, a fifty, a ten, a five and a one).

Symbols are placed from left to right in order of value, starting with the largest. However, in a few specific cases,[2] to avoid four characters being repeated in succession (such as IIII or XXXX), subtractive notation is used: as in this table:[3][4]

Number 4 9 40 90 400 900
Notation IV IX XL XC CD CM

I placed before V or X indicates one less, so four is IV (one less than five) and nine is IX (one less than ten)
X placed before L or C indicates ten less, so forty is XL (ten less than fifty) and ninety is XC (ten less than a hundred)
C placed before D or M indicates a hundred less, so four hundred is CD (a hundred less than five hundred) and nine hundred is CM (a hundred less than a thousand)[5]

For example, MCMIV is one thousand nine hundred and four, 1904 (M is a thousand, CM is nine hundred and IV is four).

Some examples of the modern use of Roman numerals include:

1954 as MCMLIV, as in the trailer for the movie The Last Time I Saw Paris[6]
1990 as MCMXC, used as the title of musical project Enigma's debut album MCMXC a.D., named after the year of its release.
2014 as MMXIV, the year of the games of the XXII (22nd) Olympic Winter Games (in Sochi)


This month's program uses Microsoft DOT NET C# code (CLI) to create a Windows Forms Application.  The Forms Class created contains a few methods that we will discuss in detail.  Some methods have simple mathematical calculations.  Others involve the graphics call necessary to produce the photo shown above.  An Error-Free input stratagy will also be presented.  Source code is available as well as an execuitable.

The program uses some of the most sophisticated Dot Net Library functions including the following:

using System
using System.Windows.Forms

There are a number of ways to refer to Microsoft's latest compilers and code. Here's what Wikipedia says: The Common Language Infrastructure (CLI) is an open specification developed by Microsoft that describes the executable code and runtime environment that form the core of the Microsoft .NET Framework. The specification defines an environment that allows multiple high-level languages to be used on different computer platforms without being rewritten for specific architectures.

Microsoft .Net Framework 4.5
C++ / C#
Visual Studio Community 2015
Common Language Infrastructure

Sample Code

/* Roman.cs B.Arnold Nov. 2016 ACGNJ CSIG Object: To convert a decimal number to Roman Numerials Algorithm: There are dozens (maybe hundreds) of algorithms. I presented my own at the December 2002 Csig meeting which is available on at http://acgnj.barnold.us/Csig0212.htm In this graphical presentation, I have used an algorithm from StackOverflow.com. See below for function IntegerToRomanNumeral(int input). Compiler: Microsoft Visual Studio 2015. C-sharp. */ using System; using System.Windows.Forms; namespace Roman { public partial class Roman : Form { public Roman() { InitializeComponent(); } private void ArabicInput_TextChanged(object sender, EventArgs e) { try { if (ArabicInput.TextLength == 0) RomanOutput.Clear(); int x = int.Parse(this.ArabicInput.Text); ConvertToRoman(x); } catch { int CursorIndex = ArabicInput.SelectionStart - 1; if (CursorIndex >= 0) { ArabicInput.Text = ArabicInput.Text.Remove(CursorIndex, 1); //Align Cursor to same index ArabicInput.SelectionStart = CursorIndex; ArabicInput.SelectionLength = 0; } } } private void ConvertToRoman(int x) { if (x > 3999 || x < 1) { RomanOutput.Text = "Out of Range"; return; } RomanOutput.Text = this.IntegerToRomanNumeral(x); } // REF: The following code is from http://stackoverflow.com // /questions/12967896/converting-integers-to-roman-numerals-java private string IntegerToRomanNumeral(int input) { if (input < 1 || input > 3999) return "Invalid Roman Number Value"; string s = ""; while (input >= 1000) { s += "M"; input -= 1000; } while (input >= 900) { s += "CM"; input -= 900; } while (input >= 500) { s += "D"; input -= 500; } while (input >= 400) { s += "CD"; input -= 400; } while (input >= 100) { s += "C"; input -= 100; } while (input >= 90) { s += "XC"; input -= 90; } while (input >= 50) { s += "L"; input -= 50; } while (input >= 40) { s += "XL"; input -= 40; } while (input >= 10) { s += "X"; input -= 10; } while (input >= 9) { s += "IX"; input -= 9; } while (input >= 5) { s += "V"; input -= 5; } while (input >= 4) { s += "IV"; input -= 4; } while (input >= 1) { s += "I"; input -= 1; } return s; } } }


Source Code Files

For help, email me at b a r n o l d @ i e e e . o r g
Back to C++ Main Page