- 1、本文档共677页,可阅读全部内容。
- 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
#include iostream.h int fib(int n); int main() {int n, answer; cout Enter number: ; cin n; cout \n\n; answer = fib(n); cout answer is the n th Fibonacci number\n; return 0; } int fib (int n) { cout Processing fib( n )... ; if (n 3 ) {cout Return 1!\n; return (1); } else {cout Call fib( n-2 ) and fib( n-1 ).\n; return( fib(n-2) + fib(n-1)); } } 例3-14 3-15 例 3-16 #include iostream.h templatetypename T void swap(Tx,Ty) { T z; z=x;x=y;y=z; } void main() { int i=1,j=2; double v=3.0,w=4.0; cout i=i j=jendl; cout v=v w=wendl; swap(i,j); swap(v,w); cout After swao: endl; cout i=i j=jendl; cout v=v w=wendl; } void swap(int x, int y) { int z; z=x;x=y;y=z; } #includeiostream.h #includemath.h double fx(double x); void main() { double x=3.14159/4; coutthe result isfx(x)endl; } 用牛顿法求:f(x)=cos(x)-x Xn+1=Xn+cos(Xn)-Xn)/sin(Xn)+1 初值为:3.14159/4 double fx(double x1) { double x0; do { x0=x1; x1=x0+(cos(x0)-x0)/(sin(x0)+1); }while( fabs(x1-x0)1e-6 ); return x1; } 习题课 (第四章) 4_5 4_7 4_8 #includeiostream.h class Dog {public: Dog(int initialAge,int initialWeight); ~Dog(){} int GetAge(){return itsAge;} void SetAge(int age){itsAge=age;} int GetWeight(){return itsWeight;} void SetWeight(int weight){itsWeight=weight;} private: int itsAge,itsWeight; }; Dog::Dog(int initialAge=0,int initialWeight=5) { itsAge=initialAge; itsWeight=initialWeight; } void main() { Dog Jack(2,10); coutJack is a Dog who is ; coutJack.GetAge() years old and; coutJack.GetWeight() pounds weight.\n; Jack.SetAge(7); Jack.SetWeight(20); coutNow Jack is ; coutJack.GetAge() years old and; coutJack.GetWeight() pounds weight.\n; } 4_9 #includeiostream.h class Rectangle {public: Rectangle(int top,int left,int bottom,int right); ~Rectangle(){} int GetTop(){return itsTop;} int GetLeft(){return itsLeft;} int GetBottom(){return itsBottom;} int GetRight(){return itsRight;} void SetTop(int top){its
文档评论(0)