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 09-Feb-2005, 21:28
SpudNuts
 
Posts: n/a

Roman to decimal to roman


I've been working on this for a while and need alittle help. The code is quite long so bear with me.

I'm getting an error twice:

romtest.cpp
error C2514: 'romanType' : class has no constructors
see declaration of 'romanType'
fatal error C1903: unable to recover from previous error(s); stopping compilation

roman.cpp
error C2514: 'romanType' : class has no constructors
see declaration of 'romanType'
fatal error C1903: unable to recover from previous error(s); stopping compilation

roman.h

CPP / C++ / C Code:
class romanType
{
Public:
romanType();
romanType(rom & string);
void setdecimal(rom & string);
void decimaltoroman();
void romantodecimal();
void printdecimal();
void printroman();
Private:
int roman;
string decimal;
int st[25];
};

roman.cpp

CPP / C++ / C Code:
#include <iostream>
#include <string>
#include "roman.h"

using namespace std;

romanType::romanType()
   {
      roman="MMMCMXCIX";
      decimal=3999;
   }
romanType::romanType(const char number[])
   {
      roman = number;
      decimal=romantodecimal();
   }
romanType::romanType(int number)    
  {
   decimal=number;
   roman = decimaltoroman();  
  }
int romanType::romantodecimal()
  {
    int value = 0;
    string rom = roman;
    for(int i=16; i>roman.size();i-- ) rom+='0';
    for(int i=0; i < 15 ; i++)
    {
     char t=rom[i]; 
     t = toupper(t);
     switch(t)
      {
       case 'M':{value+=1000; break;};  
       case 'D':{value+=500;  break;}; 
       case 'C':{
                  if((rom[i+1]=='M')||(rom[i+1]=='D')) 
                      value-=100;
                  else value+=100;
                  break;
                };
       case 'L':{value+=50; break;};
       case 'X':{ 
                  if((rom[i+1]=='C')||(rom[i+1]=='L'))
                      value-=10;
                  else value+=10;       
                  break;
                };
       case 'V':{value+=5; break;};
       case 'I':{ 
                  if((rom[i+1]=='X')||(rom[i+1]=='V'))
                      value-=1;
                  else value+=1;       
                  break;
                };
      }
    }
   printf("%s",roman.c_str());  
   printf("%s",rom.c_str());
   decimal=value;
   roman = decimaltoroman();
   value=decimal;
   return value;
  }
string romanType::decimaltoroman()   
  {
   if((decimal < 4000)&&(decimal>0)); 
   else decimal = 3999;
   string rom = "";
   int value = decimal; 
   while(value!=0)
   if (value >= 1000)
       {
        value-=1000;
        rom += 'M';
       }
   else if(value >= 900)
           {
            value-=900;
            rom += "CM";
           }
         else if(value >= 500)
                 {
                  value-=500;
                  rom += 'D';
                 }  
               else if(value >= 400)
                       {
                        value-=400;
                        rom += "CD";
                       } 
                     else if(value >= 100)
                            {
                             value-=100;
                             rom +='C';
                            }
                          else if(value >= 90)
                                 {
                                  value-=90;
                                  rom += "XC";
                                 } 
                                else if(value >= 50)
                                        {
                                          value-=50;
                                          rom += "L";
                                        }
                                      else if(value >= 40)
                                             {
                                              value-=40;
                                              rom += "XL";
                                             }                                   
                                          else if(value >= 10)
                                                {
                                                  value-=10;
                                                  roma += 'X';
                                                }
                                                else if(value >= 9)
                                                     {
                                                      value-= 9;
                                                      rom += "IX";
                                                     }
                                                     else if(value >= 5)
                                                          {
                                                           value-=5;
                                                           rom += 'V';
                                                          }
                                                          else if(value >= 4)
                                                                {
                                                                 value-=4;
                                                                 rom += "IV";
                                                                } 
                                                               else if(value >= 1)
                                                                     {
                                                                       value-=1;
                                                                       rom += 'I';
                                                                     }; 
   return rom; 
  }
roman romanType::operator=(int number)
     {
       decimal = number;              
       roman = decimaltoroman();     
     }
roman romanType::operator=(const char number[])
     {
       roman = number;
       decimal = romantodecimal();
     }
roman romanType::operator=(roman number)
     {
       decimal= number.get_decimal();
       roman = decimaltoroman();
     }
bool romanType::operator==(int number)
     {
       if (decimal==number)
       return true;
       else return false;
     }
bool romanType::operator==(const char number[])
     {
       roman rom(number);
       if (decimal == rom.get_decimal()) return true;
       else return false;
     }
bool romanType::operator==(roman number)
     {
       if (decimal == number.get_decimal()) return true;
       else return false;
     }
bool romanType::operator!=(int number)
     {
       if (decimal!=number)
       return true;
       else return false;
     }
bool romanType::operator!=(const char number[])
     {
       roman rom(number);
       if (decimal != rom.get_decimal()) return true;
       else return false;
     }
bool romanType::operator!=(roman number)
     {
       if (decimal != number.get_decimal()) return true;
       else return false;
     }
roman romanType::operator+(int number)
     {
       decimal+= number;
       roman = decimaltoroman();
     }
roman romanType::operator+(const char number[])
     {
       roman rom(number);    
       decimal+= rom.get_decimal();
       roman = decimaltoroman();
     } 
roman romanType::operator+(roman number)
     {
       decimal+=number.get_decimal();
       roman = decimaltoroman();
     }
roman romanType::operator-(int number)
     {
       decimal-= number;
       roman = decimaltoroman();
     }
roman romanType::operator-(const char number[])
     {
       roman rom(number);    
       decimal-= rom.get_decimal();
       roman = decimaltoroman();
     } 
roman romanType::operator-(roman number)
     {
       decimal-=number.get_decimal();
       roman = decimaltoroman();
     }
roman romanType::operator*(int number)
     {
       decimal= decimal*number;
       roman = decimaltoroman();
     }
roman romanType::operator*(const char number[])
     {
       roman rom(number);    
       decimal= decimal*rom.get_decimal();;
       roman = decimaltoroman();
     } 
roman romanType::operator*(roman number)
     {
       decimal= decimal*number.get_decimal();;
       roman = decimaltoroman();
     }
roman romanType::operator/(int number)
     {
       decimal= decimal/number;
       roman = decimaltoroman();
     }
roman romanType::operator/(const char number[])
     {
       roman rom(number);    
       decimal= decimal/rom.get_decimal();;
       roman = decimaltoroman();
     }
roman romanType::operator/(roman number)
     {
       decimal= decimal/number.get_decimal();;
       roman = decimaltoroman();
     }
int romanType::get_decimal()
   {
     return decimal;
   }
string romanType::get_roman() 
    {
     return roman; 
    }
romanType::~roman()
   {
    printf("\nAnd the answer is!!");
   }

romtest.cpp

CPP / C++ / C Code:
#include <iostream>
#include "roman.h"
using namespace std;


int main(void)
{   
	int n, i=0;

	RomanType r1;
	cout << "Enter your number: ";
	cin >> n;
	r1.setRoman(n);
	r1.convertToDecimal();
	cout << "Roman number is ";
	r1.printRoman();
	cout << "Decimal number is ";
	r1.printDecimal();
  
	return 0;
}

Thanks
Last edited by LuciWiz : 10-Feb-2005 at 07:48. Reason: Please insert your c code between [c] & [/c] tags
  #2  
Old 10-Feb-2005, 10:01
davekw7x davekw7x is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Left Coast, USA
Posts: 5,200
davekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to beholddavekw7x is a splendid one to behold
Quote:
Originally Posted by SpudNuts
I've been working on this for a while and need alittle help. The code is quite long so bear with me.

I'm getting an error twice:

romtest.cpp
error C2514: 'romanType' : class has no constructors
see declaration of 'romanType'
fatal error C1903: unable to recover from previous error(s); stopping compilation

roman.cpp
error C2514: 'romanType' : class has no constructors
see declaration of 'romanType'
fatal error C1903: unable to recover from previous error(s); stopping compilation

Thanks

Are these the only messages your compiler gave? What compiler?

I ran your program through three compilers (Borland, Microsoft, GNU), and each gave hundreds of errors.

There are many things to be fixed before you can get a successful compilation (let alone valid functionality).

For starters, way back in roman.h: The class storage specifiers are "private" and "public", not "Private" and "Public".

Here's a suggestion: instead of typing in several hundred lines of code and compiling it all at once, how about just getting in a few things to make sure you are on the right track? Get that code to execute properly, then add functionality a little at a time.

For example declare your class; define a couple of simple constructors and write a test program.

Here's what I have in mind.

CPP / C++ / C Code:
// This is file "roman.h"

#include <string>
using std::string;

class romanType
{
  public:
    romanType();
    romanType(string);
    romanType(int);
    void printRoman();
    void printDecimal();

  private:
    string roman;
    int decimal;
    int st[25];
};


CPP / C++ / C Code:
// This is file roman.cpp
// Define the class functions and operators
//
#include <iostream>

#include "roman.h"


// Constructors
romanType::romanType()
   {
      roman="MMMCMXCIX";
      decimal=3999;
   }
romanType::romanType(int number)    
  {
   decimal=number;
   //roman = decimaltoRoman();  
   roman = "<Need to implement decimaltoRoman()>";
  }

void romanType::printDecimal()
{
  std::cout << "Decimal value is " << decimal << std::endl;
}

void romanType::printRoman()
{
  std::cout << "Roman number is " << roman << std::endl;
}

CPP / C++ / C Code:
// This is file romtest.cpp
//
#include <iostream>
#include "roman.h"

using std::cout;
using std::endl;

int main(void)
{   

  romanType r1;
  romanType r2(1234);

  cout << endl << "Calling r1.printRoman()" << endl << "  ";
  r1.printRoman();

  cout << endl << "Calling r2.printDecimal()" << endl << "  ";
  r2.printDecimal();

  
  return 0;
}


1. See if these compile with your system. (I think they should; to the best of my ability and knowledge these are valid Standard C++ programs.) If something doesn't work and you don't understand why, ask specific questions.

2. Make sure you understand what they do. (There are other ways to do most of this stuff; if you want to do them some other way: go for it. Your fallback position is that you have something that you know works for you.) If you can't understand what is happening or why, ask specific questions.

3. Implement other constructors, functions and operators, adding them one at a time to your working program. Test each new thing that you put in. At each step, make sure it's working before putting in anything new. If you get errors or behavior that you don't understand, ask specific questions. (Show the code that you used; tell us what you expected; tell us what you got.)

Regards,

Dave
  #3  
Old 16-Feb-2005, 20:44
SpudNuts
 
Posts: n/a
VS .net, I did as you said and yes the little test program compiled without a problem. I guess i'm just having a problem bringing it all together one at a time.

Spuds
 
 

Recent GIDBlogOnce again, no time for hobbies 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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with Decimal to Hex Conversions jediboy C Programming Language 1 13-Dec-2004 01:11
Hex Result giving strange answers. Rosdahale C Programming Language 6 07-Dec-2004 21:28

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

All times are GMT -6. The time now is 23:53.


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