Linking error in the compiler given by topcoder. Plz help me out guys.

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

Join Date: Aug 2008
Posts: 38
Reputation: arun_lisieux is an unknown quantity at this point 
Solved Threads: 0
arun_lisieux's Avatar
arun_lisieux arun_lisieux is offline Offline
Light Poster

Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #1
Aug 6th, 2008
Guys,
Im not very experienced in C++. I was practicing problems from topcoder to improve my knowledge in C++. I've posted the code i used for solving a problem statement given by topcoder website. The compiler tells that there is a linking error with this code and hence its not compiling properly. Plz help me out.
  1. #include<iostream.h>
  2. #include<string.h>
  3. using namespace std;
  4.  
  5. class HowEasy
  6. {
  7. public:
  8. string statement;
  9. int flag,letterCount,wordCount;
  10. int pointVal (string);
  11. };
  12.  
  13. int pointVal (string s)
  14. {
  15. int len = s.length();
  16. int avgCount,flag=0,i,wordCount=0,letterCountMain=0,letterCountTemp=0;
  17. for(i=0; i<len ;i++)
  18. {
  19. //if((int(s[i]>=65) && int(s[i]<=90)) || int((s[i]>=97) && int(s[i]<=122)))
  20. if(((s[i]>=65)&&(s[i]<=90))||((s[i]>=97)&&(s[i]<=122)))
  21. {
  22. if(flag==0)
  23. {
  24. letterCountTemp+=1;
  25. }
  26. }
  27. else
  28. {
  29. flag=1;
  30. letterCountTemp=0;
  31. }
  32. if(s[i]==' ')
  33. {
  34. if(flag==0)
  35. {
  36. letterCountMain+=letterCountTemp;
  37. wordCount+=1;
  38. }
  39. flag=0;
  40. }
  41. if(s[i]=='.')
  42. {
  43. if(flag==0 && s[i+1]!='.')
  44. {
  45. letterCountMain+=letterCountTemp;
  46. wordCount+=1;
  47. }
  48. flag=0;
  49. }
  50. }
  51. cout << "The no of letters in the problem statement is displayed below: " << letterCountMain << endl;
  52. cout << "The no of words in the problem statement is displayed below: " << wordCount << endl;
  53. avgCount = letterCountMain/wordCount;
  54. cout << "The avg letter count in the problem statement is displayed below: " << avgCount << endl << endl;
  55. if(avgCount<=3)
  56. {
  57. return 250;
  58. }
  59. else if((avgCount==4)||(avgCount==5))
  60. {
  61. return 500;
  62. }
  63. else if(avgCount>6)
  64. {
  65. return 1000;
  66. }
  67. }
  68.  
  69. int main()
  70. {
  71. HowEasy class1;
  72. char t;
  73. cout << "Press any key to type the problem statement: ";
  74. cin >> t;
  75. cin.get();
  76. cout << "Type the problem statement: ";
  77. getline(cin, class1.statement);
  78. cout << "The problem statement's point value is :" << class1.pointVal(class1.statement);
  79. }
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #2
Aug 6th, 2008
What compiler are you using?
I can't see any error messages in your post.

Why int pointVal (string s) and where is int HowEasy::pointVal(string s) MEMBER FUNCTION definition? Probably, it's a reason of your troubles...
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: arun_lisieux is an unknown quantity at this point 
Solved Threads: 0
arun_lisieux's Avatar
arun_lisieux arun_lisieux is offline Offline
Light Poster

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #3
Aug 6th, 2008
Originally Posted by ArkM View Post
What compiler are you using?
I can't see any error messages in your post.

Why int pointVal (string s) and where is int HowEasy::pointVal(string s) MEMBER FUNCTION definition? Probably, it's a reason of your troubles...
I didn't get any errors in Borland C++ compiler. I was just getting wrong outputs. But when i used this code on the compiler given in topcoder application, it gives me linking error. And i've tried int HowEasy::pointVal(string s) also. It shows a different set of errors for that.
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 2,001
Reputation: ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of ArkM has much to be proud of 
Solved Threads: 343
ArkM's Avatar
ArkM ArkM is offline Offline
Postaholic

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #4
Aug 6th, 2008
Wrong outputs... of a compiler, of a linker, of a program?..
Are you a pilot of a shot down F-117 under hostile cross-examination?..
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: arun_lisieux is an unknown quantity at this point 
Solved Threads: 0
arun_lisieux's Avatar
arun_lisieux arun_lisieux is offline Offline
Light Poster

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #5
Aug 6th, 2008
My code had some logical errors in it. I got some output, but its not the expected output for the problem. This was when i used Borland C++. When i pasted the same code in the topcoder's compiler, im getting linking error. Any ideas on this?

PS: Im just somewhere between beginner and intermediate. If i post some thing wrong, plz correct me and help me learn more about C++.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,837
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 503
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #6
Aug 6th, 2008
ArkM is correct. It needs to be int HowEasy::pointVal(string s) . If you get other errors with that, the solution is to fix those errors, not go back to int pointVal(string s) . Try taking the ".h" off of your #include statements . Add return 0; to the end of the main function. What compiler/linker errors do you get? I don't get any after making those changes.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: arun_lisieux is an unknown quantity at this point 
Solved Threads: 0
arun_lisieux's Avatar
arun_lisieux arun_lisieux is offline Offline
Light Poster

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #7
Aug 6th, 2008
Thanks for the suggestion man. Will try it now.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #8
Aug 6th, 2008
Well, I have made some assumptions since you did not say what it is supposed to do.
I modified your code a little

  1. #include<iostream>
  2. #include<string>
  3. #define isalpha(a) (((a)>='A' && (a) <= 'Z') ||((a)>='a' && (a) <= 'z'))
  4.  
  5. using namespace std;
  6.  
  7. class HowEasy
  8. {
  9. public:
  10. int pointVal (string);
  11. string statement;
  12. private:
  13. int letterCount,wordCount;
  14.  
  15. };
  16.  
  17. int HowEasy::pointVal (string s)
  18. {
  19. int len = s.length();
  20. int avgCount, i ;
  21. wordCount=0,letterCount=0 ;
  22. for(i=0; i<len ;i++)
  23. {
  24. if(isalpha(s[i]))
  25. letterCount++;
  26. else if(s[i]==' ')
  27. wordCount++;
  28. else
  29. {
  30. while ( !isalpha(s[i+1])) i++ ;
  31. wordCount++;
  32. }
  33. }
  34. cout << "The no of letters in the string: " << letterCount << endl;
  35. cout << "The no of words in the string: " << wordCount << endl;
  36. avgCount = letterCount/wordCount;
  37. cout << "The avg letter count in the string: " << avgCount << endl ;
  38. if(avgCount<=3)
  39. return 250;
  40. else if(avgCount<=5)
  41. return 500;
  42. else
  43. return 1000;
  44. }
  45.  
  46. int main()
  47. {
  48. HowEasy class1;
  49. cout << "Type the problem statement: ";
  50. getline(cin, class1.statement);
  51. cout << "The string's point value is :" << class1.pointVal(class1.statement);
  52. cin.get() ;
  53. }

Originally Posted by Output
Type the problem statement: Hi! This Statement should be fine. I hope so...
The no of letters in the problem statement is displayed below: 34
The no of words in the problem statement is displayed below: 9
The avg letter count in the problem statement is displayed below: 3

The problem statement's point value is :250
EDIT: I don't like using string data as a public member. I didn't care about such things here since I was interested in fixing the errors
Last edited by Prabakar; Aug 6th, 2008 at 2:06 pm. Reason: Format the code
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 334
Reputation: Prabakar is on a distinguished road 
Solved Threads: 29
Prabakar's Avatar
Prabakar Prabakar is offline Offline
Posting Whiz

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #9
Aug 6th, 2008
Oops, Some syntax errors. I changed it now.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 38
Reputation: arun_lisieux is an unknown quantity at this point 
Solved Threads: 0
arun_lisieux's Avatar
arun_lisieux arun_lisieux is offline Offline
Light Poster

Re: Linking error in the compiler given by topcoder. Plz help me out guys.

 
0
  #10
Aug 6th, 2008
Thanks a lot prabhakar. I forgot to mention what the code is for. Forgive me as this is my first post. This program is for calculating the number of letters from words with only alphabets and the dividing it by the number of words. According to this value, the points are decided as in the loop(250,500,1000). Your code works. But it considers words with numbers and two full stops "..", but they must be omitted from the count of words. Thats why i used the flag variable. May i know wat went wrong in that approach? And can you explain the #define isaplha () a bit. I know #define is for defining constants or some functions. But i have some trouble comprehending this. How can the alphabets alone suffice without using their ascii values?

PS: I've posted the error message i get from the compiler below.

  1. your code did not compile:
  2.  
  3. errors linking:
  4.  
  5. HowEasy-stub.o.(.text+0x534) : In function 'main':
  6. : multiple definition of 'main'
  7. HowEasy.o.(.text+0x3fc): first defined here
  8. /usr/bin/ld: warning: size of symbol 'main' changed from 269 in HowEasy.o to 620 in HowEasy-stub.o
  9. collect2: ld returned 1 exit status
Last edited by arun_lisieux; Aug 6th, 2008 at 2:50 pm.
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the C++ Forum
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC