Lab 10-2.pdf 347 Use the program to calculate the diameter for a circle whose radius is 25.7. Thediameter is 51.4- Change the getArea function to a yalue_returning function. Save and then run the...

1 answer below »
Lab 9-2, Chapter 9 Exercise 16, Lab 10-2, Chapter 10 Exercise 16


Lab 10-2.pdf 347 Use the program to calculate the diameter for a circle whose radius is 25.7. Thediameter is 51.4- Change the getArea function to a yalue_returning function. Save and then run the pro-gram. Use the program to calculate the area of a circle whose *afw is 5.5. Then use it tocalculate the diameter of a circle whose radius is 25.7. Passing Variables to a Function In this lab, you will plan and create an algorithm for Patterson Windows. Theproblem specification and sample calcuiations are shown in Figure i0-18. A Create a program for patterson Windows, a compa ny that sells energy-effi cient replacementwindows for homes. The pr0gram should display the total amount a customer owes , given thenumber of windows ordered and the price per window The total owed is calculated by multiplyi ngthe number of windows ordered by the price per window. However , several times during the year,the company has a B0G0 (buy one, get one free) offer ,Exaqrole usins regulryicing Number of windows: 11 Price per window: 300 Total owed (11 . 300): S330O.OO ,Exar,nole uling BOGO p cing Number of windows: 15 Price per window: 200 Totalowed (8 . 200): 51600.00 Figure 10-18 Problem specification and a sample calculation for Lab l0-2 First, analyze the problem, iooking for the output first and then for the input. in this case, theerogram needs to display the total amount the customer owes. io caiculate that amount, thecomputer will need to know the number of windows o.a"."d, the price per window and therricing option (either regular or BOGO). ,\ftel.anallzing the problem, you plan the algorithm. In this case, in addition to the mai n:unction, the program will use three void functions named dispiayOptions, getRegular,and getBoGo. The di spl ayOpti ons function will display tfre piiclg options on the compurer :.J;,il ^ void function is appropriate for this task because the function will not need to return - he getRegul ar function will cajculate the total owed using the regular pricing option. TheletBoco function, on the other hand, will calculate the totaiow"a uring the BOGO pricingrption. The getRegul ar and getBoCo functions could be coded as either value-returning or,'oid functions. For this lab, you will use void functions. (you ;ill .l"rg" the functions to yalue_::lurning functions in Lab 10-3.) t LAB 10-2 PIan and Create I3., Void Functions To calculate the total owed, the getRegul ar and getBoGo functions will need to know the number of windows ordered and the price per window' The calling statement will pass that information by valueto the functions' Because both functions will be void functions' they will also need the talling statement to pass them the address of a variable in which to store the caiculated results. Figure 10-19 shows the completed IPO charts for the program's four functions' main function lnput prLcLwg oVtLow wttwtber of wLwdows wLwd'ow VrLce Processing ? r C cess,,'r'l i.--av/"s :',t"0 v'a OuQut totaL owed ALgorLthvw: t. caLLthe dLsyLagopttows fuwcLLowLo dLsTLag theprLcLwg oYtLows 2. qet the prLotwg oTtLow =. Lf (the yrLcLwg optLow Ls eLther t- or z) get the wtweber of wLwdows awd the wLwdow TrLce L{ (the prLcLwg aPLLow Ls t-) caLL the gelRtgvtLar fvtwclLow to caLovrLate the tltaL owed; ?ass the wwvwber of wLwdows awd the wLwdow yrLce, as weLL as the addYess of avarLabLeL0 stlYethetotaL lwed eLse caLL the gelBl q0 f *wctLo w to o aLcwLate the totaL owed; ?ass the wvwber of wLwdows awd the wLwdow 7rLce, as weLL as the address of a varLabLe t0 stlYe the LlLal owed ewd Lf dLsyLagthetotaL owed eLse dLELa g' @v aLLd oYtLow' vwessa qe ewd Lf f igi;:'e 1S-19 IPO charts for the functions in the Lab10-2 program (conttnues) 349 Passing Variables to a Function (continued) IPO charts for the functions in the Lab10-2 program (continues) T T start call displayOptions get pricing option and window price get number of windows pnclng option is1or2 display'lnvalid option" message pricing option isi callgetRegular; pass number of windows, window price, and the address of a variable to store the total owed call getBoGo; pass number of windows, window price, and the address of a variable to store the total owed stop ll F F T ---t--] lllt Void Functions bontinued) di spl ayoptions function lnput w0we Processing ProcessLwg Ltevws: wowe ALgorLthrw: t. dLspLag prLcLwg oqtLows Output prLutr"c cPt-i'a7v3 getRegular function lnput wu.wtber of wLwdows wLwdovt VrLce ad,dress of a varLabLelo stoYe the totaL owed, Processing ProcessLwg Llew"s: wawe Output ic:q.t o','lea. ALgorLthv*: t. caLcLlale totaL owed : w,twber o{ wLwdows * wLwdow TrLce = number of window price getBoGo function lnput wwwtber of wLwd'ows wtwdovt prLce add.ress of a varLabLeto stoYe Lhe LotaL owed Processing ProcessLwg Llew-s: wowe Output .0--?.i ltriar, ALgovLthw": r. caLu,tLate toLaL lwed : (w*n*ber of wLwdows / 2 + the revv-aLwdev of w,wwber of wLwdows / 2) * wLwdow TrLce start display pricing options start stop Fiqui'* 1l]'3-S IPO charts for the functions in the Labl0-2 program (continues) stop Passing Variables to a Function t! (conilnued) start total owed = (number of windows /2+ the remainder of number of windows / 2) . window price IPO charts for the functions in the Lab10-2 program The third step in the problem-soiving process is to desk-check the algorithm. you will desk- check the algorithms twice. For the first desk-check, you rvill use 1, 11, and 300 as the pricing option, number of windows, and window price, respectively. Using these values, the total owed should be $3300.00, as shown earlier in Figure 10-18. For the second desk-check, you will use 2, 15, and 200 as the pricing option, number of windows, and window price, respectively; the total owed should be $1600.00, as shown earlier in Figure 10-18. Figure 10-20 shows the completed desk-check tabie. Note: The names in black indicate items that belong to the mai n function. The names in red indicate items that belong to the getRegul ar function. The names in blue indicate items that belong to the getBoGo function. prLcLwg optLow w*vwber of wLwdows wLwd,ow prLce ts+elewed totaL owed -e# 1_boo.o f ft L5 3e# 2 WlW ,)a U lig:irrr: 3 il-fii Completed desk-check table for Lab 10-2's algorithms The fourth step in the problem-solving process is to code the algorithm into a program. The IpO chart information and C++ instructions for the program are shown in Figure lO-21. 351 352 Void Functions main function IPO chaft information lnout prtai.r"0, cFiLcr" '/.-/- //- C ai' cl'.,t tr"a cv t s '11i.y"j,9'11 pri.L2 Processing '"/u0,/v2 Output .-c--0.: c"tie1. Algorithm t caLL the dLspLagoptLows fv+wctLow to dLsTLag theprLcLwg oTtLows 2. get the prLcLwg optLow =. Lf (the yrLcLwg optLow Ls eLLher t- or z) main function C++ instructions int option = 0; int numordered = 0; double winPrice = 0.0i double totalowed = 0.0; displayOptionsO; cout < "pricing="" option?="" ";="" cin="">> option; if (optioh =: 1 | I option == 2) i cout < "number="" of="" windows:="" ":="" cin="">> numOrdered; cout < "price="" per="" window:="" ";="" ci="" n="">> wi nPri ce; if (option == 1) getRegul ar (numOrdered, wi nPri ce, total Owed) ; el se getBoco (numorde red , winPrice, totalOwed); / /end if cout < "total="" owed-----=""> $" < totalowed="">< endl="">< endl;="" ]="" el="" se="" cout="">< "invalid="" option"="">< endl;="" end="" if="" displayoptions="" fu="" nction="" g++="" instructions="" get="" the="" wuvv.ber="" of="" wlwdows="" awd="" the="" wlwd,ow="" prlce="" lf="" (tneprlclwg="" optlow="" ls="" t)="" c="" all="" th="" e="">< "pricing="" options:',="">< endl;="" cor.rt="">< "1="" regular="" pricing"="">< endl;cotlt="">< "2="" bogo="" pricing',="">< endl;="" getregular="" function="" c++="" instructions="" getregular="" function="" ipo="" chart="" information="" lnout="" wun*ber="" of="" wlwdows="" (format="" paranteter)="" wlwdow="" prlce="" (f="" orvv"al="" paran,-eter)="" address="" of="" a="" varlable="" to="" store="" the="" total="" ow="" ed="" (f="" orn="" "at="" paraw,eler)="" processing="" w0we="" int="" windows="" double="" price="" double="" &total="" outout="" total="" owed="" stored="" lw="" the="" total="" forn*al="" ayavwetey="" algorithm="" t.="" calcutlate="" total="" owed,="" :="" wxvuber="" of="" wlwd,ows="" *="" wlwdow="" prlce="" setbogo="" function="" ipo="" chart="" information="" lnput="" wu.wtber="" of="" wlwd="" ows="" (f="" orr*al="" paraw-eler)="" wlwdow="" vrlce="" fforw,al="" paravweter)="" total="windows" ,k="" price;="" getbogo="" function="" c++="" instructions="" int="" windows="" double="" price="" address="" of="" a="" varlableto="" store="" the="" total="" owed="" (forwtal="" paravueter)="" processing="" w0we="" double="" &total="" output="" total="" owed="" stored="" lw="" the="" total="" forvwal="" aravweter="" algorithm="" t.="" calctllale="" total="" owed,="" :="" (waw"ber="" of="" wlwdows="" 2="" +="" the="" rentalwder="" of="" w,twtber="" of="" wlwdows="" z)="" *="" wlwdow="" total="(windows/Z+" windows="" %21="" *="" price;="" trlce="" f:iq*re="" l*-?t="" lpo="" chart="" information="" and="" c++="" instructions="" for="" lab="" l0_2,s="" program="" void="" functions="" the="" fifth="" step="" in="" the="" problem-solving="" process="" is="" to="" desk-check="" the="" program.="" figure="" 10-22="" shows="" the="" entire="" program,="" and="" figure="" 10-23="" shows="" the="" completed="" desk-check="" table.="" lablo-z.cpp="" displays="" total="" owed="" 2="" created/revised="" by=""> on 3 4 5 6 7 8 9 t-0 11 L2 13 L4 L5 1_6 L7 18 1_9 ?o 2L 22 23 24 25 26 27 28 29 30 3l- 32 33 34 35 35 37 38 39 40 4L 42 43 44 45 46 47 48 49 50 51 52 53 54 #include #i nc1 ude

using namespace std; //function prototypes void display0ptionsO; voi d getRegul ar(i nt wi ndows , doubl e pri ce, doubl e &total ) ; void getBoGo(int windows, double price, double &total); int maino i int option = 0; int numOrdered = 0; double winPrice = 0.0i double totalOwed = 0.0; cout < fixed="">< setprecision(2);="" di="" spl="" ay0pti="" ons="" o="" ;="" cout="">< "pricing="" option?="" ";="" ci="" n="">> opti on; if (option == 1 { I I option == 2) cout < "number="" of="" windows:="" cin="">> numOrdered; cout < "price="" per="" window:="" ci="" n="">> wi nPri ce; i f (opti on == 1) getRegular(numOrdered, winPrice, totalOwed) ; el se getBoCo(numOrdered, wi nPri ce, totalOwed) ; //end if cout < "total="" owed-----=""> $" < totalowed="">< endl="">< endl;="" )="" el="" se="" cout="">< "invalid="" option"="">< endl;="" end="" if="" return="" 0;="" j="" end="" of="" main="" function="" -**-:t*xfuncti="" on="" defi="" ni="" ti="" ons*-:'r*'*-t="" void="" display0ptionso="" i="" cout="">< "pri="" ci="" ng="" opti="" ons="" :="" "="">< endl="" ;="" cout="">< "1="" regular="" pricing"="">< endl;="" cout="">< "2="" b0c0="" pricing"="">< endl;="" )="">
Answered Same DayApr 01, 2021

Answer To: Lab 10-2.pdf 347 Use the program to calculate the diameter for a circle whose radius is 25.7....

Samrakshini R answered on Apr 03 2021
131 Votes
#include
#include
using namespace std;
int main()
{
    for(int i=10;i<=13;i++)

    {
        cout<    }
    return 0;
}
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here