Question

The manager of the Telemarketing Group has asked you to write a program that will help...

The manager of the Telemarketing Group has asked you to write a program that will help order- entry operators look up product prices. The program should prompt the user to enter a product number, and will then display the title, description, and price of the product. The program will consist of the following functions.
getProdNum: it asks the user to enter a product number. Please be sure to reject any value out of the range of correct product numbers.
binarySearch: to search an array for a product.
displayProd: to display the title, and the price of the product.
design a class to do the previous job and please submit a compressed folder with(header file, implementation, main program, and screenshot of the results.)

Language: C++

0 0
Add a comment Improve this question Transcribed image text
Answer #1

C++ CODE:

#include <bits/stdc++.h>

using namespace std;

// Declare all constant variables

const int MIN = 515;// maximam range

const int MAX = 525; // minimum range

const int PRODS = 10; // number of items

const int TITLE_SIZE = 50; // number of titles

const int DESC_SIZE = 12;


//Function prototype

int getProdNum();

int binarySearch(int [],int,int);

void displayProd(char [][TITLE_SIZE],char [][DESC_SIZE],double [],int);

// The main function

int main()

{

    // productNumber

    int id[PRODS] = {515,516,517,518,519,520,521,522,523,524};

    // product title names

    char title[PRODS][TITLE_SIZE] ={ "REI",

                                         "APPPLE",

                                         "J.C.PAM",

                                         "Toys'R'",

                                         "Musician Friend",

                                         "Marks and Spencer",

                                         "Victoria's Secret",

                                         "Electro",

                                         "Etsy"};

    // product description

    char description[PRODS][DESC_SIZE] = {"ab","TR","abcd",

                                              "abcd","Gk","KY",

                                              "Rk","Bk","LN"};

    // product prices

    double prices[PRODS] = {25.50, 50.25, 70.00,18.50,

                                 45.50,78.52, 79.50,47.50,63.50};

        

    

    // initialize a variable                       

    int prodNum;

    int idx;

    char choice;

    // show the menu

  

    do{

        prodNum = getProdNum();

        idx = binarySearch(id, PRODS, prodNum);

        // if product number not found.

        if(idx == -1){

            cout<<"That product number was not found.\n";

        }else{

            // if product number is found.

            displayProd(title,description,prices,idx);

        }

        // ask for choice again

        cout<<"Would you like to loop up another product? ( y / n ): ";

        cin>>choice;

    }while(choice == 'y' || choice == 'Y');                         

   cout<<"\n\n";

    return 0;

}

// Declare getProdNum function

int getProdNum(){

    int prodNum;

   // ask for input product number

    cout<<"\nPlease enter a product number: ";

    cin>> prodNum;

    // check input product is valid or not

    while (prodNum < MIN || prodNum > MAX)

    {

        cout<<"Enter a number in the range of "<<MIN<<" to "<<MAX<<".\n";

        cin>>prodNum;

    }

    // return prodNum

    return prodNum;

    

}

// Declare binarySearch function

int binarySearch(int arr[], int size, int search)

{

    int first =0,

    last = size-1,

    middle =-1,

    idx;

    bool flag =false;

    // find the middle value

    middle = (first+last)/2;

    // find the product number

    while (first <= last)

    {

       if(arr[middle] < search)

       {

        first = middle + 1;

       }

       else if(arr[middle] == search)

       {

           flag =true;

           idx =middle;

           break;

       }

       else {

            last = middle - 1;

       }

     middle = (first + last)/2;

    }

    // return product number location

   return idx;

}

// Declare displayProd function

void displayProd(char title[][TITLE_SIZE],char desc[][DESC_SIZE],double price[],int idx)

{

    // display the Title,Description and Price.

    cout<<"Title: "<<title[idx]<<endl;

    cout<<"Description: "<<desc[idx]<<endl;

    cout<<"Price: $"<<price[idx]<<endl;

}

OUTPUT:

Add a comment
Know the answer?
Add Answer to:
The manager of the Telemarketing Group has asked you to write a program that will help...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The manager of the Telemarketing Group has asked you to write a program that will help...

    The manager of the Telemarketing Group has asked you to write a program that will help order- entry operators look up product prices. The program should prompt the user to enter a product number, and will then display the title, description, and price of the product. The program will consist of the following functions. getProdNum: it asks the user to enter a product number. Please be sure to reject any value out of the range of correct product numbers. C++...

  • Complete the implementation of the point_3d program. This program will help you learn how to use:...

    Complete the implementation of the point_3d program. This program will help you learn how to use: the C language if statement; relational operators; and boolean operators. The program must implement a function which maps real-valued point (x,y) to real value z≥0, as follows: z=2.84898x+1.18569y, when x≥0 and y≥0; z=2.84898x+y2, when x≥0 and y<0; z=x2+1.18569y, when x<0 and y≥0; z=x2+y2, otherwise. To get the values of x and y, display a prompt of the form "Please enter X and Y:" The...

  • Please write a Java program that does the following: Create an array of 100 integers. Store...

    Please write a Java program that does the following: Create an array of 100 integers. Store 100 random integers (between 1 and 100) in the array. Print out the elements of the array. Sort the array in ascending order. Print out the sorted array. Prompt the user to enter a number between 1 and 100. Search the array for that number and then display "Found" or "Not Found" message. Display each number from 1 to 100 and the number of...

  • With your partner, brainstorm a program that will ask the user for a number of digits...

    With your partner, brainstorm a program that will ask the user for a number of digits to be stored. The program should then create an array of that size and then prompt the user for numbers to fill each position in the array. When all of the positions are filled, display the contents of the array to the user. Create a new Project named FillArray and a new class in the default packaged named FillArray.java. You and your partner should...

  • In C++ 1. Write a program that allows a user to enter 10 integer values from...

    In C++ 1. Write a program that allows a user to enter 10 integer values from the keyboard. The values should be stored in an array. 2. The program should then ask the user for a number to search for in the array: The program should use a binary search to determine if the number exists in a list of values that are stored in an array (from Step #1). If the user enters a number that is in the...

  • (C programing, Not C++) Write a program in C that asks the user to input 10...

    (C programing, Not C++) Write a program in C that asks the user to input 10 numbers. Store these numbers in an array. Then ask the user to input a single number. Your program should execute a linear search on the array, trying to find that number. If the number exists in the array, have the program print out which position/element the number was found at. If the target number is not in the array, have the program print out...

  • The name of the C++ file must be search.cpp Write a program that will read data...

    The name of the C++ file must be search.cpp Write a program that will read data from a file. The program will allow the user to specify the filename. Use a loop that will check if the file is opened correctly, otherwise display an error message and allow the user to re-enter a filename until successful. Read the values from the file and store into an integer array. The program should then prompt the user for an integer which will...

  • Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a funct...

    Program in C++! Thank you in advance! Write a menu based program implementing the following functions: (1) Write a function that prompts the user for the name of a file to output as a text file that will hold a two dimensional array of the long double data type. Have the user specify the number of rows and the number of columns for the two dimensional array. Have the user enter the values for each row and column element in...

  • C++ with Pseudocode in the beginning This assignment will require you to write a program that...

    C++ with Pseudocode in the beginning This assignment will require you to write a program that will create an array of 10 string objects. The array will be initialized with the strings which contain the person’s name and phone number in one string. The following is an example of test data: “Renee Javens, 678-1223”, “Joe Looney, 586-0097”, “Geri Palmer, 223-8787”, “Lynn Presnell, 887-1212”, “Bill Wolfe, 223-8878”, “Sam Wiggins, 486-0998”, “Bob Kain, 586-8712”, “Tim Haynes, 586-7676”, “John Johnson, 223-9037”, “Jean James,...

  • Write a program named ClassifyScores that classifies a series of scores entered by the user into...

    Write a program named ClassifyScores that classifies a series of scores entered by the user into ranges (0-9, 10-19, and so forth). The scores will be numbers between 0 and 100. Design and implement a program to prompt the user to enter each score separately. If the score is within the correct range, then increment the appropriate range If the score entered is greater than 100, display an error message, ignore the incorrect score, and prompt for the user to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT