View the step-by-step solution to:

#include <iostream> using namespace std; int main() { // Initialize user input to 1 in order to enter loop int num = 1; // Initialize array to

C++ - Simple example of using classes and header files.

Write a program that displays the roman numeral equivalent of any decimal number between 1 and 20 that the user enters. The roman numerals should be stored in an array of strings and the decimal number that the user enters should be used to locate the array element holding the roman numeral equivalent. The program should have a loop that allows the user to continue entering numbers until an end sentinel of 0 is entered.

Input validation: Do not accept scores less than 0 or greater than 20.

My code works correctly in one main.cpp, but how could I split this up using a separate class and header file? It's supposed to help us understand object-oriented programming. Thanks!

#include <iostream> using namespace std; int main() { // Initialize user input to 1 in order to enter loop int num = 1; // Initialize array to 20+1 in order to match integer equivalent string roman[21] = {"", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", "XV", "XVI", "XVII", "XIII", "XIX", "XX"}; // Loop while the user enters valid input do { cout << "Please enter a # between 1 and 20 to convert (0 to quit): "; cin >> num; if (num>0 && num<21) cout << num << " as a Roman Numeral is <" << roman[num] << "> \n"; else if (num != 0) cout << "Error, entry not valid. \n"; } while (num != 0); return 0; }
Background image of page 1
Sign up to view the entire interaction

Top Answer

Please see the attached... View the full answer

Sign up to view the full answer

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question
Ask a homework question - tutors are online