Reference no: EM13939623
Arrays are collections of elements of the same type. The elements of the array can be accessed using their position (index) in the array. Arrays may have several dimensions: they can be similar to lists (1-dimension), matrices (2-dimensions), cubes (3-dimensions) etc.
1. The first exercise involves a 1-dimensional array of integers and uses a function that returns the maximum value of the array. The program is not completely defined, the ?? should be replaced with the corresponding expressions in order to get the program work correctly.
Here is the program
#include <iostream>
using namespace std;
//declares the size of the array as a constant integer
const int SIZE = 10;
//declares the function that computes the maximum value
//the function returns an integer and has an array of integers as parameter
int max(int a[]);
int main()
{
//declares the array of integers having the size SIZE
int arrayone[SIZE];
int max_value;
//initializes each element of the array with the value of its index+1
for(int i=0; i<SIZE; i++)
arrayone[i] = i+1;
//call here the function that returns the maximum value
max_value = ??;
cout <<"The maximum element of the array is "<< max_value <<endl;
return(0);
}
int max(int a[])
{
int maximum;
//compare each element with maximum and assign its value to maximum if //greater
for (int i=??; i<??; i++)
{
if (maximum < a[i])
maximum = a[i];
}
return(maximum);
}
2. The second program declares a bi-dimensional array and uses a function to compute the sum of the elements on the main diagonal (with index [ii]). Again, the program is not completely defined, you have to replace the ?? in order to get a compilable version.
Here is the program:
#include <iostream>
using namespace std;
//declares the size of te array as a constant integer
const int SIZE = 10;
//declares the function that returns the sum of
// the elements on the main diagonal
int sum(int a[SIZE][SIZE]);
int main()
{
//declares the array of integers
int arraytwo[SIZE][SIZE];
int s;
//initializes each element of the array with the sum of its indexes
for(int i=0; i<SIZE; i++)
for(int j = 0; j<SIZE; j++)
arraytwo[i][j] = i+j;
//call here the function that returns the sum of the main diagonal elements
s = ??
cout <<"The sum of the main diagonal elements is "<< s <<endl;
return(0);
}
int sum(int a[SIZE][SIZE])
{
int s=0;
//compute the sum of elements on main diagonal
for (int i=0; i<SIZE; i++)
{
s = ??
}
return(s);
Expected return-market risk premium-reward-to-risk ratios
: Stock Y has a beta of 1.4 and an expected return of 15.1 percent. Stock Z has a beta of .7 and an expected return of 8.6 percent. If the risk-free rate is 5 percent and the market risk premium is 6.5 percent, the reward-to-risk ratios for stocks Y an..
|
Describe the strategic planning process
: Briefly describe the strategic planning process and how you would use this to promote the aims and outcomes of the program.
|
Problem regarding the center-line vaporization
: A string of negligible diameter is drawn down the center-line of a pipe containing a Newtonian fluid. At what velocity, w, must the string be drawn in order to vaporize the fluid? Pose the problem in a general fashion but make whatever reasonable ..
|
How would it affect urine ph and why would this change occur
: While visiting your family, you come down with a severe case of stomach flu. You begin vomiting and continue vomiting for more than a day, unable to keep any food or fluids down. How would you expect your condition to affect your blood pH and why ..
|
Function that returns the maximum value of the array
: Arrays are collections of elements of the same type. The elements of the array can be accessed using their position (index) in the array.
|
Compute the roi for the division without the investment
: Compute the ROI for the division without the investment. Compute the ROI for the division with the new investment. Do you think the division manager will approve the investment?
|
Challenges that health care leaders are faced
: Critically discuss some of the challenges that health care leaders are faced with in terms of decision making within the team environment. Explore this specifically in relation to to the aged care sector and disability health services.
|
What is the expected return of gell stock
: Suppose Blek stock has a beta of 1.7, whereas Gell stock has a beta of 0.96. If the risk free interest rate is 4.2% and the expected return of the market portfolio is 13.4%, according to the CAPM, What is the expected return of Blek stock? What is th..
|
How can she make antiserum specific for rabbit igg
: Suppose a scientist wants to make antiserum specific for IgG. They inject a RABBIT with purified MOUSE IgG and get an antiserum thats reacts with MOUSE IgG and other mouse isotopes. Why did this happen? How can she make antiserum specific for RABB..
|