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

// This program counts how many sales are made in each of 5 categories of produc

ID: 3631589 • Letter: #

Question

// This program counts how many sales are made in each of 5 categories of products.
// The user continuously enters a category number (1-5) and then enters a 9 to quit.
// At the end the program prints a list of the category names and the number
// of sales that were made for that category.
// Categories are: 1=Infants; 2=Children; 3=Teens; 4=Men; 5=Women
start
Declarations
num category
num SIZE = 5
num QUIT = 9
num sales[category] = 0, 0, 0, 0, 0
housekeeping()
while category = QUIT
mainLoop()
endwhile
endOfJob()
stop

housekeeping()
output "Enter category ", QUIT, " to quit "
input category
return

mainLoop()
if category >= 1 AND category <= SIZE then
sales[category - 1] = sales[category] + 1
else
output "Invalid category"
endif
output "Enter category ", QUIT, " to quit "
input category
return

endOfJob()
Declarations
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
string categoryName[SIZE] = "Infants", "Children", "Teens", "Men", "Women"
output HEAD1
output HEAD2
while category < SIZE
output categoryName[category], sales[category]
category = category + 1
endIf
return

Explanation / Answer

Dear, Modified is highlighted with red font start
Declarations
num category num SIZE = 5
num QUIT = 9
num sales[category] = 0, 0, 0, 0, 0
housekeeping()
while category = QUIT
mainLoop()
endwhile
endOfJob()
stop

housekeeping()
output "Enter category ", QUIT, " to quit "
input category
return

mainLoop()
if category >= 1 AND category <= SIZE then
sales[category - 1] = sales[category-1] + 1
else
output "Invalid category"
endif
housekeeping()
return
endOfJob() Declarations
string HEAD1 = "Sales"
string HEAD2 = "Category Number of Sales"
string categoryName[SIZE] = "Infants", "Children", "Teens", "Men", "Women"
output HEAD1
output HEAD2 num loop=0 while category < SIZE
output categoryName[loop], sales[loop]
loop =loop+ 1
endwhile
return