Consider making a function (mini program to complete a specific task) for each of the scenarios below. State what the purpose of the function is in your own words, specify input that is needed by the function, what output is expected from the functions, and the step by step process that will obtain the output from the input (the algorithm). In addition to these 4 items also specify test data that can be used for each problem. Remember to describe your steps in enough detail so someone other than you could follow your algorithm and solve the problem. Also do not write any actual code. However as you list the steps, you may want to employ statements such as “repeat steps 2-4 until n is reached. Problem 1: Create a process that will calculate the series 1 + x + x2 + x3 + x4 ………. + xn where x is a floating point number and n is a positive number. You process should be designed so exponentiation functions are not needed. Problem 2: Write a process that will complete will find the sum of the following series. (Again do not use any exponentiation functions). 1/n + 2/(n-1) + 3/(n-2) + ………. + n/1 Program 3: Write a process to determine the average of values entered by the user. These values should be entered one at a time (do not use concept of arrays or lists).
copy to code:
#include <iostream>
using namespace std;
/*this function will calculate 1 + x + x2 + x3 + x4 ………. + xn*/
float calculateExponentialSeries(float x, int n){
//first value of series 1 store in the result
float result = 1;
//it will store the power value of element
float powerX;
//print first 1 of series
cout<<"1 ";
//loop until n
for(int i=1;i<=n;i++){
powerX=1;
//calculate the power of x for i
for(int j=1;j<=i;j++){
powerX*=x;
}
//print x and x2 based on input
cout<<"+ "<<x<<"^"<<i;
//set result to input
result+=powerX;
}
//print result
cout<<" = "<<result<<endl;
return result;
}
/*this function will calculate 1/n + 2/(n-1) + 3/(n-2) + ………. + n/1 */
float calculateDiffSeries(int n){
float result = 0;
//it will store the divide value of elements
float differentialValue;
//loop till n
for(float i=1;i<=n;i++){
//calculate the value
differentialValue = i/(n+1-i);
//store in result
result+=differentialValue;
//print series
cout<<i<<"/"<<"("<<n<<" - "<<i-1<<") ";
if(i!=n){
cout<<"+";
}
}
cout<<" = "<<result<<endl;
return result;
}
/*this function will calculate average of values entered by the user.*/
float averageOfValue(){
cout<<"Enter the values . 0 to exit"<<endl;
float input=-1,noOfInput=0,total=0;
cin>>input;
//ask user input until 0 entered
while(input!=0){
//increase the number of input by 1
noOfInput++;
//add input to total
total+=input;
//ask for next input
cin>>input;
}
//calculate the average
float average = total/noOfInput;
//print average
cout<<"Average is "<<average;
return average;
}
//main function calling all other function
int main(){
calculateExponentialSeries(2,9);
calculateDiffSeries(2);
averageOfValue();
return 0;
}
output:
Consider making a function (mini program to complete a specific task) for each of the scenarios...
Student ID: 123 Write a C+ program with the following specifications: a. Define a C++ function (name it function_StudentlD where StudentID is your actual student ID number) that has one integer input (N) and one double input (x) and returns a double output S, where N S = n 0 and X2 is given by 0 xeVn n 0,1 Хл —{2. nx 2 n 2 2 m2 x2 3 (Note: in the actual quiz, do not expect a always, practice...
In this homework, you will design a program to perform the following task: Write a program that would allow a user to enter student names and Final grades (e.g. A,B,C,D,F) from their courses. You do not know how many students need to be entered. You also do not know how many courses each of the students completed. Design your program to calculate the Grade Point Average (GPA) for each student based on each of their final grades. The program should...
in C++ Extract and Add a Series of Numbers: Write a program that will extract a series of numbers (type double) from an input sentence and then add them. EXAMPLE: Suppose the sentence entered is “Give me the sum of 25.25 and 13.50. ”The program should print to the screen: The sum = 38.75 NOTE: The numbers can be of any value. Don’t hard code to the values shown in the example. In this problem take advantage of the input...
Write a matlab program to apply Horner's algorithm to evaluate the sum of the first four nonzero terms of the Taylor series for sin(x) with c=0. Your program should not use any arrays, the exponentiation operator or the factorial function. Print out your program and include the output upon execution for the special case where x = 1. How many nonzero terms of the above Taylor series are needed to guarantee that the sum approximates sin(x) to within .0001 for...
IN MATLAB RECURSIVE FUNCTION 1. Sum of Factorials. The Recursive Function: A series that sums up the factorial of the natural numbers from 1 to N can be expressed as The recursive algorithm: N-1 N-2 N-3 Write independent matlab code to solve the above problem with the following methods: 1. 2. 3. A monolithic program (with no functions) A standard (non-recursive) user defined function (an a program to call it) A recursive function (an a program to call it) Test...
project 5 functions calling functions white a program that determines if 3 numbers that are entered, by the user, are sides of a right triangle. remember any combination of numbers can be entered, 3 4 5, 5 4 3, 4 3 5... are all the same right triangle. you must have a function that does exponentiation, one that does input one that does output. and one that does the comparisons the main will be this code main: jal allwork li $v0,10 syscall function allwork will...
C++ Problem 1 Write a function to calculate the greatest common divisor (GCD) of two integers using Euclid’s algorithm (also known as the Euclidean algorithm). Write a main () function that requests two integers from the user, calls your function to compute the GCD, and outputs the return value of the function (all user input and output should be done in main ()). In particular, you will find this pseudocode for calculating the GCD, which should be useful to you:...
In a series of numbers, a "mini peak" is a set of 3 numbers where the middle number is strictly greater than its adjacent left and right neighbors. For example, the array: [ 4, 6, 2, 1 ] contains 1 mini peak, with 6 in the middle ([ 4, 6, 2]). Write full and complete C++ program to open a text file named numbers.txt in the working folder, which contains groups of numbers, one per line, with each group starting...
use matlab To use the digits function, enter 1 To use the average function, enter 2 To use the perfect sum function, enter3 To exit the program, enter 4 Please select a number = 6 Please re-select again: 2 please enter the first number 3 please enter the second number: 6 please enter the third number: 3 The average equals to: 4 Write a function, called digits function that is able to calculate the number of digits and the summation...
Write a complete Java program, including comments in both the main program and in each method, which will do the following: 0. The main program starts by calling a method named introduction which prints out a description of what the program will do. This method is called just once. This method is not sent any parameters, and it does not return a value. The method should print your name. Then it prints several lines of output explaining what the...