In: Computer Science
a file named maintence08-01.txt is included with your
downloadable student files. Assume that this program is a working
program in your organization and that it needs modifications that
are described in the comments(lines that begin with two slashes) at
the beginning of the file. Your job is to alter the program to meet
the new specifications.
Here is the file Maintence08-01.txt
// This application reads sales data for a real estate
broker.
// The user enters a record for each of 10 salespeople
// containing the salesperson's name,
// the number of properties sold by that person during the
month,
// and the total value of those properties.
// The data records are sorted by value so the data for
// the top three salespeople can be displayed.
// Modify the program to
// (1) enter data for any number of salespeople up to 60
// (2) allow the user to choose whether to see
// (a) the data for the top three salespeople
// (or fewer if 3 are not entered) by value
// (b) the data for the top three salespeople
// (or fewer if 3 are not entered) by
// number of properties sold
start
Declarations
num SIZE = 10
string names[SIZE]
num properties[SIZE]
num values[SIZE]
num count
num NUM_TO_DISPLAY = 3
num comps
num x
num y
num tempProp
num tempVal
string tempName
getReady()
display()
finish()
stop
getReady()
count = 0
while count < SIZE
output "Enter salesperson name "
input names[count]
output "Enter number of properties sold "
input properties[count]
output "Enter total value of those properties "
input values[count]
count = count + 1
endwhile
return
display()
sort()
count = 0
while count < NUM_TO_DISPLAY
output names[count], properties[count], values[count]
count = count + 1
endwhile
return
finish()
output "End of display"
return
sort()
comps = SIZE - 1
while y < comps
x = 0
while x < comps
if values[x] < values[x + 1] then
swap()
endif
x = x + 1
endwhile
y = y + 1
endwhile
return
void swap()
tempName = names[x + 1]
names[x + 1] = names[x]
names[x] = tempName
tempProp = properties[x + 1]
properties[x + 1] = properties[x]
properties[x] = tempProp
tempVal = values[x + 1]
values[x + 1] = values[x]
values[x] = tempVal
return
start
Declarations
num reqSize
num MAX_SIZE = 60
num SIZE
string names[]
num properties[]
num values[]
num count
num MAX_NUM_TO_DISPLAY = 3
num NUM_TO_DISPLAY
num comps
num x
num y
num tempProp
num tempVal
num choose
string tempName
getReady()
display()
finish()
stop
getReady()
count = 0
output "Enter required size"
input reqSize
SIZE = Min(reqSize,MAx_SIZE)
while count < SIZE
output "Enter salesperson name "
names.add(input)
output "Enter number of properties sold "
properties.add(input)
output "Enter total value of those properties "
values.add(input)
count = count + 1
endwhile
return
display()
output "Show top salesperson by value(Type1) or properties sold (Type 2)"
input(choose)
if choose == 1
sortvalues()
endif
if choose == 2
sortproperties()
endif
count = 0
NUM_TO_DISPLAY = min(MAX_NUM_TO_DISPLAY,SIZE)
while count < NUM_TO_DISPLAY
output names[count], properties[count], values[count]
count = count + 1
endwhile
return
finish()
output "End of display"
return
sortvalues()
comps = SIZE - 1
while y < comps
x = 0
while x < comps
if values[x] < values[x + 1] then
swap()
endif
x = x + 1
endwhile
y = y + 1
endwhile
return
sortproperties()
comps = SIZE - 1
while y < comps
x = 0
while x < comps
if properties[x] < properties[x + 1] then
swap()
endif
x = x + 1
endwhile
y = y + 1
endwhile
return
void swap()
tempName = names[x + 1]
names[x + 1] = names[x]
names[x] = tempName
tempProp = properties[x + 1]
properties[x + 1] = properties[x]
properties[x] = tempProp
tempVal = values[x + 1]
values[x + 1] = values[x]
values[x] = tempVal
return
I've implied that we are using dynamic size array, rest of the program is self explanatory. Do let me know if you need any help nonetheless.