Question

In: Computer Science

Can someone please walk through this program for me and explain out the outputs are generated....

Can someone please walk through this program for me and explain out the outputs are generated.

#include <iostream>
#include <iomanip>
using namespace std;
const int size = 5;
int fun(int arz[size], int jump)
{
int i, j = 0;
for(i = 0; i < size; i += jump)
j += arz[i];
return j;
}
main()
{
int arx[size] = {1, 2, 4, 8, 16};
int ary[size] = {10, 20, 40, 80, 160};
cout << fun(arx, 1) << endl;
cout << fun(ary, 2) << endl;
cout << fun(arx, 3) << endl;
cout << fun(ary, 4) << endl;
cout << fun(arx, 5) << endl;
cout << fun(ary, 6) << endl;
} // main

Solutions

Expert Solution

//header files
#include <iostream>
#include <iomanip>
using namespace std;
//constant size having value 5
const int size = 5;
//function fun accepting array and an integer as an argument
int fun(int arz[size], int jump)
{
//set i, j to 0
int i, j = 0;
//loop in which i go from 0 to size-1 incrementing by jump
for(i = 0; i < size; i += jump)
j += arz[i];//add arr[i] to j and store back in j
//return j
return j;
}
//main function
main()
{
//array arx and ary both having 5 elements in it
int arx[size] = {1, 2, 4, 8, 16};
int ary[size] = {10, 20, 40, 80, 160};
//calling fun by passing arx and 1
cout << fun(arx, 1) << endl;
//calling fun by passing ary and 2
cout << fun(ary, 2) << endl;
//calling fun by passing arx and 3
cout << fun(arx, 3) << endl;
//calling fun by passing ary and 4
cout << fun(ary, 4) << endl;
//calling fun by passing arx and 5
cout << fun(arx, 5) << endl;
//calling fun by passing ary and 6
cout << fun(ary, 6) << endl;
} // main


Related Solutions

Can someone please explain the following program to me? I have ran it, but do not...
Can someone please explain the following program to me? I have ran it, but do not understand how the answers are being derived. #include<iostream> using namespace std; int num1 = 1; int quiz(int num) { static int n1 = 10; int n2 = 20; n1--; n2++; num1++; if (num == 1) return num1; else if (num < 3) return n1; else return n2; } // quiz main() { cout << quiz(num1) << endl; cout << quiz(num1) << endl; cout <<...
Can someone walk me through this problem. Bill Alther is a zoologist who studies Anna's hummingbird...
Can someone walk me through this problem. Bill Alther is a zoologist who studies Anna's hummingbird (Calypte anna). (Reference: Hummingbirds, K. Long, W. Alther.) Suppose that in a remote part of the Grand Canyon, a random sample of six of these birds was caught, weighed, and released. The weights (in grams) were as follows. 3.7 2.9 3.8 4.2 4.8 3.1 The sample mean is = 3.75 grams. Let x be a random variable representing weights of hummingbirds in this part...
Can anyone walk me through this please!!-- Build a Monte Carlo simulation model to solve a...
Can anyone walk me through this please!!-- Build a Monte Carlo simulation model to solve a project problem. He does not provide that information, it just says a probabilistic model.
Trace through the program and what the outputs will be. If there is an error explain...
Trace through the program and what the outputs will be. If there is an error explain what must be fixed and continue to trace through. #include <iostream> using namespace std; void beans(int y, int& n, int size); void spam(int& n, int& y); int main(){ int m = 7; int n = 4; cout<<"m is "<<m<<" n is "<<n<<endl; beans(n, m, 3); cout<<"m is "<<m<<" n is "<<n<<endl; spam(m, n); cout<<"m is "<<m<<" n is "<<n<<endl; beans(m, 2, n); cout<<"m is...
Can someone explain to me the program step by step next to each statement in the...
Can someone explain to me the program step by step next to each statement in the program by using comment \\ and do the program using the basic c++ cuz down program looked messy advance? a. Request a five-letter string value from the console. b. If the input string is not a five-letter word, print that the word is not a five-letter word. c. If the input string is a five-letter word,determine if the word is or is not a...
Please walk me through SPSS to answer this question, NOT just answer it but please show...
Please walk me through SPSS to answer this question, NOT just answer it but please show me how you did it on SPSS... Consider the data below of inches of rainfall per month for two different regions in the Northwestern United States:    Plains Mountains April 25.2 13.0 May 17.1 18.1 June 18.9 15.7 July 17.3 11.3 August 16.5 14.0 Using SPSS, perform a two-sample t-test for the hypothesis that there is not the same amount of rainfall in both...
4. Please walk me through this problem. Step by step thoroughly. Also explain the equations used....
4. Please walk me through this problem. Step by step thoroughly. Also explain the equations used. also an explanation of how you came to the answer. Thanks i will love you if you do this. You have been asked by your boss to evaluate three mutually exclusive projects. The cash flow estimates and costs of each project are given below: T=0 1 2 3 4 5 6 7 Project A -3790 200 600 300 1000 2800 Project B -3790 1000...
Can someone please explain the edgeworth box to me by typing in a way i can...
Can someone please explain the edgeworth box to me by typing in a way i can see and understand? what determines the contract curves path?
Please walk me through SPSS setup for this and complete the following, NOT just answer it,...
Please walk me through SPSS setup for this and complete the following, NOT just answer it, but show me how you did it on SPSS Consider the data below of inches of rainfall per month for three different regions in the Northwestern United States: Please use SPSS and complete the following: Plains Mountains. Forest April 25.2. 13.0 9.7 May 17.1 18.1 16.5 June 18.9. 15.7. 18.1 July 17.3 11.3 13.0 August 16.5 14.0 15.4 Using SPSS, perform an ANOVA test...
Hello can someone please explain the is lm curves step by step for me?
Hello can someone please explain the is lm curves step by step for me?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT