design with structure charts. design process problem solving and design should be done independent...
TRANSCRIPT
![Page 1: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/1.jpg)
Design withStructure Charts
![Page 2: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/2.jpg)
Design Process
• Problem solving and design should be done independent of programming.
• Code significantly clouds the design process.. It is very difficult to see the design and address design issues when coding
• Design needs to take place in a mode which minimizes code influence
![Page 3: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/3.jpg)
4 Steps
Create a structure chart based on the main
item,NOT programming
requirements
1
Modify structure chart based on the programming requirements.
Top-down design.
2
Write code toimplement the
top-down design.As you mature thiswill be skipped by
going to step 4.
3
Improve readabililtyof the code by incorporating
functions.
4
![Page 4: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/4.jpg)
National Parcel ExampleExample 2 : Parcel Service Company.
Emphasizes IF notation for top down design.
National Parcel Service (NPS) specializes in nationwide delivery of small packages. NPS will not accept
any packages whose largest dimension is greater than 3 feet or whose weight exceeds 50 pounds.
The charge for shipping a parcel is $0.75 plus an amount based on package weight as follows:
Weight (lb.) Rate-----------------------------20 or less $0.08 per lb.40 or less $0.10 per lb.Over 40 $0.15 per lb.-----------------------------
There is an additional $1.00 charge if the volume of the package exceeds 18 cubic feet. Write a program
that will read the dimensions of a parcel (in feet) and its weight (in pounds) and then compute and print
the postage due. If the package is rejected, an appropriate message should be printed.
Example Test Data Length Width Depth Weight 1.5 1.2 0.8 6.0
![Page 5: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/5.jpg)
Parcel Delivery
National Parcel Service
Parcel *
Acceptable Not Acceptable
Shipping Status
Charge
Weight Charge Volume Charge 0.75
Wt<=20 20<Wt<=40 Wt>40 Vol<=18 Vol>18
WeightSize
Length Width Depth
![Page 6: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/6.jpg)
Change in Perspective
• Our natural view of the problem domain may not match the requirements.
• There are multiple views of anything.
• Other views are not wrong, but do provide insight into the structure we expect and perceive.
• In this problem we need to adjust for a single parcel.
![Page 7: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/7.jpg)
Parcel Delivery(adjust to one package)
Parcel
Acceptable Not Acceptable
Shipping Status
Charge
Weight Charge Volume Charge 0.75
Wt<=20 20<Wt<=40 Wt>40 Vol<=18 Vol>18
WeightSize
Length Width Depth
![Page 8: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/8.jpg)
TV SurveyExample 3 : Television Rating Service
Emphasizes WHILE notation for top down design
A television rating service makes a survey of the viewing audience to sample the popularity of tv shows.
When a call is made concerning a particular show, the sex and age of the person called, as well as whether
or not the person watches the program regularly, are recorded. Write a program that will process the data
gathered for the show. The total number of people called, the number who said they watched the show
regularly, and the percentage of those who watch the show on a regular basis should be printed. The
program should also print a table showing the percentages of those who watch the show by sex and age
categories. The output table should look something like the sample shown here.
SEX UNDER 18 18 to 35 36 to 55 OVER 55 ------------------------------------------------------------------MALE 12.2% 47.5% 34.3% 6.0%FEMALE 18.5% 32.4% 35.6% 13.5%------------------------------------------------------------------
![Page 9: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/9.jpg)
TV Survey
Survey
Call *
Regular Not Regular
Viewer StatusSex
Male Female
Age<18 18<=Age<36 Age>5536<=Age<55
Age
![Page 10: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/10.jpg)
Requirements demandadjusting view
• Sex and age are typically related only through the person, not as subcategories.
• This problem views them as subcategories of one another.
• It doesn’t make any difference which is a subcategory of the other.
• Next slide shows an adjusted view.
![Page 11: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/11.jpg)
TV Survey
Survey
Call *
Regular Not Regular
Viewer Status
Sex
Male Female
Same as MaleAge<18 18<=Age<36 Age>5536<=Age<55
![Page 12: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/12.jpg)
Step 2
Adapt the structure chart
to accommodate the
program specifications:
DO A TOP-DOWN DESIGN
![Page 13: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/13.jpg)
Parcel DeliveryAdjusting Structure Chart for Program (Top-Down) Design
Compute Postage
Acceptable Not Acceptable
Determine Acceptability
Compute Charge
ComputeWeight Charge
ComputeVolume Charge
ComputeTotal Charge
Wt<=20 20<Wt<=40 Wt>40 Vol<=18 Vol>18
WeightSize
Length Width Depth
Input Package Info
Output ChargeOutput Rejection
Message
Wt_chrg=Wt*0.08
Wt_chrg=Wt*0.1
Wt_chrg=Wt*0.15
Vol_chrg=0.0
Vol_chrg=1.0
Charge=Wt_Chrg+Vol_Chrg+
0.75
![Page 14: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/14.jpg)
TV SurveyStructure Chart Conversion to Top Down Design
Summarize Survey
Process Call *
Regular Not Regular
Process Regular Viewers
Sex
Male Female
Same as Malebut use WL18,
WL36,...
Age<18 18<=Age<36 Age>5536<=Age<55
Initializations Output Report
Calculate % Write ReportInput Call Info Count # of Calls
Count RegularViewer
IncrementML18
IncrementML36
IncrementML55
IncrementMG55
![Page 15: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/15.jpg)
Step 3
Write code to implement
the design
![Page 16: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/16.jpg)
#include <iostream.h>main (){ float length,width,height,weight,WtChrg, volume,VolChrg,TotalCharge; // input package information cout << " Enter length, width and height of package\n"; cin >> length >> width >> height; cout << " Enter weight of package\n"; cin >> weight; // determine acceptability if ( (length<3) && (height<3) && (width<3) && (weight<50)) { // ACCEPTABLE // COMPUTE CHARGE // WEIGHT CHARGE if (weight<=20) WtChrg = 0.08*weight; else if (weight<=40) WtChrg = 0.10*weight; else WtChrg = 0.15*weight; // VOLUME CHARGE volume = length*width*height; if (volume > 18.0) VolChrg = 1.0; else VolChrg = 0.0; // TOTAL CHARGE TotalCharge = 0.75 + WtChrg + VolChrg; // OUTPUT CHARGE cout << "Total charge for the package is " << TotalCharge << endl; } else // NOT ACCEPTABLE { cout << "Package EXCEEDS weight/size specs for shipment\n"; cout << "...... Try another company!"; } }
ParcelDelivery
Implementation
![Page 17: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/17.jpg)
#include <iostream.h>main (){ char sex, regular; float PercentRegular; int age, rv, tv, num_read, NumberToRead; int ml18,ml36,ml55,mg55,fl18,fl36,fl55,fg55; // initializations tv=0; rv=0; ml18=0;ml36=0;ml55=0;mg55=0; fl18=0;fl36=0;fl55=0;fg55=0; cin >> NumberToRead; num_read = 0;
while (num_read < NumberToRead) { // PROCESS CALL // input call information cin >> sex >> age >> regular; // count number of calls tv++; num_read++; // process regular viewer if ( (regular == 'R') || (regular == 'r')) { // count as a regular viewer rv++; // tabulate age/sex info if ( (sex == 'M') || (sex == 'm')) { // process Male if (age < 18) ml18++; else if (age < 36) ml36++; else if (age < 55) ml55++; else mg55++; } else { // process Female if (age < 18) fl18++; else if (age < 36) fl36++; else if (age < 55) fl55++; else fg55++; } } } // loop PercentRegular=rv / tv; // write reports to output device // ........} // end
TVSurvey
Implementation
![Page 18: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/18.jpg)
Step 4
Use FUNCTIONS to implement
the design
![Page 19: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/19.jpg)
// FUNCTIONSint Acceptable(float length, float height, float width, float weight){ return ( (length<3) && (height<3) && (width<3) && (weight<50) );} float WtChrg(float weight){ float wc; if (weight<=20) wc = 0.08*weight; else if (weight<=40) wc = 0.10*weight; else wc = 0.15*weight; return wc;} float PackageVolume(float length, float height, float width){ return length*height*width;} float VolChrg(float v){ float vcharge; if (v > 18.0) vcharge = 1.0; else vcharge = 0.0; return vcharge;} void Reject() { cout << "Package EXCEEDS weight/size specs for shipment"; cout << " ...... Try another company!"; }
#include <iostream.h>
// PROTOTYPESint Acceptable(float length, float height, float width, float weight);
float WtChrg(float weight);
float PackageVolume(float length, float height, float width);
float VolChrg(float v);
void Reject();
// MAIN ROUTINEmain (){ float length,width,height,weight,volume,TotalCharge; // input package information cout << " Enter length, width and height of package\n"; cin >> length >> width >> height; cout << " Enter weight of package\n"; cin >> weight; // determine acceptability if ( Acceptable(length,height,width,weight)) { // ACCEPTABLE volume = PackageVolume(length,width,height); TotalCharge = 0.75 + WtChrg(weight) + VolChrg(volume); cout << "Total charge for the package is " << TotalCharge << endl; } else // NOT ACCEPTABLE Reject(); }
Parcel DeliveryImplementation
w/functions
![Page 20: Design with Structure Charts. Design Process Problem solving and design should be done independent of programming. Code significantly clouds the design](https://reader035.vdocument.in/reader035/viewer/2022080916/56649e4e5503460f94b45022/html5/thumbnails/20.jpg)
TV SurveyImplementation
w/functions
It’s Your Turn!