Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 17
  1. #1
    New to the CF scene
    Join Date
    Feb 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    C++ programm (palindrome using string???)

    hey guys im a newbie here ...
    could you help me???
    how can u make a palindrome programm
    where u can input string and the output is palindrome,and not a palindrome??

  • #2
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Definitely sounds like a CS homework assignment. I did the same thing for APCS back in the day.

    We're not here to do your homework assignments, if this is the case.

  • #3
    New Coder
    Join Date
    Jan 2005
    Location
    Iowa City
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    well, there are many ways to do it.. first thing that pops into my head is go through the string 1 by 1 and if its a character, make it lowercase, then put it into an array, else skip it. (This will make your program ignore cases, so a=A and ignore punctuation and whitespace).

    Now that you have an array of all the chars, simply have a for loop go through half the array, and if array[count] doesn't equal
    array[arrayLength - count] then its not a palindrome. Here is pseudo-code for the last part:

    Code:
    palindrome = true
    for i=1 to arrayLength/2
    {
       if array[i] != array[arrayLength-i]
       {
          palindrome = false
          break
       }
    }
    if(palindrom)
      print "is a palindrome"
    else print "is not a palindrome"
    PS - this is what part of the alphabet would look like if Q and R were eliminated.

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by redoc
    well, there are many ways to do it.. first thing that pops into my head is go through the string 1 by 1 and if its a character, make it lowercase, then put it into an array, else skip it. (This will make your program ignore cases, so a=A and ignore punctuation and whitespace).

    Now that you have an array of all the chars, simply have a for loop go through half the array, and if array[count] doesn't equal
    array[arrayLength - count] then its not a palindrome. Here is pseudo-code for the last part:

    Which part of "were not here to do homework assignments" was unclear to you?

    I certainly hope you get a good grade on their homework assignment.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    New Coder
    Join Date
    Dec 2004
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jkd
    Definitely sounds like a CS homework assignment. I did the same thing for APCS back in the day.

    We're not here to do your homework assignments, if this is the case.
    Agreed!

    The Palindrome program is almost as widely used as "Hello World!" among CS students. If you are asking for help with this very basic program you might want to rethink your major.

    I still have my palindrome program and it can be done in under 20 lines of code.

    Good luck and take your time, it will come to you.

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by abbeyroadd
    Agreed!

    The Palindrome program is almost as widely used as "Hello World!" among CS students. If you are asking for help with this very basic program you might want to rethink your major.

    I still have my palindrome program and it can be done in under 20 lines of code.

    Good luck and take your time, it will come to you.
    Yes it is a very common programming assignment to teach both the methods of solving problems and coding in a particular language. I got stuck doing it in assembly when I was in college.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Senior Coder
    Join Date
    Aug 2002
    Location
    Kansas City, Kansas
    Posts
    1,518
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I've also just done it in a Java class. As Spookster and JKD have already said, we don't help people with their homework around here. In the future, try to lead them in the right direction so that they can figure it out themselves.

  • #8
    New Coder
    Join Date
    Dec 2004
    Posts
    41
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Antoniohawk
    In the future, try to lead them in the right direction so that they can figure it out themselves.
    I will give him the variables that I started with, even though there a ton of ways to do this here is what I used.

    Code:
    #define size 100
    
    char strsrc[size];
    char strhld[size];
    int answer = 0;
    You could use dynamic memory with this program but I felt that was a waste of time, but if you get it done try to use dynamic memory...it's good practice.

  • #9
    New Coder
    Join Date
    Jan 2005
    Location
    Iowa City
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hey, im here to help whenever I can. I didn't post any code itself (unless psuedo code counts, and i dont think so). I posted an algorithm that could be implemented in any language you want, and a kickstart on how to do it. Perhaps this person is learning on his own using a coursebook from a friend, who knows. Besides, even if he is taking a class, there are millions of ways to cheat, and he is only hurting himself. I am not hurting a person like that because they would find other ways to cheat.

    Thanks my opinion anyways, I hope people dont have to start listing details of exactly why a question is being asked before it will be answered. I can see it now...
    My name is X, i work for company Y, my boss does know that I am asking for help online, here is a signed consent form. Now, my question is....
    PS - this is what part of the alphabet would look like if Q and R were eliminated.

  • #10
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Quote Originally Posted by redoc
    Hey, im here to help whenever I can. I didn't post any code itself (unless psuedo code counts, and i dont think so). I posted an algorithm that could be implemented in any language you want, and a kickstart on how to do it. Perhaps this person is learning on his own using a coursebook from a friend, who knows. Besides, even if he is taking a class, there are millions of ways to cheat, and he is only hurting himself. I am not hurting a person like that because they would find other ways to cheat.

    Thanks my opinion anyways, I hope people dont have to start listing details of exactly why a question is being asked before it will be answered. I can see it now...
    My name is X, i work for company Y, my boss does know that I am asking for help online, here is a signed consent form. Now, my question is....
    Like I said before half of the programming assignments are about solving the logic of the problem and you did that for them. The second part is coding and by giving them such detailed pseudocode you pretty much did the entire assignment for them.

    As we are the moderators here we can and will enforce rules as we see fit. We do not condone cheating here at CodingForums period. No if's and's or but's about it. A moderator already stated not to do the homework for them and you basically ignored that and posted it anyways. Some of us have been moderators here for several years so we are very experienced at spotting people trying to get other people to do their homework assignments for them.

    If you have a problem with us not allowing cheating here at CodingForums you are more than welcome to take it up with the management.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #11
    New Coder
    Join Date
    Jan 2005
    Location
    Iowa City
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Spookster
    As we are the moderators here we can and will enforce rules as we see fit.
    ...
    If you have a problem with us not allowing cheating here at CodingForums you are more than welcome to take it up with the management.
    I have no problems with following the rules, as long as those rules are expressed. I have read the rules of posting, and it did not mention anything about cheating whatsoever. If there is a rule about cheating, I suggest to management that it be placed in the forums Rules so all can be aware of it. Until then, I will answer any questions within my knowledge.
    PS - this is what part of the alphabet would look like if Q and R were eliminated.

  • #12
    jkd
    jkd is offline
    Senior Coder jkd's Avatar
    Join Date
    May 2002
    Location
    metro DC
    Posts
    3,163
    Thanks
    1
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by redoc
    I have read the rules of posting, and it did not mention anything about cheating whatsoever. If there is a rule about cheating, I suggest to management that it be placed in the forums Rules so all can be aware of it. Until then, I will answer any questions within my knowledge.
    A quick reality check... shouldn't the act of cheating on an assignment, and thereby violating the university's or school's plagiarism policy (which is enough to often expel a student) itself constitute enough of a reason to refrain from doing so?

    This rules of this forum don't dictate the rules of higher academic institutions or even those of simple ethics. There is no forum rule explicitly forbidding hacking CF's vBulletin installation, but you know what? It's just as illegal to do so regardless.

    You made a mistake posting the code, oh well. We're not going to hold it against you (at least I won't, and I'll use my supermoderator status to that end), but accept it and move on.
    Last edited by jkd; 02-27-2005 at 03:26 AM.

  • #13
    New Coder
    Join Date
    Jan 2005
    Location
    Iowa City
    Posts
    47
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I didn't cheat on anything... I answered somebodies question. I dont know how they used that information... Mccormick may (or may not) have cheated. He did the wrongdoing if he indeed did cheat. I made no mistake in my posting, and will continue to answers peoples questions. If this is a problem, I guess I will be banned.
    PS - this is what part of the alphabet would look like if Q and R were eliminated.

  • #14
    New Coder
    Join Date
    Nov 2003
    Location
    I have no life
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm not going answer the direct question, but instead, give you some pretty general tips:
    Code:
    #include <string>
    char& std::string::operator [](index);
    bool operator ==(std::string &lhs, std::string &rhs);
    Come to my site, currently under construction.

  • #15
    cfc
    cfc is offline
    Regular Coder
    Join Date
    Dec 2004
    Location
    Keswick, Ontario
    Posts
    251
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by redoc
    I didn't cheat on anything... I answered somebodies question. I dont know how they used that information... Mccormick may (or may not) have cheated. He did the wrongdoing if he indeed did cheat. I made no mistake in my posting, and will continue to answers peoples questions. If this is a problem, I guess I will be banned.
    That's taking too simple of a perspective on giving people answers to homework. If a moderator posts not to help somebody because they identify it as cheating on an assignment, don't help them unless the person asking provides a reasonable excuse. It may not be a rule, but it has been posted by the administrator elsewhere and by the moderators several times. You're not technically helping them with their problem if you're depriving them of the fundamental ability to analyze problems and relate them to code.

    Would you have gained your abilities if somebody did all of your coding for you?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •