infomation technology HW
A waitress named Trixie works at a local diner. The diner just opened for the day and there are
customers already siiting at several of the tables. Write the instructions thai direct Trixie to go overto
each table that needs to be waited on and tell the customers about the daily specials. While at each
table, Trixie should take each customer's order. She then should submit the order for the entire iable & the cook.
Solution
v rlt ui {uv eu u\ tu\!t. t\ut wt t d,s tu \t Uilr\.t il Uw. <insert the missing instructions here>
end ' epeaL
Additional instructions
asl<. the c,"tstowter f or hLs or lter ord,er ewd rqeat
giue the orderslip to the cook go ov€t'to the cook, at the couwter
go to a table that needs to be waited ow record the order ow the order sLLp for that tabLe rqeat for each cwstowter at t)ne tabLe: tear the aTproprtate order sLtp fron," the order pad, teLL the cvLstowcers at the LabLe abou"t the d,aLLg specLaLs
Figure 3.$-S Information for Question 2 in Mini-Quiz 15-1 lmage by Diane Zak; Created wiih Reallusion Crazylalk Animator
What Do I Owe Each Month? Figure 15-7 shows the output, processing, and input items for the Monthly Payment Calculatu. application from Chapter 74.It also shows the application's algorithm. Recall that the application calculates and displays the monthly payments on a loan. The payments are calculated using the principal and term entered by the user, along with a loop that varies the annual interest rates from 4o/o through 7o/o.
lat;::t_:: n^-owthLg pagn*ewt (for each awwvaL Lwteresi raLe)
Pn:':+;sLwa: ar4-wLt-aL Lwterest rate (ccL,L.wter that couwts .froru +V d4raugr4 7F
Lw Lwcrewtewts cf tfi) Mfl-r-:: prLwcrpaL
ternt (Lw yjears)
: r---1./t-:
' il'"--!. -heTrLwctpaL awd. tervw 'i,'t-.',3
^awA PrevLov"s tt^,owtlrlt4 pagntewts frow" the ?at4vwewts bor.
, -1, - f Dr awwvtaL Lwterest rates fiow, +ft throtqV, 7,bi^ Lwcrew,ewts of tft: lqLc^Late the cr,trrewt n'owthLt| pauvtLewt vtsLwg the TrLwctpaL, tervw, a'r,.d, cu,rrewt aww,taL Lwterest rate TLsvLau the cu-rrewt Awwr,taL Lwierest rate awd the u,trrewt vvtow|nLu rauw-ewt
7,"-j alpe7t
What Do I Owe Each Month?
15'7 Planning information for the Monthly Payment Calculator application from Chapter 14 leaming 2013
r let's say you are asked to modifl, the application so that, rather than having the user enter ffim, it automatically uses terms of 2 through 5 years. What changes would need to be made
ffie algorithm shown in Figure 15-7? obviously, you would chang"e the first step in the rifim to ewter Lhe Td"wctpaL The algorithm's second step clears"the contents of the
ts box and would still be necessary.
:let's study the loop in Step 3 in the algorithm. The loop contains the instructions to rXate and display the monthly payments. Currently, the instructions are repeated. for annual
Eest rates from4o/o through 7o/o. Inthe modified algorithm, those instructions will also need foe repeated for terms froy2 through 5 years. You can accomplish this task by including antrionai loop in the algorithm. You can either nest the term loop within the rate loop, or nest
ffis rate ioop within the term loop. But how do you determine thl nested ioop? If you want to dmplay the monthly payments by term within rate-for example, display the payment s for 2 fuough 5 years using a 4o/o rate, followed by the payments for i through'S years using a S% rate, ad so on-you would nest the term loop within the rate loop. However, if you *rrri to display t'&e monthly payments by rate within term-for example, display the 2-year payments for 4o/o rarough 7o/o, followed by the 3-year payments for 4o/o thiough io/o,'and,so on-you wouid nest the tn"'ne looP within the term loop. Figure 15-B shows the planning information for the modified ,Montlily Payment Calculator application. The modified lin", aie shaded in the figure. The a@orithm will display the monthly payments by rate within term.
'2zZr2s/4/zgVe',raZ?e at //e Ou/sde //Ves/ed / oops)
Oxtpttt:
?rocessLwg
vu-owlnL'4 PatywewL ({or eacV' r)vn-vavtal LvrLer*l rate
awd terw\
awwxar,,.wreresr raLe bor.twru tvt::_::";r;%f;rw +ff
t'vvovtz
.h
7T"
te:rvqt' tr,awlttry Yhat 'oq*wts trolw 2 tXgars lhrout'qh 5 yeavs '"yr
""'' t*|;*,*twLs aft year)
llr,przt: Pr'vwcrPAL
Alaor'tt)nwt:
",r;Y,:!';Y;-;'::;"'wowrhtt4Ta!\'"*:r::^the?at4vwewtsbo; 3 . rspehLi9! tew'\ry\4' 7 14*Uni rnyi^gh
5 lle:Ys Lw Lworetwgwts: ot' t' y,ar"
d,isyLa'g t:*e'urr' et'"itlrwL Lw th e P a tlw-ewls b Dx'
rtpeat f or awwwal Lwterest rates frovw +ft lhrovtQn 7 'T :\ :'*^t^':*ewts
o{ rft '
ca.Lcttlale the cwrrewl tt'tt"owl\'tLg wgioe*t ^ti'"g
ilne 1'twcr4aL' :s\^v{'ewL
"^-;:,;;Y:::':5!::::i:?Y::::[^)]*^*otkecurrev'tvwowihLtgTavtu"ewi dtsplag a blank Line in tne PaAtxa€nLs bo< Lo seParate the current terlu's tw{arniatto'w.frou tV,e wgiy te.n4*'s Lr;fa ruwatLo w
ewd,'reteal
F&6xne 3S-S Planning information for the modified Monthly Payment Calculator application O Cengage Learning 2013
T* *pen t$'t* ftf$*mt&r$ Fxxywt*nt **leulator *pp!*aat{*rt:
1. Open the Monthly Payment Solution (Monthly Payment Solution.sln) file contained irrthe ClearlyVB2012\Chap1S\Monthly Payment Solution-Version 1 folder. If necessarr-.
open the designer window. The application's interface is shown in Figure 15-9. The user
will enter the principal in the txtPrincipal control, \Mhen the user clicks the Calculate
Monthly Payments button, the payments will appear in the txtPayments control.
u t d * f iI ft {q
{ I
{
What Do I Owe Each Month?
Monthty paymenrCatcularor i*Elg_j@
lrlncipal: payrnents:
txtPrincipal txtPayments
Crlculate il*anthly paynrentg fuir
i'!*i.ii"* .r.i:!-i? user interface for the Monthry payment carcurator apprrcatron
r may be wondering why the interface uses a text box rather than a iabel controi to display. monthly payments' Although you can display a great a""r "r
lrrr.mation in both types of.--trols' a text box can have t..oil br., that allow yiu to ,i;;h; information not currentry- - tvtng in the control' However, for a text box to include scroll bars, its scrollBars and".itlline properties must be.set appropriately. The ScrollBars property indicates whether the'.': box has no scroll bars (the default), a horizontal scroll bar, a vertical scroll bar, or both:.izontal and vertical scroll bars. A text box's Multilin;oril;n -rieciftes
whether the text box':- accept and display multiple lines of text. For a text box to.o,r'tri, scroll bars, its Multilineperty must be set to True.
: Click the txtpayments contror. Change the contro|s Murtirine property to True, then :i?il:i:llt'#]ie"'
p'op".ry;";;;;i."r. A verticar sc.orr bar appears on the right side
' r'ou know' users cannot edit the contents of a iabel control during run time, but they can edit: contents of a text box. In this application, however, the useruno,iia not be allowed io .hung" = payments displayed in the txtPayments control. y_ou can p;; the user from editing thertents of a text box by setting the text box's Readonrv prop"itv-to 7.u".
' change the txtPayments controi's Readonly property to True. Notice that the text boxis now colored gray rather than white. " Unlock the controls on the form, and then size the txtpayments control to match Fisure15-10. (or, you can set the contro|s size p.roperty to approxim;,+ i;;, il.j ;,r:, f,,*the left borders of the Payments label ur-ri t*tluy-""il'.""i."r, as shown i, the figure.
l'm on lhe lnside; vor;" . irr. di;d. iN;ri;; Lil.,
S" Lock the controls on the form and then save the solution. Now that the interface uo"ilrrf raffi;fiilt":"tplete' you can code the Clicr< event procedure for the Carcura_=
.:::::1ir!:1.:tJi:ll:;l'..i :::ti.:,:ir:.-r.i,,:.:,.-..-... ..- -,.,. - ,...,.,.:, ::t ,:.::::.. r::a::ar::4.-' - _ i . :, ::tr
To cede ar:d tfuen test tlt* binealc_Clici< procesun*: A. Open the Code Editor window and lo
,1"j9:i;:'il*#ffi :;txffi 1'r]*.ul*,1:]:,{:-:-rr:.rl f ,'"'tr",ilT;"J;;T.'.'#';Titil::xJf*'H:$?ij:l;rurxl*rurTl Press Enter twice after ayprrrg *i"rr*rr,,, statement.
rwing two nin-, ,,u,"^"r.i I
fl*ge"*r* 3S-3& Correct size and alignment of conkols
wr,rt oo io*. rrCrl M;;ihi ",.',.i
Step 3 in the algorithm is an outer counter-controiled Ioop whose instructions should be processed for values from2 through 5 in increments of 1. You will use the For...Next statement to code the loop. Enter the following comment and For clause:
' calculate and display the monthly payments For intTerm As Integer = 2 To S Change the Next clause to Next intTerm,
The first instruction in the outer loop displays the current term in the payments box. Click the blank line below the For clause and then enter the following two lines of code: txtPayments.Text = txtPayments.Text &
"Term: " & intTerm.ToString & ControlChars.Newline The next instruction in the outer loop is a nested counter-controlled loop. The instructions in the nested ioop should be processed for values from 4o/o through 7% in increments of 1%. Here again,,you will use the For...Next statement to code the loop. Enter the foilowing For clause:
For decRate As Decimal = .04 To .07 Step .01 Change the nested Next clause to Next decRate.
The two instructions in the nested loop calculate and display the monthly payment amounts along with their corresponding annual interest rate. Click the blani< line below the nested For clause and then enter the assignment statements shown in Figure 75-17; doing this completes the nested loop.
&{&"
g.
s" Erfi
7.
* g.
Fon l :
aJinii6 [i E;;{;;,;l = a.a4-il-o:07 siei- o.oi decPayment =
-:i j.r=ri:.i=1.. Pmt(decRate / 12, intTerm + 12, txtPayments.Text = txtpayments,Text &
decRate.ToStrlng("p8,') &,, ->,' &
"''----"lr d ec Pr incioa l )
I enier ttreie tri-; i lines of code l
decPayment. ToString( "C2") & i=:::r-cl{:;"tr:. I,leuline --.* Next decRate
Figxr* "f.S-33 Additional code entered in th. n.rt.O fooo
ll i
10. The last instruction in the outer loop displays a blank line in the payments box. The blank iine will separate the current term's information from the previous term's information. Insert a biank line below the Next decRate clause. type the following line of code and then click any other line in the code Editor window: txtPayments.Text = txtPayments.Text & controlchars.Newline
1 1' Save the solution and then start the appiication. Type 10000 in the principal box and then click the Calculate Monthly payments button. see Figure 7s-12.
im on tne lnside; You're on the Outside (Nested Loops)
fniadpa.h Faynentx
Tenn:3 4 E6 -F S295.34 5 B& -> Ezg*Jt 63& -> SSS4"32 7 9* -F $3{e"7?
Term:4 4S-F SAV.SJ$
S**:late l*t*r*th[q F.sryrnm*s
vou can use the scroll bar
io view the information for the 4-year and 5-Year terms
Figure 15"1'2 lnterface showing the terms, rates' and monthly payments
n 2. Use the scroll bar to view the monthly payments for the 4-year and S-year terms'
&g. Delete the contents of the principal box and then click the Calculate Monthly Pa)rments button. A monthly payment of $0'00 appears for each rate within
each terrn'
14. Click the Exit button. Close the Code Editor window and then close the solution'
The code entered' in the btnCalc-Click procedure is shown in Figure 75-13,
What Do I Owe Each Month?
r r-i vats 5ub : {>
' r-a-i tr I :i:! r : lti
' r:i 4.::.
btnCalc_Click(sender As *bject .: ) l"iandi es btnCal c. Cl'ick
..." : i i .'..,.. -.
t-!:ia'iir: r-:i'i:irr,*ur;l ! 7t;r:; l::i: t:ir'.,,i..i;i; ,;.11
: :: 1,. iiri_: I i1'a :i : il it:,
Di m decPri nci pal As Derir"iral Di r-r decPayment A.s Dei""; mal
D*rima-l .TryParse(txtPri nc'i pal .Text, decPri ncipal) a, ,
L,
txtPayments . Text = Sil--i n_u . Empty , :.
fo- intTerm As lr"eQer = 2 to 5 txtPayments.Text = txtPayments.Text &
"Term: " & intTerm.ToStr'i ng & : .Newli ne F,:r decRate As Deii*al : 0.04 T* 0.07 ltep 0.01
decPayment = -: , ' . Pmt (decR ate / 12 , i ntTe rm '''
txtPayments.Text = txtPayments.Text & decRate.ToStrinq("P0") & " *> " & decPayment.ToStri nS( "C2") &
Itext decRate txtPayments.Text = txtPayments.Text &''
l',ie xt i ntTerm 5u i:
12, decPri nci pal
. NewLi ne
,. . Newli ne
,
)l l
i
--i
, r'r, : ,::. btnCalc_Click procedure .:;: Learning 2013
: -t I Want to Do lt a Different Way -.,.-.er than using two For...Next statements to code the Monthly Payment Calculator
:.-cation, you can use two Do...Loop statements or one For...Next statement and one . Loop statement. In the next set of steps, you will modifi, the application so that it uses a Loop statement to keep track of the annual interest rates.
Use Windows to make a copy of the Monthly Payment Solution-Version 1 foider. Save the copy in the CIear1yVB2O12\Chap15 folder. Rename the copy Monthly Payment Solution-Version 2.
Open the Monthly Payment Solution (Monthly Payment Solution.sln) file contained in the Monthly Payment Solution-Version 2 folder. Open the designer window.
Open the Code Editor window and locate the btncalc_C1ick procedure. Modif! the procedure's code as shown in Figure 15-14. The modifications are shaded in the figure. Notice that whenyou use the Do...Loop statement (rather than tl-re For...Next statement) to keep track of the annual interest rates, you must include instructions to declare, initialize, and update the decRate variable.
gr.#.H'Tji{'li,L#*#ilT"
,":iil?:,i;;: :l :?*;. ?, :?;li:+:.., ;,i;:ffJls i:#":.;.??x, Empty ' calculate and di-or tntTerm ,q. r^rlflay the:nonthly paymentsro.
l:_.I:.i,^ ni"r, i"6;;r=.:-#"!txtPayments . texi -=,,Term: ,, e i^__fltpayments.Text & $d{]H#,#si'irg & cont ror chars . Newli ne
;l;:il:l+:Jl'-'(9."-.I, te / rz, i ntrermt* t oill*":,t: I: l: - :- il'it'ffi '{. r'.'i. *'f
tJ" "'1' 12' de c P r i n c i p a r )
3::I::*l:si1;1,ii ;bq':i'a':' l:.I 3
$ffi-]il,#;I#+;i' 6 [' d' rr
* -io
n.to, .h a ns . NewL i n ei;epiilih;AreiiiruuJ, wth this Loop clause I
i 'paut" ili;';;;;l;"t Lr") & control*rans.Ne
*--_*-,-6*ir.#"*aie = J"Enlll",i],,i*q,+.***__*_*rffi u,,o;, ^. *l
iiiF"rro",c r^..+ Ll*11." += o.oj.itxtPayments. Text =Next intTerm
decPri nci pal )
-cKare += 0.01 itxtPayments. Text & C*niralChars.Newline End Sub
5 H[,?. l.T;llroJVtodiried btncarc-crick procedure
d
i{ii ff :iT::,:f,iq:+ ilirffi ryfl m:T, JJr +f::?3, ft :t " p
r in c p ar b.x a ndpayments appear in the interfa.;,'r;;i;;".r.ji". in Figure ,r_rr.""r,
,na -onttif" click the Exit button. crose the Code Editor window and then close the soiution.
$&?$m$-Sx*$x XS-tr See Appendix B for the answers.
1. Write the code to dir r"u". i. L,J;$:::*:iTj:JlXl?#::*, using two pretesr roops arong with theror the nested roop Dispray ,h;;;;;;;;;; ,ffi il,H,I::X.yn:l" e"i N"*i",;;;;;.; XXXX XXXX XXXX
Rewrite the code from no...r-ooprtui" *?L:H:tlr""1,lo'il1?a For'..Next statement ror the outer roop and a