Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ PROGRAM: Create the function: int lookup(const string a[], int n, string target); the functions you must write take 3 parameters. an array of strings

C++ PROGRAM:

Create the function: int lookup(const string a[], int n, string target);

the functions you must write take 3 parameters. an array of strings a[] , and the number of items the function will consider in the array n, starting from the beginning. And the third one is target which you will return the position of a string in the array that is equal to target; if there is more than one such string, return the smallest position number of such a matching string. Return 1 if there is no such string or if n is negative. whenever this specification talks about strings being equal or about one string being less than or greater than another, the case of letters matters. This means that you can simply use comparison operators like == or < to compare strings. Because of the character collating sequence, all upper case letters come before all lower case letters, so don't be surprised. The FAQ has a note about string comparisons. .As noted, case matters: Do not consider "SUe" to be equal to "sUE". when we say "the array", we mean the n elements that the function is aware of. The one error your function implementations doesn't have to handle is when the caller of the function lies and says the array is bigger than it really is. Your program must not use any function templates from the algorithms portion of the Standard C++ library. examples:

string h[7] = { "selina", "reed", "diana", "tony", "", "logan", "peter" }; assert(lookup(h, 7, "logan") == 5); assert(lookup(h, 7, "diana") == 2); assert(lookup(h, 2, "diana") == -1); 
2 more examples: string people[5] = { "clark", "peter", "diana", "tony", "selina" }; int i = lookup(people, 3, "selina"); // should return -1 (not found) 
string people[5] = { "clark", "peter", "diana", "tony", "selina" }; int i = lookup(people, -7, "selina"); // should return -1 

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_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

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

Get Started

Recommended Textbook for

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

3. Job rotation is used for all levels and types of employees.

Answered: 1 week ago