...

View Full Version : C++ programm (palindrome using string???)



mccormick
02-24-2005, 06:39 AM
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??
:confused: :confused: :confused:

jkd
02-24-2005, 07:00 AM
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.

redoc
02-24-2005, 07:09 AM
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:



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"

Spookster
02-24-2005, 08:01 AM
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. :rolleyes:

abbeyroadd
02-24-2005, 05:04 PM
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.

Spookster
02-24-2005, 08:03 PM
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.

Antoniohawk
02-24-2005, 10:20 PM
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.

abbeyroadd
02-24-2005, 11:33 PM
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.



#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.

redoc
02-25-2005, 01:25 AM
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....

Spookster
02-25-2005, 05:24 AM
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.

redoc
02-27-2005, 01:36 AM
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.

jkd
02-27-2005, 03:24 AM
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.

redoc
02-27-2005, 05:48 AM
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.

deadimp
02-28-2005, 02:55 AM
I'm not going answer the direct question, but instead, give you some pretty general tips:

#include <string>
char& std::string::operator [](index);
bool operator ==(std::string &lhs, std::string &rhs);

cfc
02-28-2005, 04:43 AM
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 (http://www.codingforums.com/showthread.php?t=2090) 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?

redoc
03-01-2005, 03:26 AM
I went to the link you provided, and did not see anything there about how you shouldn't answer questions that someone has suspected of being homework. I DID see where it said do not post your homework questions. I did not post a homework question. I answered a question from someone that may have been homework. Or it could have been a person playing with a language in their spare time.

If they are trying to cheat, they aren't helping themselves... and that is not of my concern.

Antoniohawk
03-01-2005, 03:37 AM
Redoc, no one is totally blaming you, but you're also not exactly innocent. The fact is that sometimes it is hard to tell when it's a homework assignment, and when it's just your average guy honing his skills.

I'd have to say that this thread has run its course and that this shall serve as a warning to make an effort not to do people's homework for them in the future. And to all of those attempting to post their homework problems, you're just hurting yourself (and bringing out Spookster's bad side :)).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum