Dear,
Here is the code
//Class Declaration
#include<string>
using namespace std;
class romanType
{
public :
romanType( string = "" );
void setRoman( string );
void convertToDecimal();
void printRoman();
void printDecimal();
private:
string roman;
int decimal;
};//end class definition of romanType
romanType::romanType( string myRoman )
{
roman = myRoman;
decimal = 0;
}//end constructor romanType
void romanType::setRoman( string myRoman )
{
roman = myRoman;
decimal = 0;
}//end function setRoman
void romanType::convertToDecimal()
{
char romans[7] = { 'M', 'D', 'C', 'L', 'X', 'V', 'I'};
int decimals[ 7 ] = { 1000, 500, 100, 50, 10, 5, 1 };
int j, pos;
size_t len = roman.length();
//process the numeral
for ( unsigned int i = 0; i < len - 1; i++ )
{
//find the roman letter
for ( pos = 0; pos < 7; pos++ )
if ( roman.at( i ) == romans[ pos ] )
break;
//check for validity of the roman letter
if ( pos < 7 )
{
//check the next roman letter's value
for ( j = 0; j < pos; j++ )
if ( roman.at( i + 1 ) == romans[ j ] )
break;
//add or subtract the dec. val
//according to the values of j and pos
if ( j == pos )
decimal += decimals[ pos ];
else
decimal -= decimals[ pos ];
}
}//end for
//process the last numeral value
for ( j = 0; j < 7; j++ )
if ( roman.at( len - 1 ) == romans[ j ] )
break;
//add the dec. val of roman letter to the dec. number
decimal += decimals[ j ];
}//end function convertToDecimal
void romanType::printRoman()
{
cout << "nntThe roman numeral is " << roman;
}//end function printRoman
void romanType::printDecimal()
{
cout << "ntThe decimal equivalent of the "
<< "given roman numeral is " << decimal;
}//end function printDecimal
/* Main method to test the class*/
int main()//function main begins program execution
{
//let the user know about the program
cout << "nntProgram that convert Roman Numeral"
<< " into decimal form.";
//instantiate object of type romanType
romanType r;
string rns[ 3 ] = { "CCCLIX", "MCXIV", "MDCLXVI" };
for ( int i = 0; i < 3; i++ )
{
//set the roman numeral string
r.setRoman( rns[ i ] );
//convert the roman numeral into decimal form
r.convertToDecimal();
//print the roman numeral
r.printRoman();
//print the decimal form of numeral
r.printDecimal();
}//end for
cout << "nnt";
system( "pause" );
return 0;// indicate program executed successfully
}// end of function, main
Hope this will help you..
C++ Write a program that converts anumber entered in Roman numerals to decimal.
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 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...
object oriented programming:Write a program that converts a number entered in decimal toRoman numerals. Your program should consist of a class, say, romanType. Anobject of type romanType should do the following:a. Store the number as a decimal.b. Convert and store the number into roman form.c. Print the number as a Roman numeral or decimal number as requestedby the user.The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1
This lab will exercise your understanding of some of the concepts covered in Chapter 10: classes, default constructors, overloaded constructors, arrays of classes A Roman numeral represents an integer using letters. Examples are XVII to represent 17, MCMLIII for 1953, and MMMCCCIII for 3303. By contrast, ordinary numbers such as 17 or 1953 are called Arabic numerals. The following table shows the Arabic equivalent of all the single-letter Roman numerals: M 1000 X 10 D 500 V 5 C...
.data # This data will serve as our map between the roman # and the decimal numbers. Here, each list will # serve as our makeshift "array", where the conversion # from decimal to roman will be according to each indice, # i.e. decimalNumeral[i] will dictate romanNumeral[i]. # This also will be useful when converting roman to # decimal, as romanNumeral[i] will dictate decimalNumeral[i] decimalNumeral: .word 1000 100 50 10 5 1 # the decimal map romanNumeral: .asciiz "MDCLXVI" #...
(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 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 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 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
*KEEP IT SIMPLE PLEASE* Write a program that allows the user to convert any integer number to Roman numeral and the other way around. - You should create and print a menu that allows the user to select either Roman to Int or Int to Roman. - If one option is selected then you should promote the user to enter the number and then you print the equivalence in the other system. - Validate input, i.e Roman numerals should be...