Question
// Demetris Leadership Center (DLC) product lookup program // This program allows the user to enter a product number // and then displays the title,
const int NUM_PRODS = 9; // The number of products produced const int MIN_PRODNUM = 914; // The lowest product number const int MAX_PRODNUM = 922; // The highest product number
// Function prototypes int getProdNum(); int binarySearch(const int[], int, int); void displayProd(const string[], const string[], const double[], int);
int main() { // Array of product IDs int id[NUM_PRODS] = { 914, 915, 916, 917, 918, 919, 920, 921, 922 };
// Array of product titles string title[NUM_PRODS] = { \"Six Steps to Leadership\", \"Six Steps to Leadership\", \"The Road to Excellence\", \"Seven Lessons of Quality\", \"Seven Lessons of Quality\", \"Seven Lessons of Quality\", \"Teams Are Made, Not Born\", \"Leadership for the Future\", \"Leadership for the Future\" };
// Array of product descriptions string description[NUM_PRODS] = { \"Book\", \"Audio CD\", \"DVD\", \"Book\", \"Audio CD\", \"DVD\", \"Book\", \"Book\", \"Audio CD\" };
// Array of product prices double prices[NUM_PRODS] = { 12.95, 14.95, 18.95, 16.95, 21.95, 31.95, 14.95, 14.95, 16.95 };
int prodNum; // To hold a product number int index; // To hold search results char again; // To hold a Y or N answer
do { // Get the desired product number. prodNum = getProdNum();
// Search for the product number. index = binarySearch(id, NUM_PRODS, prodNum);
// Display the results of the search. if (index == -1) cout else displayProd(title, description, prices, index);
// Does the user want to do this again? cout cin >> again; } while (again == 'y' || again == 'Y'); return 0; }
//*************************************************** // Definition of getProdNum function * // The getProdNum function asks the user to enter a * // product number. The input is validated, and when * // a valid number is entered, it is returned. * //***************************************************
int getProdNum() { int prodNum; // Product number
cout cin >> prodNum; // Validate input while (prodNum MAX_PRODNUM) { cout cout cin >> prodNum; } return prodNum; }
//*************************************************************** // Definition of binarySearch function * // The binarySearch function performs a binary search on an * // integer array. array, which has a maximum of numElems * // elements, is searched for the number stored in value. If the * // number is found, its array subscript is returned. Otherwise, * // -1 is returned indicating the value was not in the array. * //***************************************************************
int binarySearch(const int array[], int numElems, int value) {
/* YOUR CODE HERE*/ }
//************************************************************ // The displayProd function accepts three arrays and an int. * // The arrays parameters are expected to hold the title, * // description, and prices arrays defined in main. The index * // parameter holds a subscript. This function displays the * // information in each array contained at the subscript. * //************************************************************
void displayProd(const string title[], const string desc[], const double price[], int index) { cout cout cout
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started