Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

We have a program that has three parallel arrays: barcode (an array of integers)

ID: 3855605 • Letter: W

Question

We have a program that has three parallel arrays: barcode (an array of integers), description (an array of strings) and price (an array of doubles). The maximum size of the arrays is 100. The program will display the price and description on when you enter a specific bar code. Write a function that will send back a price and description to the main when the bar code is sent to it. The function prototype is double scanner (char descr[100] [30], double price[100], int barcode[100], int scancode, int* location);

Explanation / Answer

The below function will store the index of a matching barcode in location when found and stores -1 when not found. Returns price when found and -1 when not found. So using the value of location, the calling program will print the corresponding values in descr[] and price[] arrays whenever the location is not -1.

double scanner(char desc[100][30], double price[100], int barcode[100], int scancode, int *location)

{

int i;

for(i = 0; i < 100; i++)

{

if(barcode[i] == scancode) //found

{

*location = i;

return price[i];

}

}

  

//when not found

*location = -1;

return -1; //return a -ve value when not found

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote