程式结构进阶介绍课件.ppt

上传人(卖家):晟晟文业 文档编号:5205537 上传时间:2023-02-17 格式:PPT 页数:21 大小:57.27KB
下载 相关 举报
程式结构进阶介绍课件.ppt_第1页
第1页 / 共21页
程式结构进阶介绍课件.ppt_第2页
第2页 / 共21页
程式结构进阶介绍课件.ppt_第3页
第3页 / 共21页
程式结构进阶介绍课件.ppt_第4页
第4页 / 共21页
程式结构进阶介绍课件.ppt_第5页
第5页 / 共21页
点击查看更多>>
资源描述

1、Chapter 6程式結構進階介紹目標n函式指標n例外情形及例外處理n同名函式撰寫n函式樣板n組合多個函式成一完整程式函式指標n以指標儲存函式位址n傳回值型態 (*指標名稱)(參數列型態);nEx:qdouble(*pfun)(char*,int);qdouble*pfun(char*,int);函式指標初始值設定nlong sum(long num1,long num2);nLong(*pfun)(long,long)=sum;nornlong product(long,long);nLong(*pfun)(long,long);npfun=product;Example Ex6_01.cp

2、pfigure p208npdo_it(product(3,pdo_it(4,5),6);以函式指標為引數n函式的參數是函式指標nEx6_02.cpp函式指標陣列ndouble sum(double,double);ndouble product(double,double);ndouble difference(double,double);ndouble(*pfun3)(double,double)=sum,product,difference;函式參數初始化/EX6_03.CPPvoid showit(char*=Something is wrong.);int main(void)ch

3、ar*mymess=The end of the world is nigh.;showit();/Display the basic message showit(Something is terribly wrong!);/Display an alternative showit();/Display the default again showit(mymess);/Display a predefined message cout endl;return 0;void showit(char*message)cout endl message;return;例外情形n處理錯誤或非預期

4、狀況的機制覆載函式(function overloading)double maxdouble(double array,int len)double max=array0 doe(int i=1;ilen;i+)if(max arrayi)max=arrayi;retrun max;nhow about long,int,etc.覆載函式(cont.)n相同名稱的一系列函式n各有不同的參數列n注意!僅有傳回值不同,並不足以區分函式!Example Ex6_06.cppint max(int array,int len);/Prototypes forlong max(long array,i

5、nt len);/a set of overloadeddouble max(double array,int len);/functions覆載函式的意義n相同運算式使用相同函式名稱處理不同運算元qEx:“+”對int,long,double,n實質上相同,但引數型態不同,都應覆載,使用相同函式名稱函式樣板(Function Templates)n函式具有不同變數及參數型態n程式碼相同n一群特定程式碼n依照參數型態不同自動產生不同的版本使用函式樣板改寫 max()n關鍵字template表示樣板定義nn由樣板建立的函式實體稱為實例(instantiation)/Template for fu

6、nction to compute the maximum element of an arraytemplate T max(T x,int len)T max=x0;for(int i=1;ilen;i+)if(maxxi)max=xi;return max;Example Ex6_07.cpp#include using namespace std;/Template for function to compute the maximum element of an arraytemplate T max(T x,int len)T max=x0;for(int i=1;ilen;i+)

7、if(maxxi)max=xi;return max;int main(void)int small=1,24,34,22;long medium=23,245,123,1,234,2345;double large=23.0,1.4,2.456,345.5,12.0,21.0;int lensmall=sizeof small/sizeof small0;int lenmedium=sizeof medium/sizeof medium0;int lenlarge=sizeof large/sizeof large0;cout endl max(small,lensmall);cout endl max(medium,lenmedium);cout endl max(large,lenlarge);cout endl;return 0;Homeworknreading example p224239n6-1,6-2Chapter 7舊式Windows的滋味目標n結構n視窗基本架構nWindows APInWindows messagenWindows程式常用表示法nWindows程式基本架構

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 办公、行业 > 各类PPT课件(模板)
版权提示 | 免责声明

1,本文(程式结构进阶介绍课件.ppt)为本站会员(晟晟文业)主动上传,163文库仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。
2,用户下载本文档,所消耗的文币(积分)将全额增加到上传者的账号。
3, 若此文所含内容侵犯了您的版权或隐私,请立即通知163文库(发送邮件至3464097650@qq.com或直接QQ联系客服),我们立即给予删除!


侵权处理QQ:3464097650--上传资料QQ:3464097650

【声明】本站为“文档C2C交易模式”,即用户上传的文档直接卖给(下载)用户,本站只是网络空间服务平台,本站所有原创文档下载所得归上传人所有,如您发现上传作品侵犯了您的版权,请立刻联系我们并提供证据,我们将在3个工作日内予以改正。


163文库-Www.163Wenku.Com |网站地图|