
Concept explainers
09 randArray Part 4
DESCRIPTION
- Get a value from the user and using a loop, search for the value in the array.
- Report all the index locations where it is found
- Report if it is not found anywhere
#include <iostream>
using namespace std;
#include <cstdlib>
int main()
{
srand(17);
const int ARRAYSIZE = 20;
int RandArray[ARRAYSIZE];
int i;
for (i = 0; i < ARRAYSIZE; i++)
RandArray[i] = rand() % 100;
for (i = 0; i < ARRAYSIZE; i++)
cout <<"randArray["<< i <<"]=" << RandArray[i] << endl;
int smallestFoundSoFar=90;
int indexOfSmallest = -1;
int largestFoundSoFar=-1;
int indexOfLargest = -1;
for (i = 0; i < ARRAYSIZE; i++)
{
if (RandArray[i] > largestFoundSoFar)
{
largestFoundSoFar=RandArray[i];
indexOfLargest = i;
}
}
cout << "\nlargestFoundSoFar=" << largestFoundSoFar << " at index " << indexOfLargest;
for (i = 0; i < ARRAYSIZE; i++)
{
if (RandArray[i] < smallestFoundSoFar)
{
smallestFoundSoFar=RandArray[i];
indexOfSmallest = i;
}
}
cout << "\nsmallestFoundSoFar=" << smallestFoundSoFar<< " at index " << indexOfSmallest;
return 0;
}

Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

- Javaarrow_forwardARRAY RANDOMIZER Create a program that shuffels all the elements present in an array. To shuffle an array, you need to do at least 500 random swaps of any elements in the array given below. Print the shuffled array in the output. {12, 54, 22, 100, -3, 5, 10, -33, 78, 90, 29, -45, 77, -9, 19, 21} Language: CPParrow_forwardIn visual basic Print out the last value in a single-dimensional array.arrow_forward
- Poker A poker hand can be stored in a two-dimensional array. The statement int hand[4][13]; declares an array with 52 elements, where the first subscript ranges over the four suits and the second subscript ranges over the thirteen ranks. A poker hand is specified by placing 1's in the elements corresponding to the cards in the hand. See Figure 1. Figure 1 A 2 3 4 5 6 7 8 9 10 J Q K Club 1 Diamond Heart ♥ 1 Spade a 0|0 1 1, 1,arrow_forward1- Arrays can be created to store values of multiple data types at one place. True False 2- To copy the contents of one array to another you must copy the individual array elements. True Falsearrow_forwardC PROGRAMMING LANGUAGEarrow_forward
- 10. Lottery Application Write a Lottery class that simulates a lottery. The class should have an array of five integers named lotteryNumbers. The constructor should use the Random class (from the Java API) to generate a random number in the range of 0 through 9 for each element in the array. The class should also have a method that accepts an array of five integers that represent a per- son's lottery picks. The method is to compare the corresponding elements in the two arrays and return the number of digits that match. For example, the following shows the lotteryNumbers array and the user's array with sample numbers stored in each. There are two matching digits (elements 2 and 4). lotteryNumbers array: User's array: 7 4 4 2 1 3 7 3 In addition, the class should have a method that returns a copy of the lotteryNumbers array. Demonstrate the class in a program that asks the user to enter five numbers. The program should display the number of digits that match the randomly generated…arrow_forwardComputer sciencearrow_forwardCorrect errorsarrow_forward
- Visual basic 6.0arrow_forwardQuestion Write the code needed to create, instantiate and populate an array. You may select the datatype.arrow_forwardProgramming: Multi-Array Assignment Instructions Overview Using a two-dimensional array, you will create the game battleship using a text file that contains the board. The user will enter coordinates to try and find ships and sink them. Instructions Imagine you are using a two-dimensional array as the basis for creating the game battleship. In the game of battleship, a `~' character entry in the array represents ocean (i.e., not a ship), a `#' character represents a place in the ocean where part of a ship is present, and a `H' character represents a place in the ocean where part of a ship is present and has been hit by a torpedo. Thus, a ship with all `H' characters means the ship has been sunk. Declare a two-dimensional array that is 25 x 25 that represents the entire ocean and an If statement that prints "HIT" if a torpedo hits a ship given the coordinates X and Y. Create a text file of 25 line. Each line has 25 characters. ~ represents water and # represents part of…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





