Question

Write a main program that will randomly fill a 2 dimensional array with integer values in...

Write a main program that will randomly fill a 2 dimensional array with integer values in the range of 0 to 50. Use the Rand_Int function and constants to do this. These values represent the height of a terrain. Write a function that will determine what part of the terrain will flood.

A. Create a global constant called MAX and assign it the value of 10.

B. Prompt the user in main, at what height do they consider it to flood.

C. The function prototype is: void Map_Flood(int h[MAX][MAX], int level);

D. The function Map_Flood will output a terrain map that has an * to represent flooding and a space for no flooding.

E. An example of the map is this:
* * * * * * * *

* * * * * * * * * * * * * ** *

* * * * * * * * * * *

*    * * * * * * * * *

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program:

#include <iostream>

using namespace std;
const int MAX = 10;

void Map_Flood(int h[MAX][MAX], int level);

int main()
{
int terrian[MAX][MAX];
int height;
  
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
terrian[i][j] = rand() % 50 + 0;
}
}
  
cout<<"At what height do you consider it will flood: ";
cin>>height;
  
Map_Flood(terrian,height);
  

return 0;
}

void Map_Flood(int h[MAX][MAX], int level)
{
for(int i=0;i<MAX;i++)
{
for(int j=0;j<MAX;j++)
{
if(h[i][j]==level)
{
cout<<"*";
}
else
{
cout<<"";
}
}
cout<<endl;
}   
}

Output:

Add a comment
Know the answer?
Add Answer to:
Write a main program that will randomly fill a 2 dimensional array with integer values in...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a C++ program to scale and average the values in a two-dimensional array. Write the...

    Write a C++ program to scale and average the values in a two-dimensional array. Write the following functions:           void randomize2DArray(int arr[ROW_SIZE][COL_SIZE]) – places random values between 1 and 100 in a two-dimensional array .           void scale2DArray(int arr[ROW_SIZE][COL_SIZE], double scale) – multiplies every value in the two-dimensional array by scale.           double average2DArray(int arr[ROW_SIZE][COL_SIZE]) – calculates the average value over all elements in the two-dimensional array. Randomize and print the values in the two-dimensional array of size 7 x...

  • Create a C program that: Within main, declares a linear array consisting of 10 double values....

    Create a C program that: Within main, declares a linear array consisting of 10 double values. You can assign values to the array when it is declared or fill them items manually using scanf () - your choice. Also, declare three doubles: min, max, and average. Then from within main, a function is called. The function should take a pointer to the array declared above and then finds the maximum value, the minimum value, and calculates the average of the...

  • Write a C++ console application that adds the corresponding elements of two integer arrays of size...

    Write a C++ console application that adds the corresponding elements of two integer arrays of size five. Prompt the user for the ten values and store the first five in the first array and the second five in the second array. Then create and call function matrixAdd that adds the two arrays and prints the five sums. Here is the function prototype: void matrixAdd(int firstArr[], int secondArr[]); [your program code here]*

  • Write a java Program Initialize Array. Write a Java method initArray() with the following header to...

    Write a java Program Initialize Array. Write a Java method initArray() with the following header to initialize a one-dimensional array a such that the element values (integers) are twice the index value. For example, if i = 23, then a23 = 46. The function is void with one parameter -- the integer array of a[]. Then write a main() with an int[] array2i size 100 to call

  • Create a program that creates an array of 500 random numbers between -10 and 10. Write...

    Create a program that creates an array of 500 random numbers between -10 and 10. Write several functions: Function 1 - prints the array with a certain number of elements per line. Prototype: void printArray(int array[], int numElements, int numPerLine, ostream &os) Function 2 prints only the array elements that are evenly divisible by an input number. Prototype: void printDivBy(int array[], int numElements, int numPerLine, int divBy, ostream &os) Function 3 takes the input array and returns the maximum, the...

  • Write a Java program to find the duplicate values of an array of integer values. import...

    Write a Java program to find the duplicate values of an array of integer values. import java.util.Arrays; public class ex7DuplicateValue { public static void main(String[] args) { int[] my_array = {1, 2, 3, 3, 4, 5, 6, 2}; } } //Duplicate Element : 2 //Duplicate Element : 3

  • Two-dimensional arrays and functions Write the code CIS22A-HW7-XXXXX.cpp to create and print a 12 x 12...

    Two-dimensional arrays and functions Write the code CIS22A-HW7-XXXXX.cpp to create and print a 12 x 12 multiplication table using a 2-dimensional array and functions with nested loops. Define the following Global Constants at the top, before main function: const int ROW_SIZE = 12; const int COL_SIZE = 12; const int WIDTH = 4; Two required functions are: void createTable(int [][COL_SIZE], int rows); void printTable(int [][COL_SIZE], int rows); Use this main code without any change: int main() {         int table[ROW_SIZE]...

  • Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a...

    Create a program named IntegerFacts whose Main() method declares an array of 10 integers. Call a method named FillArray to interactively fill the array with any number of values up to 10 or until a sentinel value (999) is entered. If an entry is not an integer, reprompt the user. Call a second method named Statistics that accepts out parameters for the highest value in the array, lowest value in the array, sum of the values in the array, and...

  • Write a function getScores(...) that is given a string, an int type array to fill and...

    Write a function getScores(...) that is given a string, an int type array to fill and the max number of elements in the array as parameters and returns an integer result. The function will find each substring of the given string separated by space characters and place it in the array. The function returns the number of integers extracted. For example: int values[3]; getScores("123 456 789", values, 3 ); would return the count of 3 and fill the array with...

  • 1. Write a C function named find that receives a one-dimensional array of type integer named...

    1. Write a C function named find that receives a one-dimensional array of type integer named arr and its size of type integer. The function fills the array with values that are the power of four (4^n) where n is the index. After that, the function must select a random index from the array and move the array elements around the element stored in the randomly selected index Example arr = [1, 4, 16, 64, 256) if the randomly selected...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT