Question

*KEEP IT SIMPLE PLEASE* Write a program that allows the user to convert any integer number...

*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 greater or equal I.

- Repeat until the user enter -1 (main menu).

• You should use at least one class (.h and .cpp).

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

// ConsoleApplication1.cpp : Defines the entry point for the console application.
//


#include <iostream>
#include <string>
using namespace std;
void menu(){
   cout << endl;
   cout << ":::::::::::: CALCULATOR :::::::::::::::" <<endl;
   cout << "1. Integer 2 Roman" << endl;
   cout << "2. Roman 2 Integer" << endl;
   cout << "3. Exit" << endl;
   cout << ":::::::::::::::::::::::::::::::::::::::" << endl;
}
int changer(char rom)
{
   if (rom == 'I')
       return 1;
   if (rom == 'V')
       return 5;
   if (rom == 'X')
       return 10;
   if (rom == 'L')
       return 50;
   if (rom == 'C')
       return 100;
   if (rom == 'D')
       return 500;
   if (rom == 'M')
       return 1000;
   return -1;
}
int rom2Dec(string str)
{
   int output = 0;
   for (int i = 0; i<str.size(); i++)
   {
       int state = changer(str[i]);
       if (i + 1 < str.size())
       {
           int state2 = changer(str[i + 1]);
           if (state >= state2)
           {
               output = output + state;
           }
           else
           {
               output = output + state2 - state;
               i++;
           }
       }
       else
       {
           output = output + state;
       }
   }
   return output;
}
void dec2rom(int num){
   int number[] = { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 };
   char *letter[] = { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" };
   int i = 0;
   while (num){
       while (num / number[i]){
           cout<<letter[i];
           num = num-number[i];
       }
       i++;
   }
}
int main(){
   int choice;
   while (1){
       menu();
       cout << "Enter choice: ";
       cin >> choice;
       if (choice == 1){
           int number;
           cout << "Enter number to convert: ";
           cin >> number;
           dec2rom(number);
       }
       else if (choice == 2){
           string roman;
           cout << endl;
           cout << "Enter roman to number: ";
           cin.ignore();
           getline(cin, roman);
           cout<<rom2Dec(roman);
       }
       else {
           return 0;
       }

   }
   return 0;
}

OUTPUT:

IF YOU HAVE ANY QUERY PLEASE COMMENT DOWN BELOW

PLEASE GIVE A THUMBS UP

Add a comment
Know the answer?
Add Answer to:
*KEEP IT SIMPLE PLEASE* Write a program that allows the user to convert any integer number...
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;...

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

  • *MUST BE IN C PROGRAMMING* Demonstrate the ability to think critically Demonstrate the ability to work...

    *MUST BE IN C PROGRAMMING* Demonstrate the ability to think critically Demonstrate the ability to work with strings and chars Demonstrate the ability to design a menu system Write a simple program that allows the user to enter a number between 1 and 1000.  The program will then display the Roman numeral equivalent.  Allow the user to keep entering numbers for conversion to Roman numerals, or to quit, using a menu system of your own design. Submission Requirements: You are to write...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    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 contacts database program that presents the user with a menu that allows the user...

    Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...

  • This lab will exercise your understanding of some of the concepts covered in Chapter 10: classes,...

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

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

  • Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices....

    Objectives: Integer arithmetic, Functions, menus. Write a C++ program that displays the following menu of choices. 1. Find the number of digits in an integer. 2. Find the nth digit in an integer. 3. Find the sum of all digits of an integer. 4. Is the integer a palindrome? 5. Quit Enter a choice: Page 1 of 4 For each of the choices (1, 3, 4), Read a positive integer number and call a function that processes the menu choice...

  • Write a program that displays a menu on the screen. The menu will give the user...

    Write a program that displays a menu on the screen. The menu will give the user four options - enter two integers, enter two decimal numbers (#.#), enter one integer and one decimal number, or quit. The inputs should be labelled a, b, c, or d, and you should enter in the letter to choose the appropriate option. Once the user selects the option, two numbers will be read in from the user. The numbers will be added together and...

  • Write a program that allows the user to enter an unsigned integer (the maximum value of...

    Write a program that allows the user to enter an unsigned integer (the maximum value of an unsigned 4-byte int is 232 = 4,294,967,296) and reverses its format (from little to big endian, or vice versa). Print out the user-entered number in hexadecimal and binary, reverse the endianness, and print the reverse in hexadecimal and binary. Integers in most machine architectures are represented in little endian format: the least significant byte is stored in the smallest address; for instance, the...

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