Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2.1 Arithmetic Progression, Mean, Standard Deviation, Encrypt (20 points] 1. Arithmetic progression An arithmetic progression (AP) is a sequence of numbers such that the difference

image text in transcribed
image text in transcribed
2.1 Arithmetic Progression, Mean, Standard Deviation, Encrypt (20 points] 1. Arithmetic progression An arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive terms is constant. For instance, 5, 7, 9, 11, 13, 15.... is an arithmetic progression starting at 5 with common difference of 2. Write a recursive function named AP that takes three non-negative integer parameters start, diff, and n and returns the nth value in the arithmetic progression starting at start, with difference diff. For example, AP(5,2,0) is 5, AP(5,2,4) is 13, and AP(1,10,5) is 51. Hint: perform recursion over n and in your recursive calls, keep start and diff constant. 2. AverageArray Write a recursive function named averageArray that compute the average of an array of double values. Hint: averageArray can call another function that uses recursion to sum the elements. The average of (8.1,9.9.5.6.7.8) is 7.85. 3. Std DevArray Write a recursive function named stdDevArray that compute the standard deviation of an array of double values. To compute standard deviation: 1. For each number in the array, subtract the average and then square the result. II. Sum the squared differences from step I and divide by the size. III. Take the square root of the result of step II. Hint: stdDevArray can call averageArray, stdDevArray can call another function that uses recursion to sum the squared differences. The standard deviation of (8.1, 9.9.5.6, 7.8) is 1.52725. 4. Encrypt Write a recursive function (using substr) named encrypt that takes a string, str, to be encrypted and a string of 26 unique characters called the key. The function should return a copy of str encrypted using the key. Every letter in str should be replaced by the corresponding character in the key as follows: 'A' and 'a' should be replaced with keyf01, 'B' and 'b' should be replaced with key[1], etc. Do not encrypt characters that are not letters (copy them directly to the result). Hints: 1. 'A'-'A' is 0, 'B-A'is 1, C-A' is 2, D'-A'is 3, etc. II. toupper(ch) converts ch to uppercase, isalpha(ch) is true if ch is a letter. encrypt("Energy!", "XYZABCDEFGHIJKLMNOPQRSTUVW") is BKBODV! III. All the functions along with your test code should go into a file called "Assign2_Q1.cpp". Make sure your code works correctly

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

Step: 3

blur-text-image

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