need help to complet this program: Purpose : This program demonstrates the use o
ID: 3617957 • Letter: N
Question
need help to complet this program: Purpose : This program demonstrates the use of one-dimensionalarrays. An array of scores is read, and
the index of the searched scores is printed.
******************************************************************************/
#include <iostream>
#include <fstream>
#include <stdlib.h> //for the exit() function
using namespace std;
//function prototypes
void ReadInScores (int scores[], int & howMany);
int LinearSearch(int scores[], int howMany, int scoreToFind);
int main()
{
//varible declaration
const int MAX_SCORES = 30; //the array has at most 30 entries
int scores [MAX_SCORES]; //an array of test scores with 30 entries
int howMany; //the actual size of the array
int scoreToSearch; //score to find in array
float searchIndex; //index of the searched score in array
//activate the function to read the scores
ReadInScores(scores, howMany);
cout<<"Number to search ";
cin>>scoreToSearch;
//Place your activation statement for LinearSearch() here
//This function is passed an array of scores,the number of scores
//and the number to search. It returns the index where the value was found.
//It returns -1 if the value was not found.
Place youractivation statement for LinearSearch() heresearchIndex will be assigned from LinearSearch()It returns -1 if the value was not found.
if (searchIndex == -1)
cout<<scoreToSearch<< " is not found in the array.";
else
cout<<"Value is found at index "<<searchIndex<<endl;
return 0;
}
//Function: ReadInScores()
//This function reads a set of scores from standard input.
//First the number of scores is read, then the scores.
void ReadInScores (int scores[], int& howMany)
{
cin>>howMany;
for (int i=0; i<howMany; i++)
cin>>scores[i];
return;
}
//Place your LinearSearch() function definition here
//Function: LinearSearch()
//This function is passed an array of scores,the number of scores
//and the number to search. It returns the index where the value was found.
//It returns -1 if the value was not found.
Place yourLinearSearch() function definition hereFunction: LinearSearch()This function is passed an array of scores,the number of scoresand the number to search. It returns the index where the value wasfound.It returns -1 if the value was not found.
need help to complet this program: Purpose : This program demonstrates the use of one-dimensional
arrays. An array of scores is read, and
the index of the searched scores is printed.
******************************************************************************/
#include <iostream>
#include <fstream>
#include <stdlib.h> //for the exit() function
using namespace std;
//function prototypes
void ReadInScores (int scores[], int & howMany);
int LinearSearch(int scores[], int howMany, int scoreToFind);
int main()
{
//varible declaration
const int MAX_SCORES = 30; //the array has at most 30 entries
int scores [MAX_SCORES]; //an array of test scores with 30 entries
int howMany; //the actual size of the array
int scoreToSearch; //score to find in array
float searchIndex; //index of the searched score in array
//activate the function to read the scores
ReadInScores(scores, howMany);
cout<<"Number to search ";
cin>>scoreToSearch;
//Place your activation statement for LinearSearch() here
//This function is passed an array of scores,the number of scores
//and the number to search. It returns the index where the value was found.
//It returns -1 if the value was not found.
Place youractivation statement for LinearSearch() heresearchIndex will be assigned from LinearSearch()It returns -1 if the value was not found.
if (searchIndex == -1)
cout<<scoreToSearch<< " is not found in the array.";
else
cout<<"Value is found at index "<<searchIndex<<endl;
return 0;
}
//Function: ReadInScores()
//This function reads a set of scores from standard input.
//First the number of scores is read, then the scores.
void ReadInScores (int scores[], int& howMany)
{
cin>>howMany;
for (int i=0; i<howMany; i++)
cin>>scores[i];
return;
}
//Place your LinearSearch() function definition here
//Function: LinearSearch()
//This function is passed an array of scores,the number of scores
//and the number to search. It returns the index where the value was found.
//It returns -1 if the value was not found.
Place yourLinearSearch() function definition hereFunction: LinearSearch()This function is passed an array of scores,the number of scoresand the number to search. It returns the index where the value wasfound.It returns -1 if the value was not found.