Related questions
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;
}
Step by stepSolved in 2 steps with 2 images
- Please solve this computer science problem.arrow_forwardObjective: Write a Java program practicing the use of arrays in addition to the other programming practices you have learned, such as program decomposition and the use of Java class (static) methods. Monolithic solutions that do not exhibit good design practices and appropriate class methods will not receive full credit. Use arrays for this. Do not use ArrayLists. Material Provided: You will need the following file to complete this lab: info.txt (A sample input file, which is available on Carmen.) Set up You will need to create your own implementation of the Student class. It will look much like the Student class we saw in the class PowerPoint slides. You may take some shortcuts though. Knowing that the data will always be sets of four lines of text which contain a student name and three scores, you can get away with a constructor that takes the name and three scores and creates the instance of the Student object. (You will still need to get the data out of it though,...arrow_forwardYou have been hired by the SFPD fraud unit to help detect credit card fraud. They have given you a list of 20 stolen credit card numbers, and want you to write a program that can detect if someone is attempting to use one of these credit card numbers at the local Target store.Your program should first read in a list of credit card numbers from a file into an array, and ask the user for a credit card number they would like to use. Then, search the array of credit card numbers to see if the credit card number is in the list. To simplify, we will use a 6 digit credit card number, e.g. 424238. Your list of stolen credit card numbers must be stored in an array of 20 ints. You can get a list from my website and read it in to initialize your array, it is sorted from lowest to highest card number. To get the list into your hills directory, you can use the wget command from the hills prompt: wget http://fog.ccsf.edu/~mluttrel/cs110b/cards.txt After running this command from the hills...arrow_forward
- write in jvaarrow_forwardOkay, in my assignment I am not allowed to use array in the program. How do I replace what I have without the array?arrow_forwardJava Program - Functions with 2D Arrays Write a function named displayElements that takes a two-dimensional array, the size of its rows and columns, then prints every element of a two-dimensional array. Separate every row by a new line and every column by a space. In the main function, write a program that asks for integer input to be assigned on a 3 x 3 array and call the function displayElements to print the contents on the next line. Input 1. Multiple lines containing integer each line Output R1C1: 1 R1C2: 2 R1C3: 3 R2C1: 4 R2C2: 5 R2C3: 6 R3C1: 7 R3C2: 8 R3C3: 9 1 2 3 4 5 6 7 8 9arrow_forward
- Hello! I need some help with my Java homework. Please use Eclipse Please add comments to the to program so I can understand what the code is doing and learn Create a new Eclipse project named so as to include your name (eg smith15 or jones15). In this project, create a new package with the same name as the project. In this package, write a solution to the exercise noted below. Implement the following method that returns the maximum element in an array: public static <E extends Comparable<E>> E max(E[] list) Write a test program that generates 10 random integers, invokes this method to find the max, and then displays the random integers sorted smallest to largest and then prints the value returned from the method. Max sure the the last sorted and returned value as the same!arrow_forwardIn this assignment, you will decide how to keep the inventory in the text file. Then your program must read the inventory from the file into the array. Each product must have a record in the file with the name, regular price, and type. There are several options for storing records in the file. For example, • each value takes one line in the file (i.e., three lines for one product). Then you must take care of correct handling of the ends of the lines; • all values are in one line that can be read as a string. Then you must handle the parsing of the string; • all values are in one line separated by a delimiter. Then you must handle a line with delimiters. Assume that the inventory does not have more than 100 products. But the actual number is known only after the reading of the file. Once you can read data from the file into the array, you must add a new property to the product class – a static variable that holds the number of products in the inventory. Its value must grow as reading...arrow_forwardIs there anything special about an array that makes it so useful?arrow_forward
- Text book imageDatabase System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationText book imageStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONText book imageDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- Text book imageC How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONText book imageDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningText book imageProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education