Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduction - \"The numeric system represented by Roman numerals originated in

ID: 3588694 • Letter: I

Question


Introduction - "The numeric system represented by Roman numerals originated in ancient Rome and remained the usual way of writing numbers throughout Europe well into the Late Middle Ages. Numbers in this system are represented by combinations of letters from the Latin alphabet. Roman numerals, as used today, are based on seven symbols: Symbol I VX LC D M Value 5 10 50 100 500 1,000 The use of Roman numerals continued long after the decline of the Roman Empire. From the 14th century on, Roman numerals began to be replaced in most contexts by the more convenient Hindu-Arabic numerals; however, this process was gradual, and the use of Roman numerals persists in some minor applications to this day 5si Write a program that converts a number entered in Roman numerals to decimal. Also the program can add any two roman numbers and display the result in Roman numerals. Your program should consist of a class, say, romanType. Develop UML diagram for this class. An object of type romanType should do the following: 1. Store the number as a Roman numeral. 2. Convert and store the number into decimal form. 3. Add two roman numbers without converting them to decimal and then display the result in Roman format.[Hint: use the help link to solve this!] 4. Print the number as a Roman numerals or decimal number as requested by user. 5. Test your program using the following numerals: MCXIV, CCCLIX, MDCLXVI, CCCLXIX+ DCCCXLV

Explanation / Answer

NOTE : I am using C++ for this Code.

#include<iostream>
#include<string>
using namespace std;
class romanType                   //making required class
{  
   public:
       string s1,s5;
       int sum=0;
       int choice;
       void StoreNumber(string s4)
       {
           s1=s4;               //storing the number as roman numeral
       }
       int getvalue(char c)
       {
            if (c == 'I')
                 return 1;
            if (c == 'V')
                  return 5;
            if (c == 'X')
               return 10;
            if (c == 'L')
               return 50;
           if (c == 'C')
                  return 100;
           if (c == 'D')
                 return 500;
            if (c == 'M')
               return 1000;
           return 0;
       }
       void ConvertNumber()               //converting roman numeral to decimal number
       {
           for(int i=0;i<s1.length();i++)
           {
               int str1 = getvalue(s1[i]);
               if (i+1 < s1.length())
                 {
                     int str2 = getvalue(s1[i+1]);
                     if (str1 >= str2)
                     {
                       sum = sum+ str1;
                     }
                   else
                   {
                           sum = sum + str2 - str1;
                           i++;
                     }
                 }
               else
               {
                     sum = sum + str1;
                     i++;
                 }
           }
       }
       void AddTwoRomanNumbers(string s2,string s3)               //adding two roman numbers
       {
           s5=s2+s3;
       }
       void PrintNumber()               //printing the number choiced by user
       {
           cout<<"press 1 to see result in Decimal Number.. ";
           cout<<"press 2 to see result in Roman Numerals.. ";
           cout<<" Enter Your choice :";
           cin>>choice;
           switch(choice)
           {
               case 1:
                   cout<<" Decimal Number = "<<sum;
                   break;
               case 2:
                   cout<<" Roman Numerals = "<<s5;
                   break;
               default:
                   cout<<"Entered Incorrect Choice..";
           }
       }
};
int main()
{
   romanType r1;
   r1.StoreNumber("MCXIV");           // you can check for other roman numerals also by passing here
   r1.AddTwoRomanNumbers("CCCLXIX","DCCCXLV");          
   r1.ConvertNumber();
   r1.PrintNumber();  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote