Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,271 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,447 people online right now. Registration is fast and FREE... Join Now!




Roman Numeral

 
Reply to this topicStart new topic

Roman Numeral

Rating  3
Felisha
16 Dec, 2006 - 01:05 AM
Post #1

New D.I.C Head
*

Joined: 15 Dec, 2006
Posts: 9


My Contributions
OK..... so I don't know if I am on the right track with this.. If someone could please help me out it would be greatly appreciated.
You can either e-mail me at sweetcheeks_18@hotmail.com or post a message.. Thanks

Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class, say Roman. An object of the type Roman should do the following:

a. Store the number as a Roman numeral

b. Convert and store the number into decimal

c. Print the number as 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


CODE

include <iostream>
using namespace std;

class romanType{
public:
    void roman();
    int convert();
    void print();
    void get();

private:
    int M, D, C, L, X, V, I;
    char romanNumeral;
};
void romanType::roman(){
    M = 1000;
    D = 500;
    C = 100;
    L = 50;
    X = 10;
    V = 5;
    I = 1;
}
int romanType::convert(){
    if (romanNumeral = M){
        cout << 1000;
    }else if(romanNumeral = D){
        cout << 500;
    }else if(romanNumeral = C){
        cout << 100;
    }else if(romanNumeral = L){
        cout << 50;
    }else if(romanNumeral = X){
        cout << 10;
    }else if(romanNumeral = V){
        cout << 5;
    }else if(romanNumeral = I){
        cout << 1;
    }
    return romanNumeral;
}
void romanType::print(){
    cout << romanNumeral << endl;
}
void romanType::get(){
}
int main(){
    char romanNumeral;
    cout << "Welcome to the Roman numeral to decimal converter!\nPlease enter a number in Roman numerals to be converted: ";
    cin >> romanNumeral;

    //print();
return 0;
}

User is offlineProfile CardPM
+Quote Post

horace
RE: Roman Numeral
16 Dec, 2006 - 04:00 AM
Post #2

D.I.C Addict
Group Icon

Joined: 25 Oct, 2006
Posts: 573



Thanked: 4 times
Dream Kudos: 50
My Contributions
mainly along the right lines, you had a few problems with convert() - also added a constructor
CODE

#include <iostream>
using namespace std;

class romanType{
public:
    romanType(char&);  // ** make constructor
    int convert();
    void print();
    void get();

private:
    int M, D, C, L, X, V, I;
    char romanNumeral;
};
romanType::romanType(char &ch){
    M = 1000;
    D = 500;
    C = 100;
    L = 50;
    X = 10;
    V = 5;
    I = 1;
    cout << ch << endl;
    romanNumeral=ch;     // ** set up romanNumeral
}
int romanType::convert(){
    if (romanNumeral == 'M'){
        return 1000;                   // ** return value
    }else if(romanNumeral == 'D'){
        return  500;
    }else if(romanNumeral == 'C'){
        return  100;
    }else if(romanNumeral == 'L'){
        return  50;
    }else if(romanNumeral == 'X'){
        return  10;
    }else if(romanNumeral == 'V'){
        return  5;
    }else if(romanNumeral == 'I'){
        return  1;
    }
    return 0;   // ** error -
}
void romanType::print(){
    cout << romanNumeral << endl;
}
void romanType::get(){
}
int main(){
    char romanNumeral;
    cout << "Welcome to the Roman numeral to decimal converter!\nPlease enter a number in Roman numerals to be converted: ";
    cin >> romanNumeral;
    romanType roman=romanType(romanNumeral);  //  ** set up value
    cout << roman.convert() << endl;;

    system("pause");
return 0;
}


User is offlineProfile CardPM
+Quote Post

ericode
RE: Roman Numeral
16 Dec, 2006 - 05:47 AM
Post #3

D.I.C Head
Group Icon

Joined: 9 Dec, 2006
Posts: 89


Dream Kudos: 75
My Contributions
shouldn't this be in the C++ section?
User is offlineProfile CardPM
+Quote Post

selloorhari
RE: Roman Numeral
7 Feb, 2008 - 06:27 AM
Post #4

D.I.C Head
**

Joined: 7 Feb, 2008
Posts: 66


My Contributions
my reply is!

Hi pal,

Here is my reply to your question..
PLZ reply your opinion to me ...


#include<stdio.h>
#include<stdlib.h>
void main()
{
// M =1000, D = 500 , C = 100 , L = 50 , X = 10 , V = 5 , I = 1 ;
/* Program by Sri K. Hari */
/* mail your opinion to me PLZ */

/* Divide by 1000 add that much M, subtract with that amount of 1000
then do for 500,100,50,10 and for unity..
Be careful for 900,90 and 9 */


}

This post has been edited by selloorhari: 7 Feb, 2008 - 07:10 AM
User is offlineProfile CardPM
+Quote Post

selloorhari
RE: Roman Numeral
7 Feb, 2008 - 07:11 AM
Post #5

D.I.C Head
**

Joined: 7 Feb, 2008
Posts: 66


My Contributions
Since the term & conditions are not supporting me to send my prg to you through this forum... Sorry Pal...

User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/4/08 07:54PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month