Question

**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.

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

Program:


#include <iostream>
using namespace std;
int ConvertNumToRoman(int number);   
int main()
{
int number;
cout<<"Enter number is:";
cin>>number;
ConvertNumToRoman(number);
return 0;
}
int ConvertNumToRoman(int number)
{
int num[] = {1,2,4,5,9,10,20,40,50,90,100,200,400,500,900,1000};
string Roman[] = {"I","II","IV","V","IX","X","XX","XL","L","XC","C","CC","CD","D","CM","M"};
int i=15;   
while(number>0)
{
int a = number/num[i];
number = number%num[i];
while(a--)
{
cout<<Roman[i];
}
i--;
}
}

output:

Enter number is:10   

X

Enter number is:100                                                                                                                            

C

Enter number is:1000

M

Add a comment
Know the answer?
Add Answer to:
**c++*** Write a program that coverts a number to the roman number representation. Make sure to...
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
  • (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....

  • 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;...

  • 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...

  • 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 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 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...

  • 2) Write a program in C/C++ that asks the user to enter a number then the...

    2) Write a program in C/C++ that asks the user to enter a number then the user's input value is passed to a function which increments the number by 10 and returns the result of the incrementation. Write the program to accomplish the increment using three (3) different techniques. To test each technique separately, the user should enter a different number for each of the three (3) techniques. Make sure that you compile and execute your program. Finally, provide screenshots...

  • write a bash program to do merge sort. in that program make sure, you read the...

    write a bash program to do merge sort. in that program make sure, you read the array of size 20 using a function, and another function for output of the array and use separate functions to do merge sort

  • ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help...

    ** C++ LANGUAGE ** Write a function that will implement each Fibonacci number with the help of an integer array of size 100 (elements of this array will be digits of the Fibonacci number). When the function is called to find , it will calculate all Fibonacci numbers from to using the basic formula . To add two Fibonacci numbers, the function will add elements of two arrays corresponding to and and store their sums in the array corresponding to...

  • Task 4: a) Write a function named change() that has an integer parameter and six integer...

    Task 4: a) Write a function named change() that has an integer parameter and six integer reference parameters named hundreds, fifties, twenties, tens, fives, and ones. The function is to consider the passed integer value as a dollar amount and convert the value into the fewest number of equivalent bills. Using the reference parameters, the function should alter the arguments in the calling function. b) Include the function written in part a in a working program. Make sure your function...

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