Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

Question
100%

C++

  • 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

This is part 4 of an ongoing assignment RandArray which consisted of assigning 20 integers with a random value. I am not sure how to write this out so it matches the output ( in the attached pictures ).

I have attached the starter code to this problem as well as my code for part 3 which was correct. Thank you

( STARTER CODE )

#include <iostream>
using namespace std;

#include <cstdlib> // required for rand()

int main()
{
// Put Part3 code here

//Part 4
// ask

cout << "Enter value to find: ";

// look through the array.
// If it is found:

// print
// Found 55 at index 12

// if it is not found after looking at all the elements,
// print

// 0 is not found in randArray

}

_______________________________________________________________________

( PART 3 CODE )

#include <iostream>

using namespace std;


#include <cstdlib>

int main()

{

srand(17);

const int ARRAYSIZE = 20;

int RandArray[ARRAYSIZE]; // declaring

int i;

// store random number in array

for (i = 0; i < ARRAYSIZE; i++)

RandArray[i] = rand() % 100;

// print the array

for (i = 0; i < ARRAYSIZE; i++)

cout <<"randArray["<< i <<"]=" << RandArray[i] << endl;

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 ;;


int smallestFoundSoFar=90;

int indexOfSmallest = -1;

for (i = 0; i < ARRAYSIZE; i++)

{

if (RandArray[i] < smallestFoundSoFar)

{

smallestFoundSoFar=RandArray[i];

indexOfSmallest = i;

}

}

cout << "\nsmallestFoundSoFar=" << smallestFoundSoFar<< " at index " << indexOfSmallest << endl;

return 0;

}

Transcribed Image Text:10 randArray[9]=27 11 randArray[10]=1 12 randArray[11]=65 13 randArray[12]=79 14 randArray [13]=76 15 randArray[14]=82 16 randArray[15]=78 17 randArray[16]=8 18 randArray [17]=77 19 randArray[18]=82 20 randArray[19]=23 21 largestFoundSoFar=82 at index 14 22 smallestFoundSoFar=1 at index 10 23 Enter value to find: Found 65 at index 0 24 Found 65 at index 11 25
Transcribed Image Text:THE CORRECT OUTPUT OF THE TEST CASE 1 randArray[0]=65 2 randArray[1]=57 3 randArray[2]=39 4 randArray[3]=47 5 randArray[4]=79 6 randArray[5]=59 7 randArray [6]=45 8 randArray[7]=11 9 randArray[8]=53 10 randArray[9]=27 11 randArray[10]=1 12 randArray[11]=65 13 randArray[12]=79 14 randArray [13]=76 15 randArray[14]=82 16 randArray[15]=78
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
    SEE MORE QUESTIONS
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education