Detecting Palindromes with Recursion & Templates in CSCI 270, Fall 2004, Assignments of Data Structures and Algorithms

A programming assignment for csci 270 students in the fall 2004 semester. The assignment focuses on writing a recursive function and a function template to test if an array is a palindrome, which reads the same forward and backward, regardless of the array's character type. The document also includes instructions for creating a test driver program to read character strings from a file and output palindromes.

Typology: Assignments

Pre 2010

Uploaded on 08/18/2009

koofers-user-i45-1
koofers-user-i45-1 🇺🇸

10 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CSCI 270 Program Assignment 3
Fall 2004 Due: Thursday, 4 Nov
Emphasis on: Using Recursion and Templates to Detect Palindromes
In this assignment you will be asked to write a recursive function that tests whether an array of
characters is a palindrome. You will then rewrite the function as a function template so that you
can determine if an array of any type (e.g. arrays of int, float, bool) are palindromes.
A palindrome in the context of english words is a word that reads the same forward and
backward. For instance, the following are palindromes:
dad level did madamimadam
A couple of hints to get you started. An array with 0 or 1 characters will be defined to be a
palindrom (e.g. stopping condition). If the first and last characters of the array are equal, then it
is a palindrome provided the string in between the ends is also a palindrome.
Part A:
Write a recursive function that accepts an array of characters (and possibly other parameters)
and determines if the character array is a palindrome as defined above. The function should
return a bool result that is true if it is a palindrome and false otherwise.
Part B:
Modify your function from part A to turn it into a function template. Thereby allow your
palindrome testing function to test not only if an array of characters is a palindrome, but also
arrays of ints, floats, etc.
Part C:
Write a test driver program that will read in character strings from a file. The input file will have
1 word per line. You should read in each line as a character array then test if it is a palindrome.
If the line is a palindrome write it back out to standard output.
Requirements
1) You must create and use a function that solves the palindrome testing using true recursion
2) The palindrome function must be made into a template that can test for palindromes in any
type of array.
3) Your test driver program should read in all lines in the input file and only output those lines
that are palindromes.

Partial preview of the text

Download Detecting Palindromes with Recursion & Templates in CSCI 270, Fall 2004 and more Assignments Data Structures and Algorithms in PDF only on Docsity!

CSCI 270 Program Assignment 3

Fall 2004 Due: Thursday, 4 Nov

Emphasis on: Using Recursion and Templates to Detect Palindromes

In this assignment you will be asked to write a recursive function that tests whether an array of characters is a palindrome. You will then rewrite the function as a function template so that you can determine if an array of any type (e.g. arrays of int, float, bool) are palindromes.

A palindrome in the context of english words is a word that reads the same forward and backward. For instance, the following are palindromes:

dad level did madamimadam

A couple of hints to get you started. An array with 0 or 1 characters will be defined to be a palindrom (e.g. stopping condition). If the first and last characters of the array are equal, then it is a palindrome provided the string in between the ends is also a palindrome.

Part A: Write a recursive function that accepts an array of characters (and possibly other parameters) and determines if the character array is a palindrome as defined above. The function should return a bool result that is true if it is a palindrome and false otherwise.

Part B: Modify your function from part A to turn it into a function template. Thereby allow your palindrome testing function to test not only if an array of characters is a palindrome, but also arrays of ints, floats, etc.

Part C: Write a test driver program that will read in character strings from a file. The input file will have 1 word per line. You should read in each line as a character array then test if it is a palindrome. If the line is a palindrome write it back out to standard output.

Requirements

1) You must create and use a function that solves the palindrome testing using true recursion

2) The palindrome function must be made into a template that can test for palindromes in any

type of array.

  1. Your test driver program should read in all lines in the input file and only output those lines that are palindromes.