C++ Recursion Palindrome

Page 1 of 1

14 Replies - 725 Views - Last Post: 09 February 2020 - 12:46 AM Rate Topic: -----

#1 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

C++ Recursion Palindrome

Posted 08 February 2020 - 10:10 AM

Hello All,

I'm a pure beginner at C++. I don't know advandced concepts such as loops etc good. So please keep that in mind. I have posted what i started but it is wrong and not finished with a ton of inncorrect things im sure. I need help completing this assignement,

For this assignment, you will create a program that tests a string to see if it is a palindrome. A palindrome is a string such as “madam”, “radar”, “dad”, and “I”, that reads the same forwards and backwards. The empty string is regarded as a palindrome. Write a recursive function:

bool isPalindrome(string str, int lower, int upper)

that returns true if and only if the part of the string str in positions lower through upper (inclusive at both ends) is a palindrome. Test your function by writing a main function that repeatedly asks the user to enter strings terminated by the ENTER key. These strings are then tested for palindromicity. The program terminates when the user presses the ENTER key without typing any characters before it.


//CIS 221 M5 assignment
#include <iostream>
#include <string>

using namespace std;

bool isPalindrome(string str, int lower, int upper);

int main()
{
	string word;

	cout << "Enter a word to see if its a palindrome" << endl;
	getline(cin, word);

	if (isPalindrome(word))
		cout << word << " : is a palindrome." << endl;
	else
		cout << word << " : is not a palindrome." << endl;

	return 0;

}

bool isPalindrome(string str, int lower, int upper)
{
	if (string.length() <= 1)
		return 0;

	return (string[0] == string[string.lenght() - 1])

		isPalindrome;
}






Is This A Good Question/Topic? 0
  • +

Replies To: C++ Recursion Palindrome

#2 Salem_c   User is offline

  • void main'ers are DOOMED
  • member icon

Reputation: 2415
  • View blog
  • Posts: 4,547
  • Joined: 30-May 10

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 10:17 AM

Also here -> http://www.cplusplus...eginner/267939/
Was This Post Helpful? 2
  • +
  • -

#3 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 10:21 AM

I know =) That’s also me.
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7240
  • View blog
  • Posts: 24,551
  • Joined: 05-May 12

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 11:08 AM

Yes, and it looks like you are getting relevant timely help there. Why should we waste our time duplicating the effort?

If you posted here hoping someone would just do your homework for you, unfortunately you will be disappointed. We are not a code writing service. Like the other forum, we will guide you towards a solution but you will have to put in the effort.

For you to say that loops are an advanced concept is frightening. It is one of the basic operations of flow control. I highly suggest taking time to talk to your instructor and tell her that you are falling behind and need help. They may have some recommendations for remedial help.
Was This Post Helpful? 1
  • +
  • -

#5 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 11:15 AM

I didn’t ask for a code writing service nor did I ask someone to complete the whole assignment for me.
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7240
  • View blog
  • Posts: 24,551
  • Joined: 05-May 12

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 11:50 AM

In which case, in my opinion, the level of help you are getting at the other forum is perfect for guiding you towards a solution.
Was This Post Helpful? 0
  • +
  • -

#7 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 12:24 PM

They are not fully helping me
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7240
  • View blog
  • Posts: 24,551
  • Joined: 05-May 12

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 12:55 PM

To quote Repeater from that other forum:

Quote

Thus far, you're just copying what other people have written and mixing it round and round. You need to think.


Right now, you are just throwing code at the problem. It feels like the type of help you are looking for is to get some code written. The issue though, is that you need to understand the problem, and then come up with a plan to solve it. You are trying to drive straight to the solution without even having a plan. You are just hoping to stumble across some running code.

Early in the thread in the other forum, somebody advised you to figure out how you would solve it on paper first. Have you done so? If so, can you describe step by step the procedure you applied to solve it? If so, those detailed steps are the beginnings of your code.
Was This Post Helpful? 1
  • +
  • -

#9 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 01:00 PM

Besides putting my preprocessor directives and declaring variables. I have no clue where to start at. I’m a very basic beginner at c++ . This is my online college assignment but there is limited opportunities to get the type of help I need from the teacher
Was This Post Helpful? 0
  • +
  • -

#10 dr3am1nc0d3   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 01-December 18

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 01:41 PM

Greetings, you have to remember how recursion works. Have you ever experimented with proof by induction? Recursion works in a similar fashion.

You have to ask yourself what is your base case? Once you establish a base case(s) then you can call your function within itself (that is what incursion is). However, each time you effectively call your recursive function, you are adding onto your recursive stack. Trace it, what is it doing exactly? For me, I usually get out a pen and paper and find out what the code is doing. Don't give up too easily, this thing is hard for us all when we are beginners and even when you become relatively experienced, recursion can still sometimes be annoying.
Was This Post Helpful? 0
  • +
  • -

#11 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 04:49 PM

What should my base case be ?
Was This Post Helpful? 0
  • +
  • -

#12 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7240
  • View blog
  • Posts: 24,551
  • Joined: 05-May 12

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 06:06 PM

If the length is even, the two adjacent letters are the same. If the length is odd, then the fact that you made it that far.

Try it out an paper, specially with the examples presented by the folks over in the other forum. It will become much clearer when you do it yourself instead of someone telling you.
Was This Post Helpful? 0
  • +
  • -

#13 Skydiver   User is online

  • Code herder
  • member icon

Reputation: 7240
  • View blog
  • Posts: 24,551
  • Joined: 05-May 12

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 08:49 PM

Looks like somebody just got exasperated on the other forum thread and just spoonfed the answer. Even more curious, is that apparently people had observed that the OP is a habitual help vampire that just keeps playing dumb until somebody does his work for him.
Was This Post Helpful? 1
  • +
  • -

#14 [email protected]   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 11
  • Joined: 08-February 20

Re: C++ Recursion Palindrome

Posted 08 February 2020 - 08:55 PM

How do I play dumb ? I don’t know what I’m doing . I’ve made clear
Was This Post Helpful? 0
  • +
  • -

#15 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15502
  • View blog
  • Posts: 62,074
  • Joined: 12-June 08

Re: C++ Recursion Palindrome

Posted 09 February 2020 - 12:46 AM

Chillax . It's Sunday.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1