Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ SearchableVector Modification Modify the SearchableVector class template presented in this chapter so that it performs a binary search instead of a linear search.

In C++

SearchableVector Modification

Modify the SearchableVector class template presented in this chapter so that it performs a binary search instead of a linear search. Test the template in a driver program.

REPORTING FORMAT: Source Code & Testing Results

// This program demonstrates the SearchableVector template. 2 #include 3 #include "SearchableVector.h" 4 using namespace std; 5 6 int main() 7 { 8 const int SIZE = 10; // Number of elements 9 int count; // Loop counter 10 int result; // To hold search results 11 12 // Create two SearchableVector objects. 13 SearchableVector intTable(SIZE); 14 SearchableVector doubleTable(SIZE); 15 16 // Store values in the objects. 17 for (count = 0; count < SIZE; count++) 18 { 19 intTable[count] = (count * 2); 20 doubleTable[count] = (count * 2.14); 21 } 22 (program continues) // Display the values in the objects. 24 cout << "These values are in intTable: "; 25 for (count = 0; count < SIZE; count++) 26 cout << intTable[count] << " "; 27 cout << endl << endl; 28 cout << "These values are in doubleTable: "; 29 for (count = 0; count < SIZE; count++) 30 cout << doubleTable[count] << " "; 31 cout << endl; 32 33 // Search for the value 6 in intTable. 34 cout << " Searching for 6 in intTable. "; 35 result = intTable.findItem(6); 36 if (result == 1) 37 cout << "6 was not found in intTable. "; 38 else 39 cout << "6 was found at subscript " << result << endl; 40 41 // Search for the value 12.84 in doubleTable. 42 cout << " Searching for 12.84 in doubleTable. "; 43 result = doubleTable.findItem(12.84); 44 if (result == 1) 45 cout << "12.84 was not found in doubleTable. "; 46 else 47 cout << "12.84 was found at subscript " << result << endl; 48 return 0; 49 }

Program Output These values are in intTable: 0 2 4 6 8 10 12 14 16 18 These values are in doubleTable: 0 2.14 4.28 6.42 8.56 10.7 12.84 14.98 17.12 19.26 Searching for 6 in intTable. 6 was found at subscript 3 Searching for 12.84 in doubleTable. 12.84 was found at subscript 6

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

Recommended Textbook for

Advanced Database Systems For Integration Of Media And User Environments 98

Authors: Yahiko Kambayashi, Akifumi Makinouchi, Shunsuke Uemura, Katsumi Tanaka, Yoshifumi Masunaga

1st Edition

9810234368, 978-9810234362

More Books

Students also viewed these Databases questions