Programming Reasoning

Home - Programming Reasoning - Programming Reasoning

01.09.2019-786 views -Programming Reasoning

 Programming Logic Essay

Programming Common sense and Design, 6th Copy

Chapter 5

Exercises

1 ) What is result by each of the pseudocode sectors in Physique 5-22?

Solution:

|a. |5, 22, five | |b. |4, 6, 7 | |c. |5, 6 | |d. |Goodbye | | |Goodbye | | |Goodbye | | |Goodbye | | |Goodbye | | |Goodbye | | |Goodbye | | |Goodbye | | |Goodbye | |e. |Hello | | |Hello | | |Hello | |f. |Adios | | |Adios | | |Adios | | |Adios | | |Adios | | |Adios | | |Adios | | |Adios

2 . Design and style the logic for a program that results every amount from you through 12.

Answer:

A sample solution uses

Flowchart:

[pic]

Pseudocode:

start

Declarations

num number

housekeeping()

number sama dengan 1

although number 99999

output " Please enter into a valid scoot code”

insight custZip

endwhile

return

validateCustAge()

while custAge < 12 OR custAge > 110

output " Please enter a valid customer age”

insight custAge

endwhile

return

validateNumItems()

Declarations

num attempts = 0

num LIMIT sama dengan 2

validNumItems = you

while (numItems < one particular OR numItems > 12) AND tries < LIMIT

output " Please reenter the number of items”

input numItems

attempts = attempts + 1

endwhile

if efforts = a couple of AND numItems < 0 then

outcome " A great invalid volume of items was entered”

outcome " This order will not be counted”

validNumItems = 0

endif

return

housekeeping()

end result ZIP_PROMPT

type custZip

go back

detailLoop()

outcome AGE_PROMPT

type custAge

result ITEM_PROMPT

type numItems

validateZipCode()

validateCustAge()

validateNumItems()

countOfOrders = countOfOrders + 1

totalCustAge = totalCustAge + custAge

if custZip = STORE_ZIP

numItemsInStoreZip = numItemsInStoreZip & numItems

different

numItemsInOtherZips = numItemsInOtherZips + numItems

endif

if custAge < 31 then

numItemsUnder30 = numItemsUnder30 + numItems

else

numItems30AndOlder = numItems30AndOlder + numItems

endif

outcome ZIP_PROMPT

input custZip

go back

finishUp()

Policy riders

avgCustAge

in the event that countOfOrders > 0 then simply

output " Total products ordered inside the ”,

STORE_ZIP, " zero code = ”, numItemsInStoreZip

output " Total items ordered consist of zip codes sama dengan ”, numItemsInOtherZips

avgCustAge sama dengan totalCustAge / countOfOrders

result " The average customer age group is: ”, avgCustAge

outcome numItemsUnder30,

" items were ordered by simply customers below 30”

outcome numItems30AndOlder,...

Related