Title: ???? p??? ??t? S?ed?as
1???? p??? ??t? S?ed?asµ?? ?a? S??a?t?se??
- Top-Down Design
- afa??et???t?ta/a????s?
- S??a?t?se?? ???s?, S??ta?? ?a? S?µas?a
- ?a?aµet???
- ?p?st??f? t?µ??
- ?µße?e?a ?etaß??t??
2- ?a?? p??? ?at? S?ed?asµ?? d?e??????e? d?aspas? se
?p?p??ß??µata - ?fa??et???t?ta (abstraction) d?a????sµ?? a??µesa
st? t? ?a? t? p?? - A????t?? s?ed?asµ??(modular design)
- ?pa?a???s?µ?p???s? (reuse)
- ...
- S??a?t?se??
- ???a??sµ?? p?? ep?t?epe? st?? p????aµµat?st? ?a
???p???se? t?? d?aspas? se ?p?p??ß??µata
3?a?? p??? ?at? S?ed?asµ??
- ?????aµµa p?? d?aßa?e? e?a p?a?µat??? a???µ?,
?p??????e? t?? tet?a?????? d??aµ? t?? ?a? t??
t?p??e?
4?a??-???? ?at? S?ed?asµ??
main() / get input number / /
compute square power / / display input and
its square power /
??aspas? ???sµ?? t?? t? p?epe? ?a ???e? ??? p??
5include ltstdio.hgt include ltmath.hgt void main()
double number, square_power printf(Enter a
real number ) scanf(d, number) square_po
wer pow(number,2) printf(The square power of
e is e\n, number, square_power)
???ept??s?/???p???s?
6?fa??et???t?ta S????t?s??
include ltstdio.hgt include ltmath.hgt void main()
double number, square_power printf(Enter a
real number ) scanf(d, number) square_po
wer pow(number,2) printf(The square power of
e is e\n, number, square_power)
printf, scanf, pow ?e???µe t? ?a???? ??? p??
7S??a?t?se??
- S??a?t?se?? ??ß????????
- de? ??????ta? ap? t?? ???st?
- p? printf, scanf, pow
- e?s?µat?s? µe t? include
- S??a?t?se?? p?? ??????ta? ap? t?? p????aµµat?st?
(user defined functions)
8S??ta??
- ?a?e C p????aµµa ap?te?e?ta? ap? µ?a ?
pe??s?te?e? s??a?t?se?? - ?a?e p????aµµa e?e? µ?a s??a?t?s? main
- ?a?e s??a?t?s? p?epe? ?a ????eta?
- ??a s??a?t?s? p??? a?afe??e? p?epe? ?a ???s?e?
(defined) ? d????e? (declared) - ?e? ep?t?epeta? ?a ??a?eta? µ?a s??a?t?s? µesa se
a??? s??a?t?s?
9S??ta?? ???sµ?? S??a?t?s??
ltt?p?? ep?st??f??gt lt???µa s??a?t?s??gt(lt??sta
pa?aµet???gt) a??? t?? s??a?t?s?? d???se??
µetaß??t?? e?t??e? return lte?f?as?gt
te??? t?? s??a?t?s??
10S??ta??
- lt??p?? t?µ?? e??d??gt
- int, char, float, double, void, s???et??
- lt???µa S??a?t?s??gt
- s??ta?t??? ???? ???µa
- lt??sta ?a?aµet???gt
- ade?a ?
- t?p?? µetaß??t?, t?p?? µetaß??t?, .
11S????t?s? main ????? pa?aµet????
void main() printf(Hello out there!\n)
12S????t?s? ????? pa?aµet????
void display_six_stars() printf(\n)
void display_six_stars() printf(\n) r
eturn
13include ltstdio.hgt void display_six_stars() p
rintf(\n)
int main() display_six_stars() display_six_s
tars() return 0
14??e????? Fa???µe??(side-effect)
- ?? fa???µe?? p?? p???a?e? ? e?te?es? µ?a?
e?t????, s??a?t?s??, p????aµµat??... - ?a??? p????aµµat?sµ?? pe????afeta? µe s????a ta
side-effects ?a?e s??a?t?s?? p.?. - e?t?p?s? µ???µat??
- a??a?? t?? µetaß??t?? foo (eµße?e?a a???te?a)
- ?t?
15S??a?t?se?? µe ??a ?a?aµet??????? t?µ? e??d??
void display_area(float area) printf(The area
is f square meters\n,area)
16S??a?t?se?? µe ??a ?a?aµet??????? t?µ? e??d??
void compute_and_display_mod3(int
number) printf(dmod3 is d\n,number,
number3)
void compute_and_display_mod3(int number) int
mod3 mod3 number3 printf(dmod3 is d\n,
number, mod3)
17S????t?s? µe p???ap??? pa?aµ?t???? ????? t?µ?
e??d??
void display_area(float length, float width,
float area) printf(The area of a rectangle
with length f m and width f m is f sq.
m\n, length, width,area)
18S??a?t?se?? µe pa?aµet???? ?a?t?µ? e??d??
float compute_area(float a, float b) float
area area a b return area
19S??a?t?se??
float compute_area(float a, float b) return a
b
?p?st?efe? t?? t?µ? t?? e?f?as?? ab p?? e??a?
t?p?? float
20?a?aµ?t???
- ?p?t?ep??? t?? ep????????a (d?as??des?) µeta??
s??a?t?se?? (e?s?d? ?a? e??d? ded?µe???) - ??sta pa?aµet??? ????e? t?? a???µ?, se??a ?a?
t?p? t?µ?? p?? de?eta? µ?a s??a?t?s? - G?a e?s?d? pe?asµa d?a t?µ?? (t?µ?)
- G?a e?s?d?/e??d? pe?asµa d?a a?af??a?
(d?e????s?)- a???te?a
21S?µas?a ???s??
- ?esµe?s? µ??µ?? ??a pa?aµet???? ?a? t?p??e?
µetaß??te? t?? s??a?t?s?? (ea? ?pa?????) - ??t???af? t?? t?µ?? t?? ???sµat?? st??
pa?aµet???? (ea? ?pa????? pa?aµet???) - a???µ??, se??a ?a? t?p?? ???sµat?? ?a ta???a????
µe t?? a???µ?, se??a ?a? t?p??? t?p???? pa?aµet. - ?e???a e?te?es? ap? t?? p??t? e?t??? t??
s??a?t?s??
22S?µas?a ?p?st??f??
- ?p?t?µ?s? t?? e?f?as?? p?? a??????e? t? return
?a? a?t???af? t?? t?µ?? e??d?? st? s?µe?? ???s??
(ea? ep?st?efeta? t?µ?) - S??e??s? e?te?es?? µe t?? e?t??? p?? a??????e?
t?? ???s? - ?p?desµe?s? µ??µ?? p?? desµe????e ?ta? e???e
???s?. ?? a?t?st???e? µetaß??te? de? ?f?sta?ta?
p?e??
23include ltstdio.hgt float compute_area(float x,
float y) float compute_area(float a, float
b) return (a b) int main() float
length, width float area printf(Enter
length and width ) scanf(ff,length,
width) area compute_area(length,
width) printf(The area of a rectangle with dim
f by f m is f sq. m\n, length, width,
area) return(0)
p??t?t?p? s??a?t?s??
???sµ?? s??a?t?s??
???s? s??a?t?s??
24????s? S??a?t?s?? (function prototype)
- S??ta?? ???t?t?p?? S??a?t?s??
- ltt?p?? ep?st??f??gt lt???µa s??a?t?s??gt(lt??sta
pa?aµet???gt) - S?µas?a ep?t?epe? ???s? µ?a? s??a?t?s?? p???
a??µa ???s?e? - ?a??? p????aµµat?sµ?? ??sta µe p??t?t?pa ????
t?? s??a?t?se?? se e?a p????aµµa
25???t?t?pa S??a?t?se??
/ s????a / / include / / p??t?t?pa
s??a?t?se?? / / sta?e?e?/ / ???sµ??
s??a?t?se?? - µ?a e??a? ? main/
float compute_area(float length, float
width) void error_message_for_negative_input() i
nt get_grade(int student_id)
26include ltstdio.hgt int compute_sum(int x, int
y) int compute_sum(int a, int b) int
sum sum a b return sum int
main() int sum0 sum compute_sum(5,
4) printf(The sum of d and d is d\n,4, 5,
sum) return(0)
p??t?t?p? s??a?t?s??
???sµ?? s??a?t?s??
???s? s??a?t?s??
27include ltstdio.hgt int compute_sum(int x, int
y) int compute_sum(int a, int b) int
sum sum a b return sum int
main() int sum0 sum compute_sum(5,
4) printf(The sum of d and d is d\n,4, 5,
sum) return(0)
28include ltstdio.hgt int compute_sum(int x, int
y) int compute_sum(int a, int b) int
sum sum a b return sum int
main() int sum0 sum compute_sum(5,
4) printf(The sum of d and d is d\n,4, 5,
sum) return(0)
0
5
4
9
29include ltstdio.hgt int compute_sum(int x, int
y) int compute_sum(int a, int b) int
sum sum a b return sum int
main() int sum0 sum compute_sum(5,
4) printf(The sum of d and d is d\n,4, 5,
sum) return(0)
9
30include ltstdio.hgt int compute_sum(int x, int
y) void compute_sum(int a, int b) int
sum sum a b return sum int
main() int sum0 int a4, c6 sum
compute_sum(a, c) printf(The sum of d and d
is d\n,a, c, sum) return(0)
31?µß??e?a ?etaß??t?? (scope)
- ?? tµ?µa t?? p????aµµat?? p?? µp??e? µ?a
µetaß??t? ?a ???s?µ?p????e? - local (t?p??e?)
- d??????ta? st?? a??? e??? programming block ..
- ?p??d?p?te µeta t?? ???sµ? µesa st? block
- global (?a?????e?) - a???te?a
- d??????ta? e?? ap? s??a?t?se??
- ?p??d?p?te µeta t?? ???sµ?
32?a??de??µa
- G?a?ete µ?a s??a?t?s? µe t?? a??????? d?epaf?
- ? d?ad??as?a pa???e? µ?a pa?aµet?? t?? ??a (time)
se 24??? µ??f? ?a? t?p??e? t?? ??a ?a? ta ?epta
????sµe?a µe . ?.?. ea? ? t?µ? t?? pa?aµet???
e??a? 1256, ? e??d?? ?a e??a? The time is
1256
void display_time(int time)
33void display_time(int time) / compute hours
/ / compute minutes / / display
hoursminutes
void display_time(int time) int
hours,minutes / compute hours / hours time
/ 100 / compute minutes / minutes time
100 / display hoursminutes printf(The time
is 02d02d\n,hours, minutes)