C++ Questions

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2006
Posts: 9
Reputation: MrLew is an unknown quantity at this point 
Solved Threads: 0
MrLew's Avatar
MrLew MrLew is offline Offline
Newbie Poster

C++ Questions

 
0
  #1
May 22nd, 2006
I am trying to write a program to convert a roman numeral to decimal. If I define a variable with: char roman_num[15]; can I then select individual characters in that roman numeral with: roman=roman_num[i]; where "i" is a number value of the character I want to retrieve from 0-14?

Also, I am getting an error when I try to compile my implementation file (my header file compiles fine). I can't locate my mistake...

Here are my compiler errors:
romanTypeImp.cpp: In function `int main()':
romanTypeImp.cpp:15: error: `romanToDecimal' undeclared (first use this function)
romanTypeImp.cpp:15: error: (Each undeclared identifier is reported only once for each function it appears in.)


I am using cygwin on XP and gcc (compiling with g++):
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)

Here is my header file:
  1. class romanType
  2. {
  3. public:
  4. romanType();
  5. // Default constructor
  6. void romanToDecimal(char roman);
  7. // Convert from roman numeral to decimal
  8. void printRoman();
  9. // Print roman numeral
  10. void printDecimal();
  11. // Print decimal value
  12. private:
  13. char roman; // Store a single roman numeral
  14. int decimal; // Store decimal value
  15. char roman_num[15]; // Store roman numeral array of 15 characters
  16. int numberM; // Store value of roman numeral M
  17. int numberD; // Store value of roman numeral D
  18. int numberC; // Store value of roman numeral C
  19. int numberL; // Store value of roman numeral L
  20. int numberX; // Store value of roman numeral X
  21. int numberV; // Store value of roman numeral V
  22. int numberI; // Store value of roman numeral I
  23. };

Here is my implementation file:
  1. #include <iostream>
  2. #include "romanType.h"
  3. using namespace std;
  4. char roman;
  5. void romanType::romanToDecimal(char roman)
  6. {
  7. cout<<"Testing"<<roman;
  8. }
  9. int main()
  10. {
  11. cout<<endl<<"Enter a Roman Numeral: ";
  12. romanToDecimal('M');
  13. }
Thanks,
MrLew
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 253
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C++ Questions

 
0
  #2
May 22nd, 2006
romanToDecimal is a member function lacking an object.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 9
Reputation: MrLew is an unknown quantity at this point 
Solved Threads: 0
MrLew's Avatar
MrLew MrLew is offline Offline
Newbie Poster

Re: C++ Questions

 
0
  #3
May 23rd, 2006
I'm not grasping what you mean by an object... I tried looking it up, but I don't think I found the right solution. I made the two changes below, but still get the following error when I compile:

undefined reference to `romanType::romanType()'

  1. #include <iostream>
  2. #include "romanType.h"
  3.  
  4. using namespace std;
  5. char roman;
  6. romanType myroman; //Change #1
  7.  
  8. void romanType::romanToDecimal(char roman)
  9. {
  10. cout<<"Testing"<<roman;
  11. }
  12.  
  13. int main()
  14. {
  15. cout<<endl<<"Enter a Roman Numeral: ";
  16. myRoman. romanToDecimal('M'); //Change #2
  17. }
Thanks,
MrLew
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 253
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C++ Questions

 
0
  #4
May 23rd, 2006
You tell the compiler that you'll write a function:
class romanType
{
public:
 romanType();
Then you don't provide one. The compiler feels left out.

Note also that the language is case-sensitive, so myroman is not the same as myRoman.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 9
Reputation: MrLew is an unknown quantity at this point 
Solved Threads: 0
MrLew's Avatar
MrLew MrLew is offline Offline
Newbie Poster

Re: C++ Questions

 
0
  #5
May 23rd, 2006
Thanks for the pointers... I fixed the additional problems based off of your last tip. I've got a new error now...

romanTypeImp.cpp:22: error: return type specification for constructor invalid

Header file:
  1. class romanType
  2. {
  3. public:
  4. romanType();
  5. // Default constructor
  6. void romanToDecimal(char roman);
  7. // Convert from roman numeral to decimal
  8. void printRoman();
  9. // Print roman numeral
  10. void printDecimal();
  11. // Print decimal value
  12. private:
  13. char roman; // Store a single roman numeral
  14. int decimal; // Store decimal value
  15. char roman_num[15]; // Store roman numeral array of 15 characters
  16. int numberM; // Store value of roman numeral M
  17. int numberD; // Store value of roman numeral D
  18. int numberC; // Store value of roman numeral C
  19. int numberL; // Store value of roman numeral L
  20. int numberX; // Store value of roman numeral X
  21. int numberV; // Store value of roman numeral V
  22. int numberI; // Store value of roman numeral I
  23. };

Implementation file:
  1. #include <iostream>
  2. #include "romanType.h"
  3. using namespace std;
  4. void romanType::romanToDecimal(char roman)
  5. {
  6. cout<<"Testing"<<roman;
  7. }
  8. void romanType::printRoman()
  9. {
  10. cout<<"Testing 2";
  11. }
  12. void romanType::printDecimal()
  13. {
  14. cout<<"Testing 3";
  15. }
  16. void romanType::romanType()
  17. {
  18. printDecimal();
  19. }
  20. int main()
  21. {
  22. romanType myRoman;
  23. cout<<endl<<"Enter a Roman Numeral: ";
  24. myRoman.romanToDecimal('M');
  25. }
Thanks,
MrLew
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 253
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: C++ Questions

 
0
  #6
May 23rd, 2006
void romanType::romanType()
Constructors don't have return values.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 2455 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC