Question
So trying to write in C++, So I understand an arithmetic progression (AP) is a sequence of numbers such that the difference between the consecutive
So trying to write in C++,
So I understand 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.
Which need to 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. I have some of the code done:
#include
int AP(int start, int diff, int n) { static int result=0; static int i=0; // Nth term t(n) = a + (n-1)*d if(i<=n) { result = start + (i - 1) * diff; i++; return AP(start,diff,n); } return result; }
Then need to write a recursive function named averageArray that compute the average of an array of double values. Which averageArray can call another function that uses recursion to sum the elements. So then use average of {8.1, 9.9, 5.6, 7.8} is 7.85.
Which then need a recursive function named stdDevArray that compute the standard deviation of an array of double values. So to compute standard deviation:
First step, for each number in the array, subtract the average and then square the result.
Second step, sum the squared differences from step I and divide by the size.
Third step, take the square root of the result of step two.
So I believe I can use stdDevArray can call averageArray and stdDevArray can call another function that uses recursion to sum the squared differences, correct? The standard deviation of {8.1, 9.9, 5.6, 7.8} is 1.52725.
Then have 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 key[0], B and b should be replaced with key[1], etc. Do not encrypt characters that are not letters (copy them directly to the result).
So can use A-A is 0, B-A is 1, C-A is 2, D-A is 3, etc.
Also, toupper(ch) converts ch to uppercase, isalpha(ch) is true if ch is a letter.
So once call the function, encrypt(Energy!,"XYZABCDEFGHIJKLMNOPQRSTUVW") is BKBODV!
So all the function should go with a test code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started