assignemnt 3 of problem solving
DESCRIPTION
assign3TRANSCRIPT
ASSIGNMENT # 3
by
gurram kaladhar reddy & nishtala sandeep
True or False:
1.f
2.f
3.f
4.f
5.f
multiple choice:
1.a
2.a
3.a
4.b
short answers:
1. Accumulator is a variable that gathers values
Silmilar to a counter Counter increments by 1. Accumulator increments by some value
Accumulators require three actions actions
Initialize the accumulator to 0 Accumulators are altered: once for every data set processed At the end of processing, accumulators are output
2. we create array constants by entering a list of items and then manually surrounding the list with braces { }
3. we find a particular value in an array by using some searching techniques on that array.
exercise 4:
Pseudocode:
start
Declarations
string itemOrdered
num x
num found = 0
num total = 0
num SIZE = 3
string QUIT = “ZZZZ”
num PRICE[SIZE] = 2.49, 1, 0.59
string PRODUCT[SIZE] = “Cheeseburger”, “Pepsi”, “Chips”
string ERROR_MSG = “Sorry, we do not carry that”
getReady()
while itemOrdered not equal to QUIT
detailLoop()
endwhile
finishUp()
stop
getReady()
output “Enter an item or ”, QUIT, “ to complete your order”
input itemOrdered
return
detailLoop()
found = 0
x = 0
while x < SIZE
if itemOrdered = PRODUCT[x] then
output PRICE[x]
x = SIZE
found = 1
total = total + PRICE[x]
else
x = x + 1
endif
endwhile
if found = 0 then
output ERROR_MSG
endif
output “Enter an item or ”, QUIT, “ to complete your order”
input itemOrdered
return
finishUp()
output “Your order total is: $”, total
return
exercise 5:
A:
Pseudocode:
start
Declarations
num teamNum
num QUIT = -1
num SIZE = 5
string teams[SIZE] = “Goal Getters”, “The Force”,
“Top Guns”, “Shooting Stars”,
“Midfield Monsters”
getReady()
while teamNum not equal to QUIT
displayTeamName()
endwhile
finishUp()
stop
getReady()
output “Enter the player’s team number or ”, QUIT, “ to quit”
input teamNum
return
displayTeamName()
if teamNum >= 1 AND teamNum <= SIZE then
output teamNum, teams[teamNum-1]
else
output “Invalid team number”
endif
output “Enter the player’s team number or ”, QUIT, “ to quit”
input teamNum
return
finishUp()
output “End of program”
return
B:
Pseudocode:
start
Declarations
num teamNum
num QUIT = -1
num SIZE = 5
num teamCnt[SIZE] = 0
string teams[SIZE] = “Goal Getters”, “The Force”,
“Top Guns”, “Shooting Stars”,
“Midfield Monsters”
getReady()
while teamNum not equal to QUIT
countTeams()
endwhile
finishUp()
stop
getReady()
output “Enter the player’s team number or ”, QUIT, “ to quit”
input teamNum
return
countTeams()
if teamNum >= 1 AND teamNum <= SIZE then
output teamNum, teams[teamNum-1]
teamCnt[teamNum-1] = teamCnt[teamNum-1] + 1
else
output “Invalid team number”
endif
output “Enter the player’s team number or ”, QUIT, “ to quit”
input teamNum
return
finishUp()
teamNum = 0
while teamNum < SIZE
output teamNum+1, teamCnt[teamNum]
teamNum = teamNum + 1
endwhile
return