




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、三程序分析题 阅读以下程序 ,写出其运行结果1。#i nclude < io strea m> using namespace std; int a 10 : = 1, 2 ,3, 4, 5, 6, 7,8, 9, 1 0 ;int fun( int i ); void main() int? for(i ,s = 0;i = 0; i < =10;i+)tr yscatch( int<<s + f un( i );"s =”数组下标越界!" endl; s < e ndl;int funifint i )= 10)return ai;t
2、hrow2。#in c lu d eiostreamu sin g name sp ace stdVoid f();clas s T pu b lic:T? try)cout <<” con true t oendl;? cat c hthrowT throwcharII;V oid ma i cout exception”; )cout <<exceptionexcepit on2”< < e n d 1; cout <<” de tru c to r" n()"main f try f() ; catch( char co
3、utcout << "maivoid f()3. # i n clude <iostream>unction”<endl;)< "exception1" in function<”<< end1; endl;T t;u s i ng namespace s td;class Bclass p ub lic:Bc lass( int i, int j ) x = i ; y =? V ir tual int f un() r e tur n 0 ; pr otec ted:int x, y ;class Ic1
4、ass:p ub lic Bclass p ub1 ic :? I class( i nti, in t j, int k): Bcla s s(i,int fun() return ( x + y + z ) / 3; private :int z ;;voi d mai n() I c l a ss obj( 2, 4, 10 );Bc lass p 1 = obj;cout p1、fun( ) < end1 ;Bc1a ss & p2 = obj ;co ut < p 2、fun()<< end l;? cout < p2、Bc las s : fu
5、n() << endl;Bclas s * p3 =& o bj;? cout << p3 > fu n( ) end1 ;4。#i n cl ud e <i ost ream>ace s td;j;j) zk; u sing namesp c1a s s BASE public:V i r tual voi V irtua 1 ?prote cted :? int x , y;d getx y( i n t i, int j = 0 ) VO id fun() = 0; x = i; y = j; ”<1 ass A: pub 1 ic
6、 B A SEp ub 1 ic:void fun() cou t <”x *x<< en dl;x= " << x'"y = x x; class B: publi c BASE p u blic:voi d f u n() co ut” x =< X <''< < ” 尸"< < y <<en dl;5、V i函数:b2(a),? c ou t " y ;V oi d m ain () B ASE 衣? A obj l ;pb ); P b - x
7、/ y < endl;pb ;B ob j 2 ; pb = & obj l ; fun(); pb = o bj2; fun( );#i nclu de Viostreamu s i ng n am e sp ace s td;c la s s B ASE1 pu blic:?BAS E1( intend l ; ;class BAS E2 pub li c: B A SE2(" V j V endl ;cla ss A:blpubA(d)endl; 6、P bpbi ) cout << ”调用基类getxy( l 0 ); getxy( 100,2BAS
8、E1 得构造函数: "in t j ) cou t <”调用基类BAS E2得构造 p ublic B AS E1, pub l i c BA S E2 lie : int a, i nt b,int c, i nt d):BA S E2(b), B A S El (c ), cout"调用派生类A 得构造函数 :" abcdp rivat e: ? BAS ElBAS E2;voi d m ain( ) A obj( 1, 2,3b 1;b2;, 4 );#inclu de ios tream> us ing nam espa ce std ; cl
9、ass T publi c :T() a = 0; b =T( i nt i , intj , a = i; b =jvoid get( i n i = a;T op erat or *(p riv at e: int a , b , c;0; nt c = itjT o bj );ck ) k; , i nt &j , in t &k ) b; k = c; 0; <<v2;TtemPT:operatortemPobj;b j、a = a *tempobj、b = bobj、a;* obj、b; obj、c;vot em pobj、c = c return tem
10、 p o bj;id main()T obj1( 1,2,3 ), obj2 (5,5 int aobj3 bj3、 ut7、n dl ;,5 ), obj 3;oco, b , c;=obj1 衣 obj2; get( a, b,c ); "( obj1 * obj2<< ”a = " << a < 't' 't' < endl;<(obj2 * o bj3 )、 g et( a, b, cout <”(obj2 * obj3): a= "< at' <<
11、endl;# i n c l u de <ios t reamus i ng na mesp ace s td; class vectorp u b 1 i c :V ector。V ect or(in x =frie n d): t”<< "b = "<<c ); t ”<< / t,<< " bt i, i n t j)i ; y = j ; ve c to r op era tor +(vect o rIIv1b 't'<< b< ”c vector temPVector
12、; te mpvec tor、x = v1、x tempVector、y = V1、 y returnvoid display () cout tempvector ;ivate:int x;vov ec torcout << "v1 =idmain()v 1v 2、xv 2、"( " < x < ",”)”<< e(1,2 ), v 2( 3, 4 ), V 3 ;V 1、 dis play();cout< " V 2 = ”v2、 di sp lay() ;v3 =coutV 3、8. #inc l
13、udev1 + v 2;” 3= V 1 + v2 ="sp lay ();<i o st ream>st ructd atai nt n ;i ntsco re ;voidmaind ataa 3using namespace sdt ;)= 100 0 ,83 ,1005,70, 100 9, 95 , * p = a ; c out <<(p+ +) score << endl ;co u t << (p+ +)> score endl ;co ut< p-> scor e << e nd1 ;<
14、;< e nd1 ;9。endl;cout (*p)、 sco re +in clude iostr eam >usin g n ame space sd ;class A pu blic : int f1();i nt f2 ();void setx( int m ) void setint getX ()int get y( ) private :int x, y ;re turn x ; ret urn y ; co ut << x < < endl; y = n ; cout << y <<iint A:f2() retuvo
15、 id main() A a ;a、 setx( 10 )cout << a、nt A::f1() re turn x + y ; ?r n x - y;?;a、 sety ( 5 );g etx()< 't '<'t <<cout <<a、 f1 ( )1O.#inclu d e <iostr e amusin g n amesp ace st d;< a、getyO << end 1 ;a、f2 () << endl ;c lass T P uT? cb lic :(in t X,
16、int y ) a = x ; b = y ;o ut <"调用构造函数2、"cout a<< t' b <<e nd 1endl ;< endl ; b << e ndl ;T( T d ) cou t < cout d、调用构造函数 1、 " a < < 't' d、?T?intp r i V ate :) coua dd(t < "调用析构函数、 i nt x, i n t y = 1 <endl;) ret urn x + y ; int a ,
17、 b ;V oid m ain() T d1( 2, 4T d2( d1c out11.in clude) ;< < d2、add( 8) < Vio s tream>using namespa ce std;c la ss T public :T (i n t x) a = x; b+=x; ;s tati c void display(T c)?c ou t< "a=< c、 a<end l ;t '<” b"c、b « endvate:pra;?int?stati c i nt b ; ;int T::
18、b =5;voi d m ain() T A(3),B (5 );T: :di splay( A);? T:di splay(B) ;1 2. # in c1u d e <iostream>using n ame sp ace std ;c 1 ass A pub lic :? A() a = 25 ; void printa() cout << ”Aa: = ” private:int a ;friend ;clacl a ss B ;< endln dl1 3、usis s Bpub1iV oid; ; voic:d isplay 1 ( A t )t、a +
19、 ; cout <<”dsi play1:a = " <void t、dis play 2( A t )a - ; cout << "disp1ay2:a = "d ma i n ()A ob j1 ; obj2 ;Bobj1、printa() ; ob j 2、display1( obj1 ) obj2、di obj1、prispl ay2( obj 1 ) nta() ;t、<<a <<t、aend#include ng c1ass A pub1ic:<iostream> namespace s
20、td;A( )A (cout co"A"<<< "A”e ndl; < e nd l;class B public: Bvirtual void Virtual B( ) f(f () c);outcoutcout <<<< "B”"B"<< en”B:f" <<<< endl; dl; endl;;c 1 asspub 1iD:p ublic B c :D(vo)dfvi r tualprivate:A a;void main( ) cou t << "D ”<< end1 ;) cout << "D:f" << end
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 对话与交流中的艺术教育方法计划
- 学校教学工作规划计划
- 一起开公司合同(2025年版)
- 咖啡产业品牌发展策略计划
- 视讯教学与远程教育方案计划
- 年度合规与风险管理的重点计划
- 2025年乌兰察布a2货运从业资格证模拟考试
- 2025年舟山货运上岗证模拟考试
- 2025年各种气象要素智能传感器项目发展计划
- 2024-2025学年河南省许昌市禹州市第三高级中学高一上学期12月月考生物试卷
- 总包单位向各分包移交建筑一米线交接单
- 某隧道仰拱栈桥施工方案
- DB37∕T 5197-2021 公共建筑节能监测系统技术标准
- 门诊特定病种待遇认定申请表
- 手卫生知识培训PPT课件下载
- 钢结构设计总说明(新版)
- 码头基本建设程序审批流程图
- (完整版)六宫格数独100题
- 摄影基础入门—摄影教学课件ppt课件(带内容)
- PP或PE塑料袋质量检验标准
- 幻想水浒传2怪物掉落
评论
0/150
提交评论