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

  Q1 write a menu-driven program that maintains an address

q1. write a menu-driven program that maintains an address book using a linked list. the address book must supports the

  C++ programming uml diagrams

The goal of this lab is to better familiarize you with polymorphism and the factory design pattern, two key components in Assignment

  Program that reads in the average monthly

Write a program that reads in the average monthly rainfall for a city for each month of the year and then reads in the actual monthly rainfall for each of the previous 12 months. The program then prints out a nicely formatted table showing the rainfa..

  After the user presses any key

After the user presses any key, the board will be scrambled by making a large number of random moves (for a 3x3 puzzle, 100,000 attempted random moves in random directions will result in a sufficiently scrambled board)

  Define a relation rf by the rule

Consider three sets A, B, and C, where A has 7 elements, B has 5 elements, and C has 2 elements. How many (ternary) relations are there on the sets A, B, C?

  Write the prototype and header for a function

Write the prototype and header for a function called calculate. The function should have three parameters: an int, a reference to a double, and a long (not necessarily in that order). Only the int parameter should have a default argument, which is..

  Program that stores information for date-time objects

Derive class WeekDay from class DateTime such that WeekDay::display() will display local date time using values from the parameters and the corresponding weekday.

  We have to deal with student pilots

We have to deal with student pilots and airplanes. Students have a unique student id, a name, and a year that students are in. Airplanes have a unique airplane id, model, a cruising range

  Write a program that computes the cost of long distance call

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules.

  Overall use-case diagram considering the scnarios

1. Draw the overall use-case diagram considering the scnarios 2. Draw the Use case brief description - with ore and post conditions

  What is the :: called in c++

What is the :: called in C++ when used like this std::endl; In my main file, what line of code prevents me from having to put std before every endl

  Compute triangle area

Write a program with a form that contains three labels & text boxes (Base, Height & Area) in addition to a button labeled compute Triangle Area. The user must enter the base and height to find the area. (Triangle Area = 0. 5base x Height)

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