} LAB 8.1 Working with the Linear Search Bring in program linear_search.cpp from the Lab 8 folder. This is Sample Program 8.1 from the Pre-lab Reading Assignment. 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 << "Enter a letter to search for:" << endl; cin >> ch; found - searchList (word, SIZE, ch); if (found == -1) else cout << "The letter "<< ch <<"was not found in the list" << endl; cout << "The letter " << ch <<" is in the << found + 1 << "position of the list" << endl; return 0; // . // // task: // data in: // 11 searchList This searches an array for a particular value 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) 1 for (int count = 0; count < numElems; 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
} LAB 8.1 Working with the Linear Search Bring in program linear_search.cpp from the Lab 8 folder. This is Sample Program 8.1 from the Pre-lab Reading Assignment. 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 << "Enter a letter to search for:" << endl; cin >> ch; found - searchList (word, SIZE, ch); if (found == -1) else cout << "The letter "<< ch <<"was not found in the list" << endl; cout << "The letter " << ch <<" is in the << found + 1 << "position of the list" << endl; return 0; // . // // task: // data in: // 11 searchList This searches an array for a particular value 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) 1 for (int count = 0; count < numElems; 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
Introductory Circuit Analysis (13th Edition)
13th Edition
ISBN:9780133923605
Author:Robert L. Boylestad
Publisher:Robert L. Boylestad
Chapter1: Introduction
Section: Chapter Questions
Problem 1P: Visit your local library (at school or home) and describe the extent to which it provides literature...
Related questions
Question
solve this
![}
LAB 8.1 Working with the Linear Search
Bring in program linear_search.cpp from the Lab 8 folder. This is Sample
Program 8.1 from the Pre-lab Reading Assignment. The code is the following
// This program performs a linear search on a character array
// Place Your Name Here
#include <iostream>
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 << "Enter a letter to search for:" << endl;
cin >> ch;
found - searchList (word, SIZE, ch);
if (found == -1)
else
cout << "The letter "<< ch
<<"was not found in the list" << endl;
cout << "The letter " << ch <<" is in the << found + 1
<< "position of the list" << endl;
return 0;
//
.
//
// task:
// data in:
//
11
searchList
This searches an array for a particular value
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)
1
for (int count = 0; count < numElems; 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](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2F966ba16d-db34-4747-8867-9802a3958816%2F982ff906-c91b-4db7-be4f-e4f92e5b5e29%2F6sqsn9_processed.jpeg&w=3840&q=75)
Transcribed Image Text:}
LAB 8.1 Working with the Linear Search
Bring in program linear_search.cpp from the Lab 8 folder. This is Sample
Program 8.1 from the Pre-lab Reading Assignment. The code is the following
// This program performs a linear search on a character array
// Place Your Name Here
#include <iostream>
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 << "Enter a letter to search for:" << endl;
cin >> ch;
found - searchList (word, SIZE, ch);
if (found == -1)
else
cout << "The letter "<< ch
<<"was not found in the list" << endl;
cout << "The letter " << ch <<" is in the << found + 1
<< "position of the list" << endl;
return 0;
//
.
//
// task:
// data in:
//
11
searchList
This searches an array for a particular value
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)
1
for (int count = 0; count < numElems; 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
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 1 steps

Recommended textbooks for you

Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:
9780133923605
Author:
Robert L. Boylestad
Publisher:
PEARSON

Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:
9781337900348
Author:
Stephen L. Herman
Publisher:
Cengage Learning

Programmable Logic Controllers
Electrical Engineering
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education

Introductory Circuit Analysis (13th Edition)
Electrical Engineering
ISBN:
9780133923605
Author:
Robert L. Boylestad
Publisher:
PEARSON

Delmar's Standard Textbook Of Electricity
Electrical Engineering
ISBN:
9781337900348
Author:
Stephen L. Herman
Publisher:
Cengage Learning

Programmable Logic Controllers
Electrical Engineering
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education

Fundamentals of Electric Circuits
Electrical Engineering
ISBN:
9780078028229
Author:
Charles K Alexander, Matthew Sadiku
Publisher:
McGraw-Hill Education

Electric Circuits. (11th Edition)
Electrical Engineering
ISBN:
9780134746968
Author:
James W. Nilsson, Susan Riedel
Publisher:
PEARSON

Engineering Electromagnetics
Electrical Engineering
ISBN:
9780078028151
Author:
Hayt, William H. (william Hart), Jr, BUCK, John A.
Publisher:
Mcgraw-hill Education,