GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 04-May-2008, 02:28
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough
Unhappy

C++ Classes, implementation, ADT


hi, all
i am new to the thread posting, i am designing a project to convert roman to decimal but i don't know hoe to code the class for that cuz i don't get the class the implementation when we have to use it also the constarctor destractor and ADT it is all blurry if some will give me an example of a class with comments that would be great also i wish if some look at the function that designed to stor the roman string into a array of char then do the conversion to decimal.
CPP / C++ / C Code:
void get_Roman(string input,char[] roman,int& len)
{
int len;
cin<<input;
len=input.length();
char[len] =input;
// i am not sure how to assign a string to an array of type char

}
void convert_roman(int& len,char[] roman,int& sum )
{
int value;int i;int value[len];
for (i=len-1;i>=1;i--)
{
switch( roman[i])
case 'M'
value[i]=1000;
case 'D'
value[i]=500;
case 'C'
value[i]=100;
case 'L'
value[i]=50;
case 'X'
value[i]=10;
case 'V'
value[i]=5;
case 'I'
value[i]=1;
if (value[len-1]>=value[len])
	sum =value[i]+value[i-1]; 
else
	sum=value[i]-value[i-1];

}
Last edited by LuciWiz : 04-May-2008 at 13:31. Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
  #2  
Old 06-May-2008, 05:49
Peter_APIIT Peter_APIIT is offline
Regular Member
 
Join Date: May 2007
Location: Malaysia
Posts: 545
Peter_APIIT can only hope to improve

Re: C++ Classes, implementation, ADT


Can you provide a input and output example ?

I not understand what is roman.

You just need a class with string that contain roman and has constructor and destructor.

I hope this help.
  #3  
Old 06-May-2008, 05:53
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: C++ Classes, implementation, ADT


roman characters are :XI XV that is what roman's use to use for numbers example I=1 ,II=2,III=3,Iv=4,v+5...
  #4  
Old 06-May-2008, 05:57
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: C++ Classes, implementation, ADT


also my apologies to the ones who checked my code it wrong i admit it i have the that can convert but i am building the class RomanNumbers i will post them soon i have to submitt my project to day
  #5  
Old 06-May-2008, 06:00
zatora zatora is offline
Member
 
Join Date: May 2008
Posts: 110
zatora will become famous soon enough

Re: C++ Classes, implementation, ADT


CPP / C++ / C Code:
#include<iostream>
#include<string>
using namespace std;
 
int main()
{
    string str;
    cin>>str;
    int j = str.length();
    int val,val1,sum;
    val1=0;val=0;sum=0;
    for(int i=str.length()-1;i>=0;i--)
    {val1=val;
        switch(str[i])
        {
        case 'i':
            val=1;
            break;
        case 'v':
            val=5;
            break;
        case 'x':
            val=10;
            break;
        case 'l':
            val=50;
            break;
        case'c':
            val=100;
            break;
        case'd':
            val=500;
            break;
        case'm':
            val=1000;
            break;
        default:
            val=0;
        }
        if (val1<=val)
            sum=sum+val;
        else
        sum=sum-val;
 
        cout<<"val: "<<val<<" val 1: "<<val1<<" sum : "<<sum<<endl;
}
}
Last edited by admin II : 07-May-2008 at 05:03. Reason: Please surround your C++ code with [cpp] your code [/cpp]
 
 

Recent GIDBlogProblems with the Navy (Chiefs) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 15:00.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.