Problem Solving with C++ (10th Edition)
10th Edition
ISBN: 9780134448282
Author: Walter Savitch, Kenrick Mock
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 7.4, Problem 20STE
Program Plan Intro
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;
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
You are given an array-like data structure Listy which lacks a size method. 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.
Write code with explanation
implement this function: chunk(array, size)
? Do not mutate the input array! ?
Parameters
array - Any JavaScript Array
size - A positive integer Number indicating the desired "chunk" size.
Return Value
A new Array of Arrays. Each sub-Array has a length equal to size. Remaining elements are gathered into a final sub-Array.
Do not use Array.prototype.slice in your implementation.Do not use Array.prototype.shift in your implementation.Do not use Array.prototype.pop in your implementation.Do not use Array.prototype.splice in your implementation.
Examples
chunk(['foo', 'bar', 'baz', 'qux'], 2); // -> [["foo", "bar"], ["baz", "qux"]] chunk([1, 2, 3, 4, 5], 1); // -> [[1], [2], [3], [4], [5]]chunk([false, true, false, true], 3); // -> [[false, true, false], [true]]chunk([], 7); // -> []
Objective: To write a program to remove duplicates from an array entered via the command line.
Please write a program to remove duplicates from the series of numbers specified on the command line. So your program should output just the distinct numbers that were on the command line. Sample output is below:
MUST BE ABLE TO INPUT NUMBERS VIA COMMAND LINE
> java -classpath .:/run_dir/junit-4.12.jar:target/dependency/* Main usage: java Main 5 4 2 4 8
To remove duplicates from the numbers 5, 4, 2, 4 and 8
> java Main 5 4 2 4 8
Here are the distinct numbers: 5, 4, 2, 8
> java Main 1 3 5 2 3 5 3 3 5 7 9 3
Here are the distinct numbers: 1, 3, 5, 2, 7, 9
Chapter 7 Solutions
Problem Solving with C++ (10th Edition)
Ch. 7.1 - Prob. 1STECh. 7.1 - In the array declaration double score(5); state...Ch. 7.1 - Identity any errors in the following array...Ch. 7.1 - What is the output of the following code? char...Ch. 7.1 - What is the output of the following code? double a...Ch. 7.1 - What is the output of the following code? int i,...Ch. 7.1 - Prob. 7STECh. 7.1 - Suppose we expect the elements of the array a to...Ch. 7.1 - Prob. 9STECh. 7.1 - Suppose you have the following array declaration...
Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Prob. 12STECh. 7.2 - Write a function definition for a function called...Ch. 7.2 - Consider the following function definition: void...Ch. 7.2 - Insert const before any of the following array...Ch. 7.2 - Write a function named outOfOrder that takes as...Ch. 7.3 - Write a program that will read up to ten...Ch. 7.3 - Write a program that will read up to ten letters...Ch. 7.3 - Following is the declaration for an alternative...Ch. 7.4 - Prob. 20STECh. 7.4 - Write code that will fill the array a (declared...Ch. 7.4 - Prob. 22STECh. 7 - Write a function named firstLast2 that takes as...Ch. 7 - Write a function named countNum2s that takes as...Ch. 7 - Write a function named swapFrontBack that takes as...Ch. 7 - The following code creates a small phone book. An...Ch. 7 - There are three versions of this project. Version...Ch. 7 - Hexadecimal numerals are integers written in base...Ch. 7 - Solution to Programming Project 7.3 Write a...Ch. 7 - Prob. 4PPCh. 7 - Write a program that reads in a list of integers...Ch. 7 - Prob. 6PPCh. 7 - An array can be used to store large integers one...Ch. 7 - Write a program that will read a line of text and...Ch. 7 - Write a program to score five-card poker hands...Ch. 7 - Write a program that will allow two users to play...Ch. 7 - Write a program to assign passengers seats in an...Ch. 7 - Prob. 12PPCh. 7 - The mathematician John Horton Conway invented the...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - Redo (or do for the first time) Programming...Ch. 7 - A common memory matching game played by young...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Your swim school has two swimming instructors,...Ch. 7 - Prob. 19PPCh. 7 - The Social Security Administration maintains an...
Knowledge Booster
Similar questions
- 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
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- 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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education