CS 141 Programming Assignment 3

Roman Numerals


Overview

For programming assignment 3, you are going to be converting arabic numbers to roman numerals and vice versa. More specifically, your program will take the name of two files on the command line. The first file should contain numbers either either a roman numerals like MCMLXXX1X or arabic numerals like 1989, one number per line. If the file contains roman numerals you should convert them to arabic numbers and if the file contains arabic numbers you should convert them to roman numerals.

For example, if the user ran your program like this:

./a.out foo.txt bar.txt

You would open an existing file foo.txt and produce a new file bar.txt that contains the translations.

If you cannot open the first file, you should print an error. If the first file contains anything other than valid numbers, you should print an error. In particular, if a line in the file contains invalid input, then print an error such as "Invalid input detected on line 5 of foo.txt". After any error, you can simply exit the program. In the case of an error, the contents of the output file is undefined.

Here is a sample input file and a corresponding output file . Notice that when you use the output file as input you should get back the original input file.

Inside your program you should have at least 2 functions arabicToRoman and romanToArabic that handle the conversions. For these two functions, please write clear pre and post condition comments.

You are only required to handle numbers from 1 to 3999. If you would like to try handling numbers above 3999, you can but they will require placing lines above digits to indicate larger numbers like 4000 or 5000.

Remember to start early!! Little logistical problems solved with a quick question or an email, turn into major crisis the night before the due date when no one is available to help. Also if you don't start early, you won't have time for testing with lots of users. Determine which office hours fit your schedule and plan to start the assignment before those!!! Then come in for help if you need it.


What to Turn In

You should turn in the assignment to the directory /afs/cu/class/cs141/students/YOUR_USERNAME/prog3 (e.g. I would put mine in /afs/cu/class/cs141/students/jmatthew/prog3). There should be three files:

  • A prog3.cpp file with the source code of your working program. The program must compile and run on polaris.clarkson.edu using g++. Remember to choose good variable names, use consistent, clear indentation and add good comments to explain your code.
  • A sample input file, input.txt. This file should attempt to thoroughly test your program. Try to include tests that will exercise all of your code, but do not do exhaustive testing (in other words no need to have a file with all numbers 1-3999 in roman and arabic!).
  • A correct output file corresponding to your input file called output.txt