Page 1 of 1

Hi if I could get some help with this program in c++ that would be amazing! Comment if you need anymore info. Thank you

Posted: Fri May 20, 2022 5:08 pm
by answerhappygod
Hi if I could get some help with this program in c++ that would
be amazing! Comment if you need anymore info. Thank you
Assignment 8 Part A - required [40 points] - Recursive
algorithms
Rather than using a while statement, do-while statement, or for
statement to execute a segment of code again, the programs with
recursive algorithms use a selection statement (if or switch
statement) to determine whether to repeat the code by calling the
function again or to stop the process.
Each recursive solution has at least two cases: the base case
and the general case. The base case is the one to which we have an
answer; the general case expresses the solution in terms of a call
to itself with a smaller version of the problem. Because the
general case solves a smaller and smaller version of the original
problem, eventually the program reaches the base case where an
answer is known and the recursion stops.
Listed below are a few such programming challenges requiring
function algorithms with recursive
solutions. Carefully read the program specifications
for each recursive set of algorithms and select any TWO
from the three sets provided below.
(b) Recursion with String Types [20 points]
For the second recursive set of algorithms for this assignment
..write a program with two separate recursive functions to process
characters in a string. Demonstrate the function algorithms in
a driver program.
Embed the two recursive functions* in a program and
write a couple of drivers to test your functions. You may use the
sample program interface provided
: sample8b.cpp Download sample8b.cpp or create your
own. Submit your final source code.
sample8b.cpp
//Sample test driver code for assignment 8b
#include <iostream>
#include <string>
using namespace std;
// Sample Function prototype
void strReverse(/*in*/string,/*in*/ int);
bool isPalindrome(/*in*/string);
int main( )
{
// To hold string input
string input;
// Get a string to test the strReverse function algorithm.
cout << "What is the name of your college? ";
getline(cin, input);
// Display string input backwards.
cout << "\nYour college name backward is ";
strReverse(input, input.length() - 1);
cout << endl;
cout <<
"\n---------------------------------------------------- \n\n"; //
a
spacer
const int SIZE = 6;
// Create an array of strings to test the isPalindrome
algorithm.
string testStrings[SIZE] =
{ "ABLE WAS I ERE I SAW ELBA",
"FOUR SCORE AND SEVEN YEARS AGO",
"NOW IS THE TIME FOR ALL GOOD MEN",
"DESSERTS I STRESSED",
"AKS NOT WHAT YOUR COUNTRY CAN DO FOR YOU",
"KAYAK" };
// Test the strings.
for (int i = 0; i < SIZE; i++)
{
cout << "\"" << testStrings << "\"";
if (isPalindrome(testStrings))
cout << " is a palindrome.\n";
else
cout << " is NOT a palindrome.\n";
}
cout <<
"\n---------------------------------------------------- \n\n"; //
a
spacer
cout << "\nNow exiting the function test driver program.
\n";
return 0;
}
/*
Function strReverse: This function accepts a string object and an
integer
containing the length of the string as its arguments. The function
uses
recursion to display the string backward.
*
*/
void strReverse(/*in*/string str,/*in*/ int length)
{
// TBD: strReverse recursive algorithm to reverse string str
parameter and
display result....
}
/*
Function isPalindrome: Returns true if the argument sent to
parameter string str
is a palindrome, false otherwise. The algorithm uses recursion to
update and
returns
the current state of bool status. *
*/
bool isPalindrome(/*in*/ string str)
{
bool status = false;
// TBD: isPalindrome recursive algorithm to determine and return
status of string
str parameter....
return status;
}
/* A sample Test results of completed program output
What is the name of your college? Santa Rosa Junior College
Your college name backward is egelloC roinuJ asoR atnaS
----------------------------------------------------
"ABLE WAS I ERE I SAW ELBA" is a palindrome.
"FOUR SCORE AND SEVEN YEARS AGO" is NOT a palindrome.
"NOW IS THE TIME FOR ALL GOOD MEN" is NOT a palindrome.
"DESSERTS I STRESSED" is a palindrome.
"AKS NOT WHAT YOUR COUNTRY CAN DO FOR YOU" is NOT a
palindrome.
"KAYAK" is a palindrome.
----------------------------------------------------
Now exiting the function test driver program.
Process returned 0 (0x0) execution time : 8.225 s
Press any key to continue.
*/