Starting from:
$35

$29

Project 2 Solution




Write a C program project2.c that operates as follows. First your program reads a string which is expected to be an extended Roman numeral, and then it converts this string to an integer in the range from -3,999,999 to 3,999,999. Next your program should display this integer, unless the input string is not a valid extended Roman numeral, in which case it should just display the string “Error”. The entire input is one string. The entire output is either an integer or the string “Error”.

Classical Roman numerals are converted to integers one digit as a time, as follows:




Thousands
Hundreds
Tens
Units
1000
← M
100←C
10
← X
1
← I
2000
← MM
200 ← CC
20
← XX
2
← II
3000
← MMM
300 ← CCC
30
← XXX
3
← III




400
← CD
40
← XL
4
← IV




500
← D
50
← L
5
← V




600
← DC
60
← LX
6
← VI




700
← DCC
70
← LXX
7
← VII




800
← DCCC
80
← LXXX
8
← VIII




900
← CM
90
← XC
9
← IX
For this project, we extend the Roman numeral notation to obtain a larger range as follows:




Millions


Hundred thousands
Ten thousands
Thousands
1000000
← N
100000 ← B
10000
← Y
1000
← M
2000000
← NN
200000 ← BB
20000
← YY
2000
← MM
3000000
← NNN
300000 ← BBB
30000
← YYY
3000
← MMM




400000
← BE
40000
← YK
4000
← MU




500000
← E
50000
← K
5000
← U




600000
← EB
60000
← KY
6000
← UM




700000
← EBB
70000
← KYY
7000
← UMM




800000
← EBBB
80000
← KYYY
8000
← UMMM




900000
← BN
90000
← YB
9000
← MY
Furthermore, if the leading character in the input is ‘–‘ then this denotes a negative integer, and if the entire string is “–“ then this denotes the integer 0. Here are some example inputs and the corresponding expected outputs:







CS → Error




NNYKDCVIII → 2040608




NBBYYYMUDLXVII → 1234567




-NNNBEKUMDCCLXXXIX → -3456789




-BBBULXX → -305070




IBM → Error







Please carefully read the following requirements:




You must do your own work. You must not borrow any code from any other person, book, website, or any other source. You also must not share your code with any other person, or post it on any website. We run plagiarism detection software on every project. So if you violate these rules, you may receive an invitation to the dean’s office to discuss the penalties for academic misconduct.



Make sure your program runs properly on the cs-intro.ua.edu server. Your program will be graded on that system using this command: gcc project2.c –Wall –lm –std=c99. In particular, make sure your program initializes the values of all variables when they are declared or allocated. Otherwise it might behave differently on Linux than it does on a PC or Mac.



Compress your project into a zip file that contains your C program source file. Right-click (or secondary click) on your project directory, and then (depending on your operating system) select either the Compress option or Send To → Compress from the popup menu. Finally upload your .zip file that contains your .c file for this project to Blackboard.



If you violate the above requirements such that it breaks our grading script, your project will be assessed a significant point deduction, and extreme or multiple violations may cause the project to be considered ungradable.



Every semester many students lose some points because they don’t follow all the instructions. So please read and follow all the project specifications precisely to prevent losing points unnecessarily. If anything is unclear, please ask for clarification well before the project is due. Please pay particular attention to input and output formats.



Submit your project on Blackboard by the due date (11:59pm Friday). There is a grace period of 24 hours (until 11:59pm Saturday). Projects submitted on Sunday will be assessed a late penalty of 5% per hour. No projects will be accepted after Sunday. Once it is graded, your project score will be posted on Blackboard and the results of the grading script will be sent to your Crimson email account.



Double-check and triple-check your submission when you submit it. Errors discovered later cannot be fixed and resubmitted after the project is graded. Projects will not be re-graded unless an error is found in the grading script or in the input/output files that are used during grading.

More products