Question: Convert to Java //Price Check.cpp //Uses a two-dimensional array to store a price list; //displays the price associated with a product ID #include #include #include

Convert to Java

//Price Check.cpp

//Uses a two-dimensional array to store a price list;

//displays the price associated with a product ID

#include

#include

#include

#include

using namespace std;

int main()

{ //declare variable and array

string searchForId = "";

string products[5][2] = {{"BX35", "13.00"},

{"CR20", "10.00"},

{"FE15", "12.00"},

{"KW10", "24.00"},

{"MM67", "4.00"}};

//get ID to search for, then convert to uppercase

cout << "Enter ID (X to exit): ";

getline(cin, searchForId);

transform(searchForId.begin(), searchForId.end(), searchForId.begin(), toupper);

while (searchForId != "X")

{

//locate position of product ID in the first column in the array

int row = 0; //keeps track of array subscripts

while (row < 5 && products[row][0] != searchForId)

{

row = row + 1;

}//end while

//if ID was found, display price from the second column in the array

//otherwise, display error message

if (row < 5)

{

cout << setiosflags(ios::fixed) << setprecision(2)

<< "Price for product ID " << products[row][0]

<< ": $" << products[row][1] << endl << endl;

}

else

{

cout << "Invalid product ID" << endl << endl;

}//end if

//get ID to search for, then convert to uppercase

cout << "Enter ID (X to exit): ";

getline(cin, searchForId);

transform(searchForId.begin(), searchForId.end(), searchForId.begin(), toupper);

}//end while

return 0;

}//end of main function

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!