(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
}
==============================================================================================
Sample output screenshots:
(c++) Write a program that converts a positive integer into the Roman number system.(c++) Roman numbers....
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 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...
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...
**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 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 to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...
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 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 =...
Convert this C++ language to PEP/8 assembly language. #include <stdio.h> int main(void) { int num, rem; printf("Enter a number: "); scanf("%d", &num); printf("Roman numerals: "); while(num != 0) { if (num >= 1000) // 1000 - m { printf("m"); num -= 1000; } else if (num >= 900) // 900 - cm { printf("cm"); num -= 900; } else if (num >= 500) // 500 - d { printf("d"); num -= 500; } else if (num >= 400) // 400 - cd { printf("cd"); num -= 400; } else if (num >= 100) // 100 - c { printf("c"); num -= 100; } else if (num >= 90) // 90 - xc { printf("xc"); num -= 90; } else if (num >= 50) // 50 - l { printf("l"); num -= 50; } else if (num >= 40) // 40 - xl { printf("xl"); num -= 40; } else if (num >= 10) // 10 - x { printf("x"); num -= 10; } else if (num >= 9) // 9 - ix { printf("ix"); num -= 9; } else if (num >= 5) // 5 - v { printf("v"); num -= 5; } else if (num >= 4) // 4 - iv { printf("iv"); num -= 4; } else if (num >= 1) // 1 - i { printf("i"); num -= 1; } } return 0;}
/** * This program Performs various number base conversions. It also verifies if * a number is valid in its base. * Author: M. Rahman * Date: 06 September 2018 */ public class NumberConversion { public static String dec2any(String dec, int base) { /** * Converts a decimal value to a target base * inputs: * dec: the decimal value to be converted * base: the target base * output: 256-base as dotted decimal, hex as usual, bases * over...