Any Sample Program???

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

Join Date: Oct 2005
Posts: 7
Reputation: omick16 is an unknown quantity at this point 
Solved Threads: 0
omick16's Avatar
omick16 omick16 is offline Offline
Newbie Poster

Re: Any Sample Program???

 
1
  #11
Oct 15th, 2005
Hi... there... I'm omick from the Philippines... Actually I'm a newbie here... I really dont know what you people are talking about... But anyways i'll be giving my idea of how to make a palindrome... I mean not really the whole thing... and i'm not that sure if this stuff thats on my mind will work out... ok here it is:

define your main function and include all those prompt thingy...:
like this one... i'm not so sure with this...

  1. bool it_is_palindrome(string palindrome2)
  2. int main()
  3. {
  4. string palindrome;
  5. //prompt the user for a line of input
  6. e.g.:
  7. cout << "Enter now your word: ";
  8. getline(cin, palindrome);
  9. //now to test whether it is a palindrome you make a validation function... e.g. bool;
  10. if (it_is_palindrome(palindrome))
  11. cout << "It is a palindrome!";
  12. else
  13. cout << "Not a palindrome";
  14. return 0;
  15. }
<< moderator edit: added code tags: [code][/code] >>

uhmmm.... i'm using a cafe... sorry i dont have much time left... maybe next time ok...

but wait...

arrays are very useful here...

this function should be included:
*function that will convert all your letters into small letters
e.g.
  1. for (int i=0; i<lengt_of_string; i++)
  2. letter[i]=(tolower(another_letter[i]);
*function that will remove any punctuation marks including spaces

Tell me if you like my sample solution... I can really solve the problem... But I dont have enough time... If you like it... I can provide you the whole program... ok... e-mail me: << moderator edit: email snipped >>
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 494
Reputation: Puckdropper is an unknown quantity at this point 
Solved Threads: 21
Puckdropper Puckdropper is offline Offline
Posting Pro in Training

Re: Any Sample Program???

 
1
  #12
Oct 15th, 2005
You could implement a stack, then pop each element off the top while at the same time pushing the element on to another stack. Then compare the results.

Naturally, there are much better ways to do what you want.
www.uncreativelabs.net

Old computers are getting to be a lost art. Here at Uncreative Labs, we still enjoy using the old computers. Sometimes we want to see how far a particular system can go, other times we use a stock system to remind ourselves of what we once had.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 16
Reputation: mysterio is an unknown quantity at this point 
Solved Threads: 0
mysterio mysterio is offline Offline
Newbie Poster

Re: Any Sample Program???

 
0
  #13
Oct 16th, 2005
Originally Posted by omick16
Hi... there... I'm omick from the Philippines... Actually I'm a newbie here... I really dont know what you people are talking about... But anyways i'll be giving my idea of how to make a palindrome... I mean not really the whole thing... and i'm not that sure if this stuff thats on my mind will work out... ok here it is:

define your main function and include all those prompt thingy...:
like this one... i'm not so sure with this...

  1. bool it_is_palindrome(string palindrome2)
  2. int main()
  3. {
  4. string palindrome;
  5. //prompt the user for a line of input
  6. e.g.:
  7. cout << "Enter now your word: ";
  8. getline(cin, palindrome);
  9. //now to test whether it is a palindrome you make a validation function... e.g. bool;
  10. if (it_is_palindrome(palindrome))
  11. cout << "It is a palindrome!";
  12. else
  13. cout << "Not a palindrome";
  14. return 0;
  15. }
<< moderator edit: added code tags: [code][/code] >>

uhmmm.... i'm using a cafe... sorry i dont have much time left... maybe next time ok...

but wait...

arrays are very useful here...

this function should be included:
*function that will convert all your letters into small letters
e.g.
  1. for (int i=0; i<lengt_of_string; i++)
  2. letter[i]=(tolower(another_letter[i]);
*function that will remove any punctuation marks including spaces

Tell me if you like my sample solution... I can really solve the problem... But I dont have enough time... If you like it... I can provide you the whole program... ok... e-mail me: << moderator edit: email snipped >>
The palindrome part i know to do...but the problem i having is the alphabet...from A to a
i didnt know where to put the function...

i done with #include 'Stack.h', #include 'Queue.h' and Main.cpp
i show main program n add me the function (tolowercase,touppercase)

my main.cpp as below..

  1. #include <iostream>
  2. #include <cstdlib> // For EXIT_FAILURE and EXIT_SUCCESS
  3. #include <fstream>
  4. #include <string>
  5. #include <algorithm>
  6. #include <iomanip>
  7. #include <cctype>
  8.  
  9. using namespace std;
  10.  
  11. #include "Queue.h"
  12. #include "Stack.h"
  13.  
  14.  
  15. /***************************MAIN******************************/
  16. int main()
  17. {
  18. Stack S; // initialize stack
  19. Queue Q; // initialize queue
  20. string s;
  21. int i=0; // initialze int 'i'
  22. char string[MAX]; // initialize char string
  23. bool RESULT=false; // initilize bool RESULT to false
  24.  
  25.  
  26. strcpy(string," ");
  27. cout << "Please enter a line of text: " << endl;
  28. cin.getline (string,100);
  29.  
  30. for( int j = 0; j < s.size(); ++j)
  31. {
  32. if(s[j] >= 'A' && s[j] <= 'Z')
  33. s += (s[j] | 32);
  34. else
  35. if(s[j] >= 'a' && s[j] <= 'z')
  36. s += (s[j] & (~32));
  37. else
  38. s += s[j];
  39. }
  40.  
  41. while(string[i]!=NULL)
  42. {
  43. S.push(string[i]); // push chars individually from string to
  44. Q.addq(string[i]); // stack and queue
  45. i++; // next char
  46. }
  47. while(i>0)
  48. {
  49. if(S.topNpop()==Q.frontNremoveq()) // compare each element from
  50. { // stack and queue
  51. RESULT=true; // if same for all chars return true
  52. }
  53. else
  54. {
  55. RESULT=false; // if not same for any char break and return false
  56. break;
  57. }
  58. i--;
  59. }
  60.  
  61.  
  62. if(RESULT==true)
  63. {
  64. cout<<string<<" \nThis is a palindrome\n"; // display if true
  65. }
  66. else
  67. {
  68. cout<<string<<" \nThis is not a palindrome\n"; // display if false
  69. }
  70.  
  71. cout<<s<<s<<endl;
  72.  
  73. return 0;
  74. }
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 7
Reputation: omick16 is an unknown quantity at this point 
Solved Threads: 0
omick16's Avatar
omick16 omick16 is offline Offline
Newbie Poster

Re: Any Sample Program???

 
0
  #14
Oct 29th, 2005
hi hey... sorry for the late reply... i'm so busy processing my clearance to get home... kindly check for any mispelled things ok??? I have only type this stuff for you... so i cannot assure you that is free from errors... i havent tested this program... ok>>> but i know this would surely work!

heres the function that will convert any capital letters into small ones

  1. //your main_function here
  2. //dont forget to use getline(cin, your_string_here);
  3. //if (is_your_string_palindrome(your_string_here));
  4. //cout << "Palindrome!";
  5. //else
  6. //cout << "not!";
  7. //and one thing... dont forget your header string ok? #include <string> :cheesy:
  8.  
  9.  
  10.  
  11. //heres the function that will remove all punctuation marks
  12.  
  13. string punctuation_erase (const string& your_string, const string& punctuation)
  14. {
  15. string no_punctuation; //this will create an empty string ok.
  16. int your_string_length = your_string.length();
  17. int punctuation_length = punctuation.length();
  18. for (int i =0; i < your_string_length; i++)
  19. {
  20. string report_char = your_string.substr(i, 1) //pick-up a one character
  21. int character_location = punctuation.find(report_char, 0);
  22. if (character_location < 0 || character_location >= punctuation_length)
  23. no_punctuation = no_punctuation + report_char // concatenates (+) strings that cannot be found in punctuation
  24. }
  25. return no_punctuation;
  26. }
  27.  
  28. //the function that will determine whether the input line is a palindrome
  29.  
  30. bool is_your_string_palindrome(cons string& your_string)
  31. {
  32. string punctuation ("?,:;'!\" "); // theres a space ok.. you can add other punctuations here.
  33. string string_here(your_string);
  34. string_here = make_lower_letters(string_here);
  35. string lowerstring_puncterase = punctuation_erase(string_here, punctuation);
  36. return (lowerstring_puncterase==reverse(lowerstring_puncterase);
  37. }
  38.  
  39. string make_lower_letters (const string& your_string)
  40. {
  41. string new_string(your_string);
  42. for (int i=0; i < your_string.length(); i++)
  43. new_string[i] = tolower(your_string[i]);
  44. return new_string;
  45. }
  46.  
  47. string reverse(const string& your_string)
  48. {
  49. int first = 0;
  50. int last = your_string.length();
  51. string string_here(your_string);
  52. while (first < last)
  53. {
  54. last--;
  55. swap(string_here[first], string_here[last];
  56. first++;
  57. }
  58. return string_here;
  59. }
  60.  
  61. void swap_letters(char& letter1, char& letter2)
  62. {
  63. char letter_here = letter1;
  64. letter1 = letter2;
  65. letter2 = letter_here;
  66. }
<< moderator edit: added code tags: [code][/code] >>
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 1
Reputation: canadianvpk is an unknown quantity at this point 
Solved Threads: 0
canadianvpk canadianvpk is offline Offline
Newbie Poster

dout

 
0
  #15
Jan 30th, 2008
sent a palindrome program in vb .......example also please .........quick
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,971
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: dout

 
0
  #16
Jan 30th, 2008
Originally Posted by canadianvpk View Post
sent a palindrome program in vb
So you bump a 2.5 year old thread and then expect to get some free homework?
You're not even in the right forum, this is C++ not VB.
Originally Posted by canadianvpk View Post
quick
[...]

Here's what you could try:
- Begin programming it yourself
- If you get stuck go to the right forum (VB) and look for the answer
- If the question was not answered in other thread, start a new thread and ask your question
- Don't use words like "Quick"

And to get you started, you might want to look here

Niek
Last edited by niek_e; Jan 30th, 2008 at 9:39 am.
Reply With Quote Quick reply to this message  
Join Date: Jul 2004
Posts: 12
Reputation: gkbush is an unknown quantity at this point 
Solved Threads: 0
gkbush gkbush is offline Offline
Newbie Poster

Re: Any Sample Program???

 
0
  #17
Jan 30th, 2008
You don't seem to get the hint. aniweb is to assist newbies by mentoring them.
This is not a place to get others to do your homework.
You learn programming by doing, not copying others.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC