Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this assignment you will use the myString class that you wrote earlier in this course. A palindrome is a string that reads the same

In this assignment you will use the myString class that you wrote earlier in this course.

A palindrome is a string that reads the same forward and backward. Write a program that reads in any number of myStrings of characters from the user and determines if each myString is a palindrome. The user will terminate each myString by pressing the return (or enter) button. The user will indicate that there are no more myStrings by entering "quit".

Do not make any changes to the myString class. Do not use the C++ string class.

To do this you must write a recursive function named isAPalindrome that takes a single MyString argument and two arguments that are bounds on array indices. The function must examine the part of the argument between the two bounds (including the bounds) and return true if this part of the argument is a palindrome, false if it is not a palindrome. The function must be recursive and must not call any other functions except ispunct(), isspace(), and toupper() (described below).

Follow this sample output closely:

Enter a string: Able was I, ere I saw Elba Able was I, ere I saw Elba is a palindrome. Enter a string: peanut butter peanut butter is not a palindrome. Enter a string: quit 

In determining whether a string is a palindrome, this function must consider uppercase and lowercase letters to be the same and ignore punctuation characters and whitespace characters. You should not modify the argument in any way to accomplish this. The simplest way to handle uppercase/lowercase issues is to make everything uppercase on the fly, right at the instant that you are comparing the two characters.

You will want to use three functions that are in the cctype library (i.e. you must #include cctype to use them). They are ispunct(char), a bool function which returns true if its argument is a punctuation mark and false otherwise, isspace(char), which returns true if its argument is a whitespace character and false otherwise, and toupper(char), which returns the uppercase equivalent of its argument (without changing the argument itself).

I strongly suggest that you first write this program so that it works in the general case (i.e. assuming that all letters are uppercase and no characters are punctuation characters or whitespace characters), and then add code to handle the uppercase/lowercase and puncuation/whitespace issues.

Assignment 16.3 [15 points]

Write a recursive function to sort an array of integers into ascending order using the following idea: place the smallest element in the first position, then sort the rest of the array by a recursive call. This is a recursive version of the selection sort. (Note: You will probably want to call an auxiliary function that finds the index of the smallest item in the array. Make sure that the sorting function itself is recursive. Any auxiliary function that you use may be either recursive or iterative.) Embed your sort function in a driver program to test it. Turn in the entire program and the output.

Submit Your Work

You will be submitting three files

Code to edit:

#include using namespace std;

void reverseWithinBounds(char arr[], int low, int up){

// base case if(low >= up) return;

char temp = arr[low]; arr[low] = arr[up]; arr[up] = temp;

// recursive case reverseWithinBounds(arr, low+1, up-1); }

int main(){

char arr[] = "pravesh";

cout<

reverseWithinBounds(arr, 2, 6);

cout<

return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

List the steps needed to develop an activity-based cost.

Answered: 1 week ago

Question

Explain the causes of indiscipline.

Answered: 1 week ago

Question

5. Our efficiency focus eliminates free time for fresh thinking.

Answered: 1 week ago