the spread-a-smile greeting card store maintains customer records with data fiel
ID: 3627709 • Letter: T
Question
the spread-a-smile greeting card store maintains customer records with data fields for first name, last name, address and total purchases in dollars. At the end of each month,the store manager invites the five customers with the greatest value of purchases to an exclusive sales event. Develop the logic for a program that reads in 100 customer records and stores the first and last names and total purchases in three parallel arrays. then sort the arrays so that records are in descending order by purchase amount for the month. the output lists the names of the top five customers.Explanation / Answer
declare string arrays firstName, lastName and address
declare float array purchases
for(k from 1 to 100):
input firstName, lastName, address, purchases into separate arrays sub k
//Simple selection sort
for(k from 1 to 100):
declare integer max=k
for(j from k+1 to 100):
if purchases sub j > purchases sub max:
max=j
swap values in position max with values in position k for all four arrays
print("Top five customers: ")
for(k from 1 to 5):
print(firstName sub k +" "+lastName sub k)
--This method is pseudocode for a selection sort, where we iterate through each position in the array and "select" the correct value for that position (that is, the next biggest value).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.