Purpose of given code:
The purpose of given code is to store the values in multidimensional array and print these values.
Given code:
/*Include the appropriate headers*/
#include<iostream>
using namespace std;
//Main method
int main()
{
/*Declaration of variables*/
int myArray[4][4], index1, index2;
/*Loop for rows*/
for (index1 = 0; index1 < 4; index1++)
/*Loop for columns*/
for (index2 = 0; index2 < 4; index2++)
/*Assign the values into array*/
myArray[index1][index2] = index2;
/*Loop for rows*/
for (index1 = 0; index1 < 4; index1++)
{
/*Loop for columns*/
for (index2 = 0; index2 < 4; index2++)
/*Print statement with values*/
cout << myArray[index1][index2] << " ";
//Print statement
cout << endl;
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Problem Solving with C++ Plus MyLab Programming with Pearson eText -- Access Card Package (10th Edition)
- Please fix this JavaScript function so that the when calling the function with the parameters chunk([false, true, false, true], 3); the output is [[false, true, false], [true]] (subarrays)and when the parameters are chunk([undefined, null, 0, false, NaN, ""], 3); the output is [[undefined, null, 0], [false, NaN, ""]]thank you very much! function chunk(ar, sz) { var res = []; var ind = 0; // itterating through the new length of resulting array for (var i = 0; i < ar.length / sz; i++) { var t = []; // iterating through the given size for (var j = 0; j < sz; j++) { // adding elements to new 1D array t[] t.push(ar[ind]); ind++; } // push this new array into res[] res.push(t); } // return the answer return res;}arrow_forwardImplement the function below. void swap(int pos1, int pos2){} Initial code to be completed: class ArrayList : public List { int* array; int index; int capacity; void dyn_all_add(){ int cap = ceil(capacity * 1.5); array = (int*)realloc(array,cap * sizeof(int)); capacity = cap; } void dyn_all_rem(){ int cap = capacity - (capacity/3); array = (int*)realloc(array,cap * sizeof(int)); capacity = cap; } public: // CONSTRUCTOR ArrayList() { capacity = 4; array = (int*)malloc(capacity); index = 0; } int add(int num) { if (index == capacity){ dyn_all_add(); } *(array + index) = num; index++; return index; } int get(int pos){ if (pos-1 < index){ return *(array + pos-1); } return -1; } int size(){ return index; }…arrow_forwardHello The java function belw is generating a NullPointerException. How can I improve it? public int quadraticProbing(String[] hashArray, int initial_index, int collision) { int index = (initial_index + (collisions * collisions)) % maxSize; System.out.println("Index " + index); if (index == maxSize) { System.out.println("flag 04"); index = 0; // To wrap around the table } if (hashArray[index] == null) { return index; // We can insert at this location } else { // The index isn't empty so we need to insert the value // at the end of the list } collisions = ++collision; return quadraticProbing(hashArray, initial_index, collision); // Recursive call } Thanks in advance. Respectfully, Emmanuelarrow_forward
- Suppose that two arraysx1,x2,…,xnandy1,y2,…,yn.( Need only handwritten solution please otherwise downvote).arrow_forwardFor this assignment please use 2 arrays. Write a program DiscreteDistribution.java that will take an integer command-line argument m, followed by a sequence of positive integer command-line arguments a1,a2,…,ana1,a2,…,an, and will print m random indices (separated by whitespace), choosing each index i with probability proportional to ai.arrow_forward: You are given an array-like data structure Listy which lacks a sizemethod. It does, however, have an elementAt ( i) method that returns the element at index i in 0( 1) time. If i is beyond the bounds of the data structure, it returns -1. (For this reason, the data structure only supports positive integers.) Given a Listy which contains sorted, positive integers,find the index at which an element x occurs. If x occurs multiple times, you may return any index.arrow_forward
- In a given statement such as studname=name[5], what array operation is being implemented? Select one: a. initialize b. assign c. all of the choices d. access Evaluate the given expression z-a*b/w+w*y Given a=4, b=6, w=2, y=-5, z=5 Select one: a. none of the choices b. -5 c. 17 d. -7 How many data types are included in numeric category? Select one: a. 7 b. 8 c. 5 d. 2arrow_forwardIn Python, Define and invoke using chain function calls, the myArange() and myReshape() methods in one line of code as shown in the figure below, and use a for loop to place one element at a time from the 1D array into the 2D array. a = myClass() rows = int(input('Enter the number of rows: ')) columns = int(input('Enter the number of columns: ')) arrMain = a.myArange(1,16).myReshape(rows,columns)arrow_forwardI need help with this assignment, I use C++. Write a program to do the following: Use the same input seed data you used for Lab 4 (your BST homework) as seed input data into a hash table. Declare a hash table of size 29 elements. To hash your currency objects into the hash table, use the pseudorandom hash scheme - (m*w + n*f) % size - where size = 29, m = 2, n = 3, w = whole value, f = fractional value. For collision resolution, use quadratic probing in the same direction always. Remember to circle around to the start of the array if needed. Your main will first load the data file into the hash table and print the number of data items loaded, load factor and number of collisions. Then it will ask the user in a loop to enter a Dollar to search for. If the Dollar object is found in the hash table, it will print the index where found, otherwise it will print 'Invalid Data'. Then it will ask the user if they want to check again or end the program. To submit, upload your code files and…arrow_forward
- Need help making a java file that combines both linearSearch and binarySearch •Both search methods must use the Comparable<T> interface and the compareTo() method.•Your program must be able to handle different data types, i.e., use generics.•For binarySearch, if you decide to use a midpoint computation formula that is different fromthe textbook, explain that formula briefly as a comment within your code. //code from textbook //linearSearch public static <T> boolean linearSearch(T[] data, int min, int max, T target) { int index = min; boolean found = false; while (!found && index <= max) { found = data [index].equals(target); index++; } return found; } //binarySearch public static <T extends Comparable<T>> boolean binarySearch(T[] data, int min, int max, T target) { boolean found = false; int midpoint = (min + max)/2; if (data[midpoint].compareTo(target)==0)…arrow_forwardYou are going to implement hashing with chaining with separate chaining. Please implement your hash function accordingly to distribute the data evenly in the array. Fill in the missing code! C only! ASAP!!! THE CODE: #include <stdio.h> // RecordTypestruct RecordType{int id;char name;int order;}; // Fill out this structurestruct HashType{ }; // Compute the hash functionint hash(int x){ } // parses input file to an integer arrayint parseData(char* inputFileName, struct RecordType** ppData){FILE* inFile = fopen(inputFileName, "r");int dataSz = 0;int i, n;char c;struct RecordType *pRecord;*ppData = NULL; if (inFile){fscanf(inFile, "%d\n", &dataSz);*ppData = (struct RecordType*) malloc(sizeof(struct RecordType) * dataSz);// Implement parse data blockif (*ppData == NULL){printf("Cannot allocate memory\n");exit(-1);}for (i = 0; i < dataSz; ++i){pRecord = *ppData + i;fscanf(inFile, "%d ", &n);pRecord->id = n;fscanf(inFile, "%c ", &c);pRecord->name =…arrow_forwardI need help with this assignment, I use C++. Can you also please show the console for the program? Thank you. Write a program to do the following: Use the same input seed data you used for Lab 4 (your BST homework) as seed input data into a hash table. Declare a hash table of size 29 elements. To hash your currency objects into the hash table, use the pseudorandom hash scheme - (m*w + n*f) % size - where size = 29, m = 2, n = 3, w = whole value, f = fractional value. For collision resolution, use quadratic probing in the same direction always. Remember to circle around to the start of the array if needed. Your main will first load the data file into the hash table and print the number of data items loaded, load factor and number of collisions. Then it will ask the user in a loop to enter a Dollar to search for. If the Dollar object is found in the hash table, it will print the index where found, otherwise it will print 'Invalid Data'. Then it will ask the user if they want to check…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