Question

c++ object oriented programming

object oriented programming:
Write a program that converts a number entered in decimal to
Roman numerals. Your program should consist of a class, say, romanType. An
object 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 requested
by the user.
The decimal values of the Roman numerals are:
M 1000
D 500
C 100
L 50
X 10
V 5
I 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <iostream>
#include <string>
using namespace std;
class romanType
{
public:
    romanType(int);
    void decToRoman();
    void printIndecmal();
    void printInRoman();
private:
    string numR;
    int numD;
};
romanType::romanType(int n)
{numR="";
numD=n;
}
void romanType::decToRoman()
{int numbers[8]={1,5,10,50,100,500,1000,5000},i,p,num;
char letters[8]={'I','V','X','L','C','D','M'};
num=numD;
    while(num>0)
        {i=0;
         while(i<7)
            {while(num>=numbers[i]&&num<numbers[i+1])
                 {p=i%2;
                   if(num>=numbers[i+1]-numbers[i-p])
                        {numR=numR+letters[i-p]+letters[i+1];
                         num=num-(numbers[i+1]-numbers[i-p]);
                         }
                    else
                         {numR=numR+letters[i];
                          num=num-numbers[i];
                          }
                    }
               i++;
              }
          }
}
void romanType::printIndecmal()
{cout<<numD;
}
void romanType::printInRoman()
{cout<<numR;
}
int main()
{int n;
cout<<"Enter a number to convert: ";
cin>>n;
romanType r(n);
r.decToRoman();
r.printIndecmal();
cout<<" decimal = ";
r.printInRoman();
cout<<" roman\n";
system("pause");
return 0;
}


answered by: codegates
Add a comment
Know the answer?
Add Answer to:
c++ object oriented programming
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;...

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

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

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

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

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

  • 3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16...

    3. (a) Outline any four features of Object-Oriented Programming OOP, giving examples in each case. [16 marks]      (b) Consider the following code fragments: If   a = 10; Evaluate the new value of “b” in the following:                (i)   b =   ++ a;               (ii) b = a ++;             What value would a and b store in (i) and (ii) after program execution?                                                                                                            [4 marks] 4. Create a C++ program that makes use of three arrays; name, mark, grade. The program should accept...

  • Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete...

    Assignment Draw a flowchart, using Microsoft Visio or LucidChart, to document the logic required to complete this program Save the flowchart as a PDF file Develop a C++ program, following the logic in your flowchart, to convert a series of whole number decimal values to their Roman equivalent. Develop a function that will accept a whole number value in the range 1-9999 and return a string containing the long-form Roman Numeral equivalent of the input value, consisting only of upper-case...

  • This is for my Object Oriented Programming class, I know how to set it up in...

    This is for my Object Oriented Programming class, I know how to set it up in Python, but clueless in setting it up as Javascript. (1) Write a program that prompts the user for a positive integer and then prints a diamond pattern in which the number of asterisks on the middle line is equal to their entered integer. The example below printed if the user types in "3". * * * * * * * * *

  • Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing...

    Programming Assignment 6: Object Oriented Programming Due date: Check Syllabus and Canvas Objectives: After successfully completing this assignment, students will practice Object Oriented design and programming by creating a Java program that will implement Object Oriented basic concepts. RetailItem Class: Part 1: Write a class named RetailItem that holds data about an item in a retail store. The class should have the following fields: • description. The description field references a String object that holds a brief description of 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