Question

In: Computer Science

Using C++ (microsoft visual studios 2013) create a program that uses three parallel numberic arrays of...

Using C++ (microsoft visual studios 2013) create a program that uses three parallel numberic arrays of size 6. The program searches one of the arrays and then displays the corresponding values from the other two arrays. The program should prompt the user to enter ProductID. Valid ProductID's should be the numbers 24, 37, 42, 51, 66 and 79. The program should search the array for the product ID in the ID's array and display the corresponding price and quantity from the prices and quantities array. Populate the prices and quantities arrays with any values you desire. Price should allow for two decimal places. Allow the user to display the price and quantitiy for as many product ID's as desired without having to execute the program again. Of course and bad ProductID's should display an error message, but the user should be able to continue until a sentinel is entered. The program should be structured to work with any numbers should to company change product ID's in the future.

Solutions

Expert Solution

C++ Program:

// products.cpp

#include "stdafx.h"
#include <iostream>
#include <iomanip>

int main()
{
   //Three Parallel arrays
    //Product id array
    int productIds[] = {24, 37, 42, 51, 66, 79};

    //Quantity array
    int quantity[] = {10, 8, 6, 23, 2, 5};

    //Price array
    double prices[] = {23.6, 18.4, 65.255, 10.69, 85.144, 50.24};

    int i, pos, prodId;

    //Reading product id from user
    std::cout << "\n Enter product Id (-999 to Exit): ";
    std::cin >> prodId;

    //Loop till user enters a sentinel value
    while(prodId != -999)
    {
        //Initializing pos to -1
        pos = -1;

        //Searching for product id
        for(i=0; i<6; i++)
        {
            if(productIds[i] == prodId)
            {
                //Updating pos value
                pos = i;
            }
        }

       //Prodcut with given id is not found
        if(pos == -1)
        {
            std::cout << "\n Invalid Product ID.... \n";
        }
        else
        {
           //Product found
            std::cout << "\n Quantity: " << quantity[pos];
            std::cout << "\n Price: $" << std::setprecision(2) << prices[pos];
        }

        //Reading product id from user
        std::cout << "\n\n Enter product Id (-999 to Exit): ";
        std::cin >> prodId;
    }

    std::cout << "\n\n";

   system("pause");

    return 0;
}

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:


Related Solutions

Program is to be written in C++ using Visual studios Community You are to design a...
Program is to be written in C++ using Visual studios Community You are to design a system to keep track of either a CD or DVD/Blu-ray collection. The program will only work exclusively with either CDs or DVDs/Blu-rays since some of the data is different. Which item your program will work with will be up to you. Each CD/DVD/Blu-ray in the collection will be represented as a class, so there will be one class that is the CD/DVD/Blu-ray. The CD...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that...
C# Programming language!!! Using visual studios if possible!! PrimeHealth Suite You will create an application that serves as a healthcare billing management system. This application is a multiform project (Chapter 9) with three buttons. The "All Accounts" button allows the user to see all the account information for each patient which is stored in an array of class type objects (Chapter 9, section 9.4).The "Charge Service" button calls the Debit method which charges the selected service to the patient's account...
I need this code in C++ form using visual studios please: Create a class that simulates...
I need this code in C++ form using visual studios please: Create a class that simulates an alarm clock. In this class you should: •       Store time in hours, minutes, and seconds. Note if time is AM or PM. (Hint: You should have separate private members for the alarm and the clock. Do not forget to have a character variable representing AM or PM.) •       Initialize the clock to a specified time. •       Allow the clock to increment to the...
In Visual Studios 2017, using c++, Create a class (Scores) that stores test scores (integers) in...
In Visual Studios 2017, using c++, Create a class (Scores) that stores test scores (integers) in an array (assume a maximum of 100 scores). The class should have a constructor that allows the client to specify the initial value of the scores (the same initial value applies to all of them) and another default constructor that initializes them to 0. The class should have functions as follows: 1. A member function that adds a score to the array.  The client must...
In visual Studio C++ Create a program that uses a for loop to input the high...
In visual Studio C++ Create a program that uses a for loop to input the high temperature, and low temperature for each day of the week. The high and low will be placed into two elements of the array. For each loop the high and low will be placed into the next set of elements of the array. After the temps for all seven days have been entered into the array, a for loop will be used to pull out...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to...
Java program problem 1 Come up with an idea for parallel arrays Create the arrays to hold 5 items in each In the main(), load the arrays with data Then output the entire contents of the arrays Create a method called find1() and pass the 2 arrays to that method. problem 2 In the find1() method, ask the user to enter a value to search for Write logic to search the first array and then output the related data from...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate...
Microsoft Visual C++ Assembly language Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop For example: Fib(1) = 1, Fib(2) = 2, Fib(3) = Fib(1) + Fib(2) = 3, Fib(4) = Fib(2) + Fib(3)...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays,...
Using Dev-C++ write a program that allows a small business owner to input, in parallel arrays, the type of item, its cost, and the number in stock. The program should output this information in the form of a table. The output will look something like below. Also, assume for a finite number of item name of 3 Item Name Cost Number in Stock Widget 25.00 4 ... ... ... Wombet 47.50 9 Prelude to Programming (6th edition)
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and...
Your task is to create a book ordering form using VISUAL STUDIOS, with the code and screenshots 1. Boxes for first name, last name, address. 2. Radio buttons to select: hard cover, soft cover, ebook. 3. Drop down list to select the book (make up three or four book names). 4. Radio buttons to select credit card (at least Visa, Master Card, American Express). 5. Box to enter credit card numbers. 6. The credit card box MUST verify that numbers...
create a C++ program using Visual Studio that could be used by a college to track...
create a C++ program using Visual Studio that could be used by a college to track its courses. In this program, create a CollegeCourse class includes fields representing department, course number, credit hours, and tuition. Create a child (sub class) class named LabCourse, that inherits all fields from the the CollegeCourse class, includes one more field that holds a lab fee charged in addition to the tuition. Create appropriate functions for these classes, and write a main() function that instantiates...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT