Question

(c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....

(c++) Write a program that converts a positive integer into the Roman number system.(c++)

Roman numbers. Write a program that converts a positive integer into the Roman number system. The Roman number system has digits

I 1
V 5
X 10
L 50
C 100
D 500
M 1,000

Numbers are formed according to the following rules. (1) Only numbers up to 3,999 are represented. (2) As in the decimal system, the thousands, hundreds, tens, and ones are expressed separately. (3) The numbers 1 to 9 are expressed as

I 1
II 2
III 3
IV 4
V 5
VI 6
VII 7
VIII 8
IX 9

As you can see, a I preceding a V or X is subtracted from the value, and you can never have more than three I’s in a row. (4) Tens and hundreds are done the same way, except that the letters X, L, C and C, D, M are used instead of I and V, X, respectively.

Your program should take an input, such as 1978, and convert it to Roman numerals, MCMLXXVIII.

code

#include <iostream>
#include <string>
using namespace std;
int main()
{
//ask user to input num to convert

//if num is less than 0
{
cout << "Your number must be greater than zero.";
return 1;
}

string roman = "";

int digit = num / 1000;

//if digit is equal to three
{
roman = "MMM";
}
else if (...)
{
roman = "MM";
}
else if (...)   
{   
roman = "M";
}
num = num % 1000;
digit = num / 100;

if (digit == 9)
{
roman = ...
}
else if (digit == 4)
{
roman = ...
}
else
{
if (digit >= 5)
{
roman = roman + "D";
digit = digit - 5;
}
if (digit == 3)
{
roman = ...;
}
else if (digit == 2)
{
roman = ...;
}
else if (digit == 1)
{
roman = ...;
}
}   
num = num % 100;   
digit = num / 10;

if (digit == 9)
{
roman = roman + "XC";
}
else if (digit == 4)
{
roman = ...;
}
else
{
if (digit >= 5)
{
roman = ...;
digit = ...;
}
if (digit == 3)
{
roman = ...;
}
else if (digit == 2)
{
roman = ...;
}
else if (digit == 1)
{
roman = ...;
}
}   
digit = num % 10;   
if (digit == 9)
{
roman = ...;
}
else if (digit == 4)
{
roman =...;
}
else
{
if (digit >= 5)
{
roman = ...;
digit = ...;
}
if (digit == 3)
{
roman = ...;
}
else if (digit == 2)
{
roman = ...;
}
else if (digit == 1)
{
roman = ...;
}
}   
//print results
//return 0
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

main.cpp 1 // Program to convert integer number to romanNumeral numerals 2 3 #include iostream» 4 #include <string> 5 using n//by 1 ( postincrement) pointing the Location for the next array element for(int i-1; i<-counter;i++)1 31 romanNumeral [indexfor(int i-1; i<-counter;i++)1 59 60 61 romanNumeral[index+]-D // the remainder is calculated to get the number which is Less/is 9. Counter will be 1 if the digit is 9 and characters X C are added //to the array. counter-number/90; for(int i-l; 1< co//the remainder is calculated to get the number which is Less than 40 number number%40 ; 116 118 119 120 121 122 123 124 125for(int 1(scounter;i++){ 144 145 146 147 148 149 150 1-1; romanNumeral[index++]-V //the remainder is calculated to get the nfor(int i-0; i<index;i++)1 173 174 175 176 cout <<romanNumeral[i] 178 179 180 //main method to start the program execution 18// call the funtion to convert the decimal number to roman numeral convertDecimalToRoman(number); 202 203 204 205 206 return

==============================================================================================

Sample output screenshots:

Please enter the Decimal number to convert to Roman Numerals :: 3999 Given number :: 3999 Roman Numeral MMMCMXcIx

Please enter the Decimal number to convert to Roman Numerals:: 3899 Given number :: 3899 Roman Numeral :: MMMDCCCXCIX

Please enter the Decimal number to convert to Roman Numerals : 4000 ror !! Your number should be less than 4000.

Please enter the Decimal number to convert to Roman Numerals·2567 Given number :: 2567 Roman Numeral: MMDLXVII

Please enter the Decimal number to convert to Roman Numerals·467 Given number :: 467 Roman Numeral :: CDLXVII

Please enter the Decimal number to convert to Roman Numerals·320 Given number : 320 Roman Numeral :: СССХ

Add a comment
Know the answer?
Add Answer to:
(c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program in C++ that converts a number entered in Roman numerals to a positive...

    Write a program in C++ that converts a number entered in Roman numerals to a positive integer. Your program should consist of a class, say, romanType. An object of type romanType should do the following: Store the number as a Roman numeral. Convert and store the number as a positive integer. Print the number as a Roman numeral or positive integer as requested by the user. The integer values of the Roman numerals are: M = 1000; D = 500;...

  • C++ Write a program that converts anumber entered in Roman numerals to decimal.

    In C++ Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class, say,romanType. An object of typeromanTypeshould do the following:a. Store the number as a Romannumeral.b. Convert and store the number into decimalform.c. Print the number as a Roman numeral ordecimal number as requested by the user.The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1d. Test your program using the followingRoman numerals: MCXIV, CCCLIX,...

  • Write the roman.cpp implementation file that converts a number entered in Roman numerals to a positive...

    Write the roman.cpp implementation file that converts a number entered in Roman numerals to a positive integer. Your program should consist of a class, say, romanType. An object of type romanType should do the following: Step a: Store the number as a Roman numeral. Step b: Convert and store the number as a positive integer. Step c: Print the number as a Roman numeral or positive integer as requested by the user. Step d: Test your program using the following...

  • **c++*** Write a program that coverts a number to the roman number representation. Make sure to...

    **c++*** Write a program that coverts a number to the roman number representation. Make sure to use a single function that determines the units, tens, hundreds, and thousands digits.

  • Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its...

    Write and test a function toDecimal() that converts a roman number such as MCMLXXVII to its decimal number representation. Write a main program to test the function. Your function should have two arguments - the roman number as a string, and an error processing function. Write a helper function that will return the numeric value of each of the letters used in roman numbers. Then convert the string argument as follows look at the first two characters. If the first...

  • Write a Java program. In the "modern Roman" system a number is also a sequence of...

    Write a Java program. In the "modern Roman" system a number is also a sequence of M's, D's, C's, L's, X's, V's, and 1's. The symbols have to appear more or less in that order and the value of a number is obtained as before with one important exception: A symbol C, X, or I may precede a symbol of higher value, in which case the value of that symbol C, X, or I is taken to be negative. Write...

  • Write up a detailed solution to the problem: Design a program to convert a Roman numeral...

    Write up a detailed solution to the problem: Design a program to convert a Roman numeral to a decimal number. The program should read a Roman numeral. You may read it as a string or one character at a time. Do the conversion and then output the decimal number. Here are the “letters” you need to know: Symbol =   Value I   = 1 V =   5 X =   10 L =   50 C =   100 D =   500 M   =...

  • Write a function that converts an integer number in the range [1, 2000] into Roman Numerals....

    Write a function that converts an integer number in the range [1, 2000] into Roman Numerals. void IntToRoman(int n, char *roman); Write a main() program to test and demonstrate your function

  • Write a C program convert.c that converts each number in an array by the sum of...

    Write a C program convert.c that converts each number in an array by the sum of that number plus 6 modulus 10. A sample input/output: Enter the length of the array: 5 Enter the elements of the array: 3 928 4 14 77 Output: 9 4 0 0 3 The program should include the following function: void convert(int *a1, int n, int *a2) The function converts every element in array a1 of length n to an output array a2. The...

  • Write a C program to convert a given integer to roman number.Roman numerals are represented by...

    Write a C program to convert a given integer to roman number.Roman numerals are represented by 7different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT