CS117-Palindrome

Exercise #1

A palindrome is any word or phrase which reads the same backwards as it does forward. For instance the word Bob is a palindrome. Napoleon is also attributed as saying the famous palindrome Able was I ere I saw Elba. As a counter example the phrase Computer Science is fun is NOT a palindrome.

For this exercise you will implement a program which asks the user for a string. The program will then output whether or not the phrase is a palindrome.

Hint: use an array of characters to determine if the string is a palindrome.

Sample output:

1
2
3
Enter a phrase: Rise to vote sir

"Rise to vote sir" IS A PALINDROME

Save your solution in a file named palindrome.cpp.

Exercise #2

In statistics, the standard deviation measures the amount of variation or dispersion from the average. It can be calculated using the following formula:

1
σ =√∑(x−μ)2 / n

Where σ is the standard deviation, x is each value in the data set, μ is the mean of all values in the data set, and n is the number of values in the data set. For your program you will ask the user for double values. Your program should stop when the user enters -99 when at this point your program will display the mean and the standard deviation from the data set.

Sample output:

1
2
3
4
5
6
7
Enter a value (or -99 to quit): 3
Enter a value (or -99 to quit): 5
Enter a value (or -99 to quit): 11
Enter a value (or -99 to quit): 14
Enter a value (or -99 to quit): 11
Enter a value (or -99 to quit): -99
The average is 8.8 with a standard deviation of 4.11.

Save your solution in a file named stddev.cpp.

Exercise #3

Consider the classic number guessing game we played in class, where one person thinks of a number and the second player attempts to guess that number given a number of attempts. For this exercise, you will write a program where the user will think of a number between 1 and 100, and the computer will attempt to guess it using the binary search algorithm.

Sample output:

1
2
3
4
5
Think of a number between 1 and 100.    Ready?    (Y/N)    Y
Is the number 50? (1=Higher, 2=Lower, 3=Exact) 2
Is the number 25? (1=Higher, 2=Lower, 3=Exact) 1
Is the number 37? (1=Higher, 2=Lower, 3=Exact) 3
Thanks for playing.

Save your solution in a file named guess.cpp.

Exercise #4

For this exercise you will read in student names and test scores into two arrays: an array of strings for the names and an array of integers for the scores. You will write a program which sorts the scores and displays the scores from highest to lowest and the student’s name who received the grade. Please use one of the sorting algorithms discussed in class. Do not use std::sort.

Implement the sort using either the Quick Sort algorithm, Merge Sort algorithm or with any advanced sorting algorithm with an average case runtime of Θ(nlog2n).

Sample output:

1
2
3
4
5
6
7
8
9
10
11
How many students took the exam?    3
Student #1 Name: Justin Verlander
Student #1 Score: 84
Student #2 Name: Jon Lester
Student #2 Score: 96
Student #3 Name: Clayton Kershaw
Student #3 Score: 51
RESULTS:
Jon Lester 96
Justin Verlander 84
Clayton Kershaw - 51

Save your solution in a file named reversal.cpp.