Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ need typed code 230 Hands-on Exercise #8 Chapter 8 LAB 8.1 Working with Linear Search Bring in program linear_search.cpp from the Lab 8 folder.

C++ need typed code
230
Hands-on Exercise #8 Chapter 8
LAB 8.1 Working with Linear Search
Bring in program linear_search.cpp from the Lab 8 folder. The code is the following:
______________________________________________________________________________
// This program performs a linear search on a character array
// Place Your Name Here
#include
using namespace std;
int searchList( char[], int, char); // function prototype
const int SIZE = 8;
int main()
{
char word[SIZE] = "Harpoon";
int found;
char ch;
cout
cin >> ch;
found = searchList(word, SIZE, ch);
if (found == -1)
cout
else
cout
return 0;
}
//*******************************************************************
// searchList
//
// task: This searches an array for a particular value
// data in: List of values in an array, the number of
// elements in the array, and the value searched for
// in the array
// data returned: Position in the array of the value or -1 if value
// not found
//
//*******************************************************************
int searchList( char List[], int numElems, char value)
{
for (int count = 0;count
{
if (List[count] == value)
// each array entry is checked to see if it contains
// the desired value.
return count;
// if the desired value is found, the array subscript
// count is returned to indicate the location in the array
}
return -1; // if the value is not found, -1 is returned
}
_____________________________________________________________________________
Exercise 3: Modify your program from Exercise 1 so that it reads the information from the gradfile.txt file, reading until the end of file is encountered. You will need to first retrieve this file from the Lab 7 folder and place it in the same folder as your C++ source code. Run the program.
Sample Run:
image text in transcribed
C:\Users\elee\Desktop\CPSC230\Debug CPSC230.exe The grades read in from the file are:90 The grades read in from the file are:45 The grades read in from the file are:23 The grades read in from the file are:21 The grades read in from the file are:62 Enter a Number to search for: Or Enter -99999 to Exit 62 The Number 62 is in the 5 position of the list Enter a Number to search for: Or Enter -99999 to Exit 21 The Number 21 is in the 4 position of the list Enter a Number to search for: Or Enter -99999 to Exit 90 The Number 90 is in the 1 position of the list Enter a Number to search for: Or Enter -99999 to Exit 44 The Number 44 was not found in the list Enter a Number to search for: Or Enter -99999 to Exit -9999 The Number -9999 was not found in the list Enter a Number to search for: Or Enter -99999 to Exit

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions