欢迎来到天天文库
浏览记录
ID:1391372
大小:211.00 KB
页数:42页
时间:2017-11-11
《或物件所属的空间名称》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、ObjectorientedprogrammingWhatisClass?WhatisObject?Fromobject-orientedpointofviewClassisauser-defineddatatypewhichcontainsrelevantdataandfunctionsObjectisavariabledeclaredundersomeclassdatatypeFromphilosophyconceptClassisanabstractconceptthatdescribestheattributesofacollec
2、tionofobjects1FromCtoC++Namespace變數、函數、或物件所屬的空間名稱,在不同的namespace中可使用相同的變數名稱。std:C++所有系統提供的函數所屬的namespaceavoidconflictofvariablenamesinthedifferentclasslibraries2namespaceexample//Thisprogramoutputsthemessage////C++:onesmallstepfortheprogram,//onegiantleapfortheprogrammer//
3、//tothescreen#includeusingnamespacestd;intmain(){cout<<"C++:onesmallstepfortheprogram,"<<"onegiantleapfortheprogrammer";return0;}comparetoC:#includemain(){printf(“….”);withoutnamespace3namespacescreatenamespaceexamples:namespacemfc{intinflag;voidg(i
4、nt);…}namespaceowl{intinflag;…}4namespaceusevariablesinanamespaceusescoperesolutionoperator::e.g.mfc::inflag=3;owl::inflg=-823;cout<5、tandardinputcoutstandardoutputcerrstandarderrore.g.cin>>x;cin>>len;cout<>x>>len;cout<usingnamespacestd;intmain(){intid;floatav;cout<<“Entertheidandtheaverage:”;cin>>id>>av;cout<<“Id:”<6、7、8、mal)i=91(decimal)10manipulatorslistedinchap.14-9dec,endl,fixed,flush,hex,left,oct,right,scientif
5、tandardinputcoutstandardoutputcerrstandarderrore.g.cin>>x;cin>>len;cout<>x>>len;cout<usingnamespacestd;intmain(){intid;floatav;cout<<“Entertheidandtheaverage:”;cin>>id>>av;cout<<“Id:”<6、7、8、mal)i=91(decimal)10manipulatorslistedinchap.14-9dec,endl,fixed,flush,hex,left,oct,right,scientif
6、7、8、mal)i=91(decimal)10manipulatorslistedinchap.14-9dec,endl,fixed,flush,hex,left,oct,right,scientif
7、8、mal)i=91(decimal)10manipulatorslistedinchap.14-9dec,endl,fixed,flush,hex,left,oct,right,scientif
8、mal)i=91(decimal)10manipulatorslistedinchap.14-9dec,endl,fixed,flush,hex,left,oct,right,scientif
此文档下载收益归作者所有