Title: Linear Control By Example
1Lecture 7 ????????
2???? ??????????????????????????? ???????????????
??????????????????????????????????????
???????????? ??????????????????????????????????
???? ???????????????????????????
????????(Function) ??????????????????? 1.
??????????????????????????????? 2.
????????????????? 3. ????????????? ?. ?????????
??????????????? 4. ???????????????
?????(Module)????????????(Function)
????????????????????????????
3OBJECTIVE 1. ???????????????(Standard
Functions) 2. ??????????????????????(User-defined
Functions) - ??? Test Driver -
???????????????????????? 3. ???????????????????(O
verloading Function)
4?????????? 2 ???? 1. ???????????????(Standard
Functions) ??????????????????????????????????Compl
ier ??????????????????????????????????????????????
???????????????? ?????????????????
??????????????????? module ???? header file ??
???????????????????? include ?????????????????????
2. ??????????????????????????(User-define
Functions) ???????????????????????????????????????
???? ?????????????????????????????????????????????
????????? ??????????????????????????????????????
include ??????????????????????????????????????????
?
57.1 ???????????????????????
????????????????????????????????????????????????
???????????????????????????????
??????????????????????????????????????????????????
? library ???????????????? include
ltiostream.hgt include ltmath.hgt int main()
for (int i 0 i lt 6 i) cout ltlt i ltlt
"\t" ltlt sqrt(i) ltlt endl return 0 ????????
sqrt() ??????????????????????? ???????????????????
??????????? C ??? C ????????????????????????????
?????????????????? include ltmath.hgt???? include
math.h ??????????????????
6?????????? math.h ??????
abs Return absolute value of int acos
Calculate arccosine asin Calculate arcsine atan,
atan2 Calculate arctangent atof Convert
character string to double-precision
floating-point value cos Calculate
cosine cosh Calculate hyperbolic
cosine sin Calculate sine sinh Calculate
hyperbolic sine exp Calculate exponential
function fabs Find absolute value log Calculate
natural logarithm log10 Calculate base-10
logarithm pow Calculate value raised to a power
7??????????????????? library ??????????? C
ltmath.hgt ???????????????????????? ltstdio.hgt
?????????????????????????????????????????????????
ltstringh.hgt ?????????????????????????????????????
??? lttime.hgt ??????????????????????????? ltctype.h
gt ?????????????????????????????????? ltiostream.hgt
?????????????????????????????????????????????
8ltassert.hgt -- for enforcing assertions when
functions executeltctype.hgt -- for classifying
characterslterrno.hgt -- for testing error codes
reported by library functionsltfloat.hgt -- for
testing floating-point type propertiesltlimits.hgt
-- for testing integer type propertiesltlocale.hgt
-- for adapting to different cultural
conventionsltmath.hgt -- for computing common
mathematical functionsltsetjmp.hgt -- for
executing nonlocal goto statementsltsignal.hgt --
for controlling various exceptional
conditionsltstdarg.hgt -- for accessing a varying
number of argumentsltstddef.hgt -- for defining
several useful types and macrosltstdio.hgt -- for
performing input and outputltstdlib.hgt -- for
performing a variety of operationsltstring.hgt --
for manipulating several kinds of
stringslttime.hgt -- for converting between
various time and date formatsltwchar.hgt -- for
manipulating wide streams and several kinds of
stringsltwctype.hgt -- for classifying wide
characters
97.2 ?????????????????????????
????????????????????????????????????????????????
? ???????????????????????? ???????????????????????
??????? ??????? ????C ???????????
??????????????????????????
??????????????
???????????????????? ?????????????(???????????????
????? ??????) ?????????????????????
Local statement statement return
????????????????
10????????
include ltiostream.hgt include ltmath.hgt int
cube(int x) //declare function int
main(void) int ans anscube(5) coutltlt"Resul
t is "ltltansltltendl return 0 int cube(int
x) int result //local variable result
xxx return result
11- ??????????????????(Test Driver)
???????????????????????????????????????????
??????????????????????????????????????????????????
?????????????(Test driver) ???????????????????????
???? ????????????????????????????????????????????
?????? ???????????????????????????????????????????
????????????????????
12??????????? Test Driver
include ltiostream.hgt include ltmath.hgt int
cube(int x) //declare function int
main(void) int ans cin gtgtans //recive value
to ans anscube(5) //test Driver function
cube() by 5 coutltltans return 0 int
cube(int x) int result //local
variable result xxx return result
13- ???????????????????????????????????
?????????????????????????????????? 2????
1.????????????????????? (pass by value)
2.??????????????????(pass by reference) ?????????
???????????? ???????????????????????????????????
????????? ?????????????????????
?????????????????????????????(address)
????????????????????????? ????????????????????????
??????????????????????? ????????????? C
??????????????????? 1 ??? ????????????????????????
??????????????????????????? 1 ???
14?????????????????????????????(???1) ?????? C ???
C
include ltiostream.hgt void divide(int data1)
//declare function void main(void) //main
function int a1 a1 20 divide(a1) coutltlta1
ltltendl void divide(int data1)
//function data1 data1/4
15?????????????????????
a1
data1
0x001120
20
?????? a1
???data ?????????????? a1
0x001120
Address ??? a1
data1
include ltiostream.hgt void divide(int data1)
//declare function void main(void) //main
function int a1 a1 20 divide(a1) coutltlta1
ltltendl void divide(int data1)
//function data1 data1/4
16?????????????????????????????(???2) ??????
?????C
include ltiostream.hgt void divide(int data1)
//declare function void main(void) //main
function int a1 a1 20 divide(a1) coutltlta1lt
ltendl void divide(int data1)
//function data1 data1/4
17- ?????????????????????????????
??????????????????????????????????????????????????
? void ????????????????????????????????????????
1.????????????????????????????????????
void ?????????????(????????????????????
??????)
2.????????????????????????????????????
??????????????????? ?????????????(void)
183.????????????????????????????????????????????????
?
void ?????????????(void)
???????????? 3 ???????????????????????????
????????????????????????????????????
????????????????? Gobal ??????????????????????????
?????? ????????????????????????????????? Gobal
19??????????????????????????????????????????????????
??
include ltiostream.hgt void max(float dat1,float
dat2) //declare function void main(void)
//main function float a1,b1 coutltltType a1
cingtgta1 coutltltType b1 cingtgtb1 max(a1,b1)
void max(float dat1,float dat2)
//function if(dat1gtdat2) coutltltdat1ltlt Max
thanltltdat2ltltendl else coutltltdat1ltlt a1 Less
Than or Equalltltdat1ltltendl
20??????????????????????????????????????????????????
??
include ltiostream.hgt char Sex(void) //declare
function void main(void) //main function char
dat1 dat1Sex() //call function
coutltlt"Your sex is "ltltdat1ltltendl switch(dat1)
case 'f' case 'F' coutltlt"Your Female \n"
break case 'm' case 'M' coutltlt"Your
Male\n" break char Sex(void) //sub
function char sex coutltlt"What your sex (f/m)?
" cingtgtsex return sex
21??????????????????????????????????????????????????
include ltiostream.hgt void Name(void)
//declare function char name20 //gobal
variable 20 character void main(void) //main
function Name() coutltlt Your name is ltlt
name ltlt endl void Name(void) //sub
function coutltlt What your name ? cin gtgt
name
?????????????????? ??????????????? gobal
227.3 ???????????????????????
???? C ?????????????????????????????????????????
??????????????????????????????????????????????????
??? ??????????????????????????????????????????????
??????????????
23???????????????????????????????
include ltiostream.hgt int max(int, int) double
max(double, double) int main() cout ltlt
max(99,77) ltlt " " ltlt max(3.4,7.2) ltlt endl
return 0 int max(int x, int y) return (x
y) double max(double x, double y)
return (x - y)
24Inclass Lab1
??????????????????????????????? min() ????????
?????????????? min(int,int) ??????????????????????
?????????????????????????????? 2 ????? int
min(int x , int y) ??????????????? Test Driver
???????????????????
25Inclass Lab2
??????????????????????????????? GetRadius()
???????? ?????????????? GetRadius(void)
??????????????????????????????????????????????????
????????????????????????? main() int
GetRadius(void) ??????????????? Test Driver
???????????????????
26Inclass Lab3
??????????????????????????????? ComputeCircle()
???????? ?????????????? ComputeCircle()
???????????????????????????????
??????????????????? ?????????????????? ???
???????????? ?????????????? void
ComputeCircle(float r , float Area , float
Circle) ??????????????? Test Driver
???????????????????