206k views
1 vote
Write a program that asks the user to enter a number within the range of 1 through 10. Use a switch statement to display the Roman numeral version of that number. Do not accept a number less than 1 or greater than 10. The output of the program should be just a Roman numeral, such as VII. Your program class should be called RomanNumerals

User Gandi
by
3.7k points

1 Answer

2 votes

Answer:

Following are the program in the C++ Programming Language.

//set header file

#include<iostream>

//set namespace

using namespace std;

//define class

class RomanNumerals

{

public:

//declare integer type variable

int number;

void getin()

{

//print message to get input

cout << "Enter a number (1 - 10): ";

//get input from the user

cin >> number;

}

void roman(){

//set switch statement

switch (number)

{ //check that the input is 1

case 1:

cout << "Roman numeral of " << number << " is: ";

cout << "I.";

break;

//check that the input is 1

case 2:

cout << "Roman numeral of " << number << " is: ";

cout << "II.";

break;

//check that the input is 1

case 3:

cout << "Roman numeral of " << number << " is: ";

cout << "III.";

break;

//check that the input is 1

case 4:

cout << "Roman numeral of " << number << " is: ";

cout << "IV.";

break;

//check that the input is 1

case 5:

cout << "Roman numeral of " << number << " is: ";

cout << "V.";

break;

//check that the input is 1

case 6:

cout << "Roman numeral of " << number << " is: ";

cout << "VI.";

break;

//check that the input is 1

case 7:

cout << "Roman numeral of " << number << " is: ";

cout << "VII.";

break;

//check that the input is 1

case 8:

cout << "Roman numeral of " << number << " is: ";

cout << "VIII.";

break;

//check that the input is 1

case 9:

cout << "Roman numeral of " << number << " is: ";

cout << "IX.";

break;

//check that the input is 1

case 10:

cout << "Roman numeral of " << number << " is: ";

cout << "X.";

break;

//if the input is other than requirement

default:

cout << "Enter number between 1 to 10.";

break;

}

}

};

//define main method

int main()

{

RomanNumerals ob;

ob.getin();

ob.roman();

return 0;

}

Output:

Enter a number (1 - 10): 9

Roman numeral of 9 is: IX.

Step-by-step explanation:

Following are the description of the program.

  • Set the required header file and define class 'RomanNumerals'.
  • Declare integer data type variable then, set void type function 'getin()' that gets input from the user.
  • Again define void type function 'roman()' and inside it, we set switch statements that print the roman number according to the number.
  • Finally, set the main method and inside it, we set an object of the class then, through the object we call the following functions.
User PGH
by
4.2k points