Function that returns the maximum value of the array

Assignment Help C/C++ Programming
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);

Reference no: EM13939623

Questions Cloud

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..

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program that computes and prints the 1000th prime number

You will need some variables to keep track of which prime number you're on and keep track of where you are in your loop.

  Programing in c data validity

write a main function to input 20 integers in the range of 1 to 6. write a function count the number of times the numbers 2 and 5 occur. the function should declare static variables count2 and count5. check the data validity in the main functi..

  Program that prints the statement

Write a program that prints the statement "Learning new topics is Fun!" in a function called writeThoughts that is called by the main function.

  Requirements of flyhigh airlines

The development team of SoftSols Inc. has revamped the software according to the requirements of FlyHigh Airlines and is in the process of testing the software. While testing the software, the team encounters the following issues:

  Which manufactures electrical switches

Jake Company, which manufactures electrical switches, uses a standard cost system and carries all inventories at standard. The standard manufacturing overhead costs per switch are based on direct labor hours and are shown below:Variable overhead (5 h..

  Savingsaccount objects and two checkingaccount objects

Develop a polymorphic banking application using the Account hierarchy you created. Create the following two SavingsAccount objects and two CheckingAccount objects and store them in an array called "arrays" of Account references to the objects

  Local diner that allows customers to see the diner''s menu

Design a program to be used for a small local diner that allows customers to see the diner's menu and then make their meal selections using the program.The program will also calculate and print an itemized bill.

  Program that print out the contents of the file

Write a program that will prompt for a file name to open for writing. Prompt the user for 5 lines of text, writing each to the file. When finished, print out the contents of the file.

  Program that declares three variables minnum

Write a C++ program that declares three variables minNum, midNum and maxNum to receive three integers read from the keyboard.

  Compare and contrast the mode operators ios

Compare and contrast the mode operators ios::in, ios::app, and ios::out. Provide a C++ code segment that illustrates the use of these mode operators.

  Add a sentinel command to stop the loop

add a sentinel command to stop the loop. When the program is compiled, It'll ask the user to type in a palindrome. I want the user to type EXIT to end the loop.

  Using array subscript notation

Using array subscript notation, base/offset notation with the array name as the pointer, array notation with  vPtr , and pointer/offset notation with  vPtr , add 3 to the value in the 3 rd element and display that number. (Do not modify the value in ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd