Concept explainers
Background: This assignment will help you further learn to use multidimensional arrays.
You will need a 10x2 matrix for this problem.
Consider 10 points on a map, You need to identify the distance between each point (or vertex). A vertex requires two pieces of information. An x,y coordinate (think longitude and latitude.) This is why you have a matrix of 10x2, each entry is the two values you will need.
You can think of these points a cities, or friend's houses. We're only looking for a direct route (as the crow flies) not taking roads to make it simpler.
You can find the distance between any two points by use of: sqr_root((x1 - x2)^2 + (y1 - y2)^2)
You will need to fill your matrix with some random values.
Then you will need to calculate the distance between each possible point, eventually displaying it on a matrix in output.
Think something like:
1 2 3 4 5
1 0 8 12 4 6
2 8 0 7 ....
3 12 7 ....
4 4 ...
5 6 ...
Hint: You may want to display the point values somewhere as well.
Hint: There should be a section where each value is 0, as the distance from a point to itself if zero (0)
Trending nowThis is a popular solution!
Step by stepSolved in 4 steps with 3 images
- The WalkingBoard class represents a board with a figure standing on position x,y. Each position also has a value associated with it. Initialise the board in two different ways: either make it size×size or use the given dimensions and initial values. About the second way: The rows may not be uniform: they may have differing numbers of columns in them. Don’t simply take the argument array: create its copy in the field. All values are set to BASE_TILE_SCORE, or to the given value if that’s bigger. Operations. getPosition: returns the values of x and y in an array. getTile: returns the value of the of the board position. Let this condition be checked by the helper method isValidPosition. If it is an invalid position, throw an IllegalArgumentException. getTiles: returns the values of all the board positions. Don’t let the field contents be accessed from the caller: create and return an exact copy of the structure. getXStep and getYStep: helper methods, they indicate how far (-1,…arrow_forwardin java ecplise . Implement a program that randomly generates 10 integers from -100 to 100,stores them in a 1D array, and finds their maximum value. Calculate theexecution time of finding a maximum. Repeat the test for 10,000 and10,000,000 numbers. Provide your results in the form of a table below andprovide a small summary. Implement a Java program that will populate a 5x5 matrix with randomlygenerated integers from 0 to 100.(1) print your matrix in a table form.(2) modify your code to multiply all even numbers by 10 and print the matrix.Your output of questions (1) and (2) should match the format of the followingsample outputs:arrow_forward1. Create a script that will take 4 vertices (total 8 numbers) then make decision whether those vertices form a square, a rectangular, a diamond (A.K.A Rhombus), a parallelogram, or just a quadrilateral. Also, the area of the shapes if the shape is a square or rectangular. [CREATE AN ARRAY FOR 4 VERTICES (TOTAL 8 NUMBERS, THEN REPEAT THE SAME PROCEDURE. The WHOLE COMPUTATION NEEDS TO BE DONE BY ACCESSING ELEMENTS IN THE ARRAY .) Taking values for the ARRAY has to be done within main(). But computation and displaying the result should be done with the USER DEFINED FUNCTION!)arrow_forward
- Create a 2D array of size 14x14 having same values ranging from 0 to 255 in each row. You are free to specify the values of this array. For instance, consider a 3x3 array as;Array [3] [3]= {{12,12,12}, {75, 75, 75}, {247, 247, 247}}12, 75, and 247 pixel values are specified in a way that they are in a range of 0 to 255 and they are same in a row.Write a code namely arraytoimage.c using any pgm (portable gray map) format image that represents an image in a text file in which each pixel is represented by a number ranging from 0 and 255. In this code, write:-P2 (magic number)-Width and height of the image-Maximum grayscale value-Gray scale intensity values you specify in the arrayin an order to this imagearrow_forwarduse the RUSTarrow_forwardAn array is positive dominant if it contains strictly more unique positive values than unique negative values. Write a function that returns true if an array is positive dominant. Examples ispositiveDominant([1, 1, 1, 1, -3, -4]) // There is only 1 unique positive value (1). // There are 2 unique negative values (-3, -4). ispositiveDominant([5, 99, 832, -3, -4]) → true ispositiveDominant([5, 0]) → true ispositive Dominant([0, -4, -1]) → falsearrow_forward
- Code to ::::implement a SnapshotArray that supports the following interface: SnapshotArray(int length) initializes an array-like data structure with the given length. Initially, each element equals 0. void set(index, val) sets the element at the given index to be equal to val. int snap() takes a snapshot of the array and returns the snap_id: the total number of times we called snap() minus 1. int get(index, snap_id) returns the value at the given index, at the time we took the snapshot with the given snap_id Example 1: Input: ["SnapshotArray","set","snap","set","get"] [[3],[0,5],[],[0,6],[0,0]] Output: [null,null,0,null,5] Explanation: SnapshotArray snapshotArr = new SnapshotArray(3); // set the length to be 3 snapshotArr.set(0,5); // Set array[0] = 5 snapshotArr.snap(); // Take a snapshot, return snap_id = 0 snapshotArr.set(0,6); snapshotArr.get(0,0); // Get the value of array[0] with snap_id = 0, return 5...arrow_forwardGiven an array, find the next greater element for each element in the array, ifavailable. If not available, print the element itself. The next greater element y for anelement x in the array is the first element that is greater than x and occurs on its rightside. The next greater element of the right most element in an array is the elementitself.Example: Given A = [ 6 8 4 3 9] the next greater element listB = [8 9 9 9 9].arrow_forwardWrite a program that creates a 3x3 2d array and populate it by user input. It then creates a secondarray of size 3 which stores the sum of each row in the user input matrix.If the matrix is [ [1,1,1], [2,2,2], [3,3,3] ], sums should be [3, 6, 9].The sums are then printed on the screen.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education