Question: Lab 21 Due Date: See Blackboard Source File: /2336/21/1ab21.cpp Input: Output: Value: under control of main function under control of main function Write a recursive

 Lab 21 Due Date: See Blackboard Source File: /2336/21/1ab21.cpp Input: Output:Value: under control of main function under control of main function Writea recursive function template whose prototype is given by : template typename

Lab 21 Due Date: See Blackboard Source File: /2336/21/1ab21.cpp Input: Output: Value: under control of main function under control of main function Write a recursive function template whose prototype is given by : template typename T> const T *lnearSearch(const T *array, int n, tenToFind); The function performs a linear search of the range [array, arrayn) for itemToFind. The function returns the smallest address i in the range [array, array + n) such that iitemToFind. The function returns nullptr if no such address exists. A main function for testing your function is shown in Figure 1 The expected output from executing this code is shown in Figure 2. To use the Makefile as distributed in class, add a target of lab21main to targets1srcfile #include #include 4 using namespace std; Ifunction template prototype 7 template 8 const T linearSearch(const T array, int n, T itemToFind); 10 #include "lab21.cpp 12 template 1s void printArray(const T array, int count) 1sif (count > 0) cout as void printAndSearch(const T *array, int n, T itemToFind, string nameOfArray) 2const T ptr; 29cout "Lexus" "d"); 57 printAndSearch(d, dCount, static_cast"Mercedes", "d") 59 return 0; Figure 1. /usr/local/2336/src/lab21main.c (Part 2 of 2) 1 newuser@csunix > cd 2336 2 newuser@csunix /2336 ./getlab.ksh 2:1 3 * Checking to see if a folder exists for Lab 21 . . . No 4*Creating a folder for Lab 21 Checking to see if Lab 21 has sample input and output files. . .Yes and output files for Lab 21 from folder /usr/local/2336/data/21 to folder /21 Checking to see if /usr/local/2336/src/lab21main.C exists. . .Yes aCopying file /usr/local/2336/src/1ab21main.C to folder ./21 0Checking to see if /usr/local/2336/include/1ab21.h exists. . No 41Copying file /usr/local/2336/src/Makefile to folder /21 12Adding a target of lab21main to targetsisrcfile 13Touching file ./21/1ab21.cpp Edit file ./21/1ab21.cpp in Notepad++ s newuser@csunix /2336> cd 21 newuser@csunix "/2336/21> 1s 1 01.out 1 newuser@csunix /2336/21> make lab21main 9 gt+ -g -Wall-std-c++11-c lab21main.C -I/usr/local/2336/include -I 20 g+t-o lab21main lab21main.o -L/usr/local/2336/lib -1m-1bits Makefile lab21.cpp lab21main.C Figure 2. Commands to Compile, Link, & Run Lab 21 (Part 1 of 2) Lab 21 Due Date: See Blackboard nevuser@csunix /2336/21> /lab21main 22 Array a contains: 23 5 5 5 5 5 24 5 is in array a and is located at index 0 26 Array a contains: 2 5 5 5 5 5 28 2 is not in array a Array b contains: 31 7.7 6.6 5.5 4.4 3.3 2.2 1.1 32 1.1 is in array b and is located at index 6 Array b contains 35 7.7 6.6 5.5 4.4 3.3 2.2 1.1 36 11.11 is not in array b s8 Array c contains: 3 r a ce c a 4 e is in array c and is located at index 3 42 Array c contains: 43 r a ce c a 44 E is not in array c Array d contains: 47 Cadillac Oldsmobile Chevrolet Toyota Lexus Dodge GMC BMW BMW GMC Dodge Lexus 48 Lexus is in array d and is located at index 4 s Array d contains: 51 Cadillac Oldsmobile Chevrolet Toyota Lexus Dodge GMC BMW BMW GMC Dodge Lexus 52 Mercedes is not in array d 4 newuser csunix /2336/21> ./lab21main > my.out ss newuser@csunix /2336/21> diff 01.out my.out 56 newuserQcsunix /2336/21> Figure 2. Commands to Compile, Link, & Run Lab 21 (Part 2 of 2)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!