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: Jan 2008
Posts: 3,814
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: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster

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

 
0
  #11
Aug 6th, 2008
Originally Posted by arun_lisieux View Post
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). 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?

While this works fine,

  1. #define isalpha(a) (((a)>='A' && (a) <= 'Z') ||((a)>='a' && (a) <= 'z'))

I believe that the function below is preferable, particularly for someone new to C++. The above is probably more efficient due to the fact that you'll have fewer function calls, but is harder for someone new to C++ to read.

  1. bool isalpha (char a)
  2. {
  3. return (((a)>='A' && (a) <= 'Z') ||((a)>='a' && (a) <= 'z'));
  4. }

It takes a character a and checks whether the ASCII value of a is between the ASCII values of 'A' (65) and 'Z' (90) or between the ASCII values of 'a' (97) and 'z' (122). If it is, it's a letter. If not, it isn't. By "between", I am including the boundary conditions ('A', 'Z', 'a', 'z') as being "between". You don't have to write your own function. cctype provides the equivalent function:

http://www.cplusplus.com/reference/c...e/isalpha.html
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
  #12
Aug 6th, 2008
Thanks VernonDozier. That explains things. And do you have any clue about why im getting the error which i've edited in my previous post?
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
  #13
Aug 6th, 2008
Perhaps you may have to toggle to plain text before coping the code. Here is the code again.

EDIT: and I saw the explanation. So flag is indeed need incase the word contains text & numbers. Well, add that in your code should be simple
Last edited by Prabakar; Aug 6th, 2008 at 3:49 pm.
Attached Files
File Type: cpp Untitled1.cpp (1.2 KB, 1 views)
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
  #14
Aug 6th, 2008
Original algorithm diagnosis: the patient's case is hopeless.
  1. #include <ctype.h>
  2. // Now we have isalpha()...
  3. int HowEasy::pointVal(const string& s)
  4. {
  5. int slen = s.length();
  6. int words = 0;
  7. int letters = 0;
  8.  
  9. for (int i = 0; i < slen; ++i)
  10. {
  11. while (i < slen && !isalpha(s[i]))
  12. ++i;
  13. if (i >= slen)
  14. break;
  15. ++words;
  16. ++letters;
  17. while (++i < slen && isalpha(s[i]))
  18. ++letters;
  19. }
  20.  
  21. if (words == 0)
  22. return 0;
  23.  
  24. int points;
  25. int average = letters / words;
  26.  
  27. if (average <= 3)
  28. points = 250;
  29. else if (average < 6)
  30. points = 500;
  31. else
  32. points = 1000;
  33.  
  34. return points;
  35. }
Furthemore: try to avoid "in deep level printing" syndrome. The only goal of pointVal() member function is: calculate easy reading points. That's all. Let callee comments the result.

Pay attention on the right function parameter type. No need to copy argument string, pass argument by reference.

Clean up main function dialog. Why bla-bla-bla with "Press any key...", cin > t etc?
It's enough:
  1. cout << "Type the problem statement:" << endl;;
  2. getline(cin, class1.statement);
  3. cout << "The problem statement's point value is: "
  4. << class1.pointVal(class1.statement)
  5. << endl;

Apropos, you have absolutely useless member in HowEasy... Right, it's string HowEasy::statement (public!). Do you think that there is extremely shortage of the memory outside HowEasy bounds?..

Let's remember now your post header: Linking error in the compiler...
A compiler does not perform linkage. It compiles...

Good luck!
Last edited by ArkM; Aug 6th, 2008 at 4:09 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



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC