In: Computer Science
NEED TO DEBUG
// This pseudocode should create a list that describes annual
profit
// statistics for a retail store. Input records contain a
department
// name (for example, “Cosmetics”) and profits for each quarter
for
// the last two years. The program should determine whether
// the profit is higher, lower, or the same
// for this full year compared to the last full year.
start
Declarations
string department
num salesQuarter1ThisYear
num salesQuarter2ThisYear
num salesQuarter3ThisYear
num salesQuarter3ThisYear
num salesQuarter1LastYear
num salesQuarter2LastYear
num salesQuarter3ThisYear
num salesQuarter4LastYear
num totalThisYear
num totalLastYear
string status
num QUIT = "ZZZZ"
housekeeping()
while department <> QUIT
compareProfit()
endwhile
finishUp()
stop
housekeeping()
output "Enter department name or ", QUIT, " to quit "
input dept
return
compareProfit()
getSalesData()
sumSalesData()
if totalThisYear = totalLastYear then
status = "Higher"
else
if totalThisYear <= totalLastYear then
status = "Lower"
else
status = "Same"
endif
endif
output department, status
output "Enter department name or ", QUIT, " to quit "
input department
return
getSalesData()
output "Enter sales for first quarter this year "
input salesQuarter1ThisYear
output "Enter sales for second quarter this year "
input salesQuarter1ThisYear
output "Enter sales for third quarter this year "
input salesQuarter1ThisYear
output "Enter sales for fourth quarter this year "
input salesQuarter4ThisYear
output "Enter sales for first quarter last year "
input salesQuarter1LastYear
output "Enter sales for second quarter last year "
input salesQuarter3LastYear
output "Enter sales for third quarter last year "
input salesQuarter3LastYear
output "Enter sales for fourth quarter last year "
input salesQuarter3LastYear
return
sumSalesData()
totalThisYear = salesQuarter1ThisYear + salesQuarter2ThisYear
+
salesQuarter2ThisYear + salesQuarter4ThisYear
totalLastYear = salesQuarter2LastYear + salesQuarter2LastYear
+
salesQuarter3LastYear + salesQuarter4LastYear
return
finishUp()
output "End of report"
return
// This pseudocode should create a list that describes annual
profit
// statistics for a retail store. Input records contain a
department
// name (for example, “Cosmetics”) and profits for each quarter
for
// the last two years. The program should determine whether
// the profit is higher, lower, or the same
// for this full year compared to the last full year.
Start
Declarations
string department
num totalThisYear
num totalLastYear
string status
string QUIT = "ZZZZ" // this will be of type string
not num
department = housekeeping()
while department <> QUIT
department = compareProfit()
end while
finishUp()
Stop
function housekeeping()
output "Enter department name or ", QUIT, " to quit
"
input dept
return dept // dept name should be returned
function compareProfit()
Declarations
num salesQuarter1ThisYear
num salesQuarter2ThisYear
num salesQuarter3ThisYear
num salesQuarter4ThisYear
num salesQuarter1LastYear
num salesQuarter2LastYear
num salesQuarter3LastYear
num salesQuarter4LastYear
num totalThisYear
num totalLastYear
string department
[salesQuarter1ThisYear, salesQuarter2ThisYear,
salesQuarter3ThisYear,salesQuarter4ThisYear,salesQuarter1LastYear,
salesQuarter2LastYear,salesQuarter3LastYear,salesQuarter4LastYear ]
= getSalesData()
[totalThisYear, totalLastYear] =
sumSalesData(salesQuarter1ThisYear, salesQuarter2ThisYear,
salesQuarter3ThisYear,salesQuarter4ThisYear,salesQuarter1LastYear,
salesQuarter2LastYear,salesQuarter3LastYear,salesQuarter4LastYear)
if totalThisYear > totalLastYear then // the
comparison operator will be greater than not equal to
status = "Higher"
else
if totalThisYear < totalLastYear
then // the comparison operator will be less than not less than or
equal to
status =
"Lower"
else
status =
"Same"
end if
end if
output department, status
output "Enter department name or ", QUIT, " to quit
"
input department
return department
function getSalesData()
Declarations
num salesQuarter1ThisYear
num salesQuarter2ThisYear
num salesQuarter3ThisYear
num salesQuarter4ThisYear
num salesQuarter1LastYear
num salesQuarter2LastYear
num salesQuarter3LastYear
num salesQuarter4LastYear
output "Enter sales for first quarter this year
"
input salesQuarter1ThisYear
output "Enter sales for second quarter this year
"
input salesQuarter2ThisYear
output "Enter sales for third quarter this year
"
input salesQuarter3ThisYear
output "Enter sales for fourth quarter this year
"
input salesQuarter4ThisYear
output "Enter sales for first quarter last year
"
input salesQuarter1LastYear
output "Enter sales for second quarter last year
"
input salesQuarter2LastYear
output "Enter sales for third quarter last year
"
input salesQuarter3LastYear
output "Enter sales for fourth quarter last year
"
input salesQuarter4LastYear
return (salesQuarter1ThisYear, salesQuarter2ThisYear,
salesQuarter3ThisYear, salesQuarter4ThisYear,
salesQuarter1LastYear,
salesQuarter2LastYear, salesQuarter3LastYear,
salesQuarter4LastYear)
function sumSalesData(salesQuarter1ThisYear,
salesQuarter2ThisYear,
salesQuarter3ThisYear,salesQuarter4ThisYear,salesQuarter1LastYear,
salesQuarter2LastYear,salesQuarter3LastYear,salesQuarter4LastYear)
Declarations
num totalThisYear
num totalLastYear
totalThisYear = salesQuarter1ThisYear +
salesQuarter2ThisYear + salesQuarter3ThisYear +
salesQuarter4ThisYear
totalLastYear = salesQuarter1LastYear +
salesQuarter2LastYear + salesQuarter3LastYear +
salesQuarter4LastYear
return(totalThisYear, totalLastYear)
function finishUp()
output "End of report"
return