assignemnt 3 of problem solving

13
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

Upload: kaladher-reddy

Post on 21-Jul-2016

10 views

Category:

Documents


7 download

DESCRIPTION

assign3

TRANSCRIPT

Page 1: Assignemnt 3 of Problem Solving

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

Page 2: Assignemnt 3 of Problem Solving

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.

Page 3: Assignemnt 3 of Problem Solving
Page 4: Assignemnt 3 of Problem Solving

exercise 4:

Page 5: Assignemnt 3 of Problem Solving

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

Page 6: Assignemnt 3 of Problem Solving

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

Page 7: Assignemnt 3 of Problem Solving

exercise 5:

A:

Page 8: Assignemnt 3 of Problem Solving

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

Page 9: Assignemnt 3 of Problem Solving

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

Page 10: Assignemnt 3 of Problem Solving

B:

Pseudocode:

start

Declarations

num teamNum

num QUIT = -1

Page 11: Assignemnt 3 of Problem Solving

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

Page 12: Assignemnt 3 of Problem Solving

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