《面向?qū)ο蟪绦蛟O(shè)計(jì)c》綜合復(fù)習(xí)題集及答案詳解_第1頁(yè)
《面向?qū)ο蟪绦蛟O(shè)計(jì)c》綜合復(fù)習(xí)題集及答案詳解_第2頁(yè)
《面向?qū)ο蟪绦蛟O(shè)計(jì)c》綜合復(fù)習(xí)題集及答案詳解_第3頁(yè)
《面向?qū)ο蟪绦蛟O(shè)計(jì)c》綜合復(fù)習(xí)題集及答案詳解_第4頁(yè)
《面向?qū)ο蟪绦蛟O(shè)計(jì)c》綜合復(fù)習(xí)題集及答案詳解_第5頁(yè)
已閱讀5頁(yè),還剩53頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、精選優(yōu)質(zhì)文檔-傾情為你奉上面向?qū)ο蟪绦蛟O(shè)計(jì)綜合復(fù)習(xí)題集 四、程序填充1. 斐波那契數(shù)列的第1和第2個(gè)數(shù)分別為0和1 ,從第三個(gè)數(shù)開(kāi)始,每個(gè)數(shù)等于其前兩個(gè)數(shù)之和。求斐波那契數(shù)列中的前20個(gè)數(shù),要求每行輸出5個(gè)數(shù)。#include<iostream.h>void main() int f,f1,f2,i; cout<<” 斐波那契數(shù)列:n”;f1=0; f2=1;cout<<setw(6)<<f1<<setw(6)<<f2;for(i=3;i<=20;i+) f=_(1)_; cout<<setw(

2、6)<<f;if(_(2)_) cout<<endl;f1=f2;f2=_(3)_; cout<<endl; (1) (2) (3) 2. 計(jì)算的值。 #include<iostream.h> void main() double x,p1=1,p2=1,s=0; int i,j=1; cout<<"輸入x的值:"cin>>x; for(i=1;i<=10;i+) p1*=_(1)_; p2*=_(2)_; s+=j*p1/p2; /j的值為(-1)i+1 j=_(3)_; cout<<

3、;s<<endl; (1) (2) (3) 17. 假定有定義為“struct NODEint data; NODE* next;”,下面算法根據(jù)table數(shù)組中的n個(gè)元素建立一個(gè)表頭指針為L(zhǎng)的鏈表,鏈表中結(jié)點(diǎn)值的順序與數(shù)組元素值的順序相同。void f5(NODE*& L, int table, int n) if(n<=0) L=NULL; return;L=new NODE; /生成附加的頭結(jié)點(diǎn)int i=0; NODE* p=L;while(_(1)_) p=p->next=_(2)_;p->data=_(3)_;i+;p->next=NUL

4、L; /把最后一個(gè)結(jié)點(diǎn)的指針域置空p=L;L=L->next; /使L指向鏈表的第一個(gè)帶值的結(jié)點(diǎn)delete p;(1)(2)(3) 22. 已知一維數(shù)組類ARRAY的定義如下,構(gòu)造函數(shù)的作用是把參數(shù)n的值賦給s,給v動(dòng)態(tài)分配長(zhǎng)度為n的數(shù)組空間,接著利用數(shù)組參數(shù)a初始化v所指向的數(shù)組。class ARRAY int *v; /指向存放數(shù)組數(shù)據(jù)的空間int s; /數(shù)組大小 public: ARRAY(int a, int n); ARRAY()delete v; int size() return s; int& operator(int n); ;_(1)_ ARRAY(int

5、 a, int n)if(n<=0) v=NULL;s=0;return;s=n;v=_(2)_;for(int i=0; i<n; i+) _(3)_;(1)(2)(3)24. 已知一個(gè)類的定義如下:#include<iostream.h>class AA int a10;int n;public:void SetA(int aa, int nn); /用數(shù)組aa初始化數(shù)據(jù)成員a, /用nn初始化數(shù)據(jù)成員nint MaxA(); /從數(shù)組a中前n個(gè)元素中查找最大值void SortA(); /采用選擇排序的方法對(duì)數(shù)組a中前n個(gè)元素 /進(jìn)行從小到大排序 void Ins

6、ertA();/采用插入排序的方法對(duì)數(shù)組a中前n個(gè)元素進(jìn)行從小到大排序void PrintA(); /依次輸出數(shù)組a中的前n個(gè)元素;該類中MaxA()函數(shù)的實(shí)現(xiàn)如下,請(qǐng)?jiān)跇?biāo)號(hào)位置補(bǔ)充適當(dāng)?shù)膬?nèi)容。int _(1)_ int x=a0;for(int i=1; i<n; i+) if(ai>x) _(2)_;_(3)_;(1) (2) (3)25. 已知一個(gè)類的定義如下:#include<iostream.h>class AA int a10;int n;public:void SetA(int aa, int nn); /用數(shù)組aa初始化數(shù)據(jù)成員a, /用nn初始化數(shù)據(jù)成

7、員nint MaxA(); /從數(shù)組a中前n個(gè)元素中查找最大值void SortA(); /采用選擇排序的方法對(duì)數(shù)組a中前n個(gè)元素 /進(jìn)行從小到大排序 void InsertA();/采用插入排序的方法對(duì)數(shù)組a中前n個(gè)元素進(jìn)行從小到大排序void PrintA(); /依次輸出數(shù)組a中的前n個(gè)元素;void AA:SortA()int i,j;for(i=0; _(1)_; i+) int x=ai, k=i;for(j=i+1; j<n; j+)if(aj<x) _(2)_ak=ai;_(3)_;(1) (2) (3)26. 已知一個(gè)類的定義如下:#include<iost

8、ream.h>class AA int a10;int n;public:void SetA(int aa, int nn); /用數(shù)組aa初始化數(shù)據(jù)成員a, /用nn初始化數(shù)據(jù)成員nint MaxA(); /從數(shù)組a中前n個(gè)元素中查找最大值void SortA(); /采用選擇排序的方法對(duì)數(shù)組a中前n個(gè)元素 /進(jìn)行從小到大排序 void InsertA();/采用插入排序的方法對(duì)數(shù)組a中前n個(gè)元素進(jìn)行從小到大排序void PrintA(); /依次輸出數(shù)組a中的前n個(gè)元素;void _(1)_ int i,j;for(i=1; i<n; i+) int x=ai;for(j=i-

9、1; j>=0; j-)if(x<aj) _(2)_;else _(3)_;aj+1=x;(1) (2) (3)27. 已知一個(gè)類的定義如下:#include<iostream.h>class AA int a10;int n;public:void SetA(int aa, int nn); /用數(shù)組aa初始化數(shù)據(jù)成員a, /用nn初始化數(shù)據(jù)成員nint MaxA(); /從數(shù)組a中前n個(gè)元素中查找最大值void SortA(); /采用選擇排序的方法對(duì)數(shù)組a中前n個(gè)元素 /進(jìn)行從小到大排序 void InsertA();/采用插入排序的方法對(duì)數(shù)組a中前n個(gè)元素進(jìn)行從

10、小到大排序void PrintA(); /依次輸出數(shù)組a中的前n個(gè)元素 /最后輸出一個(gè)換行;使用該類的主函數(shù)如下:void main()int a10=23,78,46,55,62,76,90,25,38,42;AA x;_(1)_;int m=_(2)_;_(3)_;cout<<m<<endl;該程序運(yùn)行結(jié)果為:23 78 46 55 62 7678(1) (2) (3)28. 已知一個(gè)類的定義如下:#include<iostream.h>class AA int a10;int n;public:void SetA(int aa, int nn); /用

11、數(shù)組aa初始化數(shù)據(jù)成員a, /用nn初始化數(shù)據(jù)成員nint MaxA(); /從數(shù)組a中前n個(gè)元素中查找最大值void SortA(); /采用選擇排序的方法對(duì)數(shù)組a中前n個(gè)元素 /進(jìn)行從小到大排序void PrintA(); /依次輸出數(shù)組a中的前n個(gè)元素, /最后輸出一個(gè)換行;使用該類的主函數(shù)如下:void main()int a10=23,78,46,55,62,76,90,25,38,42;_(1)_;x.SetA(a,8);int _(2)_;_(3)_;x.PrintA();cout<<m<<endl;該程序運(yùn)行結(jié)果為:23 25 46 55 62 76 7

12、8 9090(1) (2) (3) 29. 已知一個(gè)利用數(shù)組實(shí)現(xiàn)棧的類定義如下:const int ARRAY_SIZE=10;class Stack public:void Init() top=-1; /初始化棧為空 void Push(int newElem); /向棧中壓入一個(gè)元素int Pop(); /從棧頂彈出一個(gè)元素bool Empty() /判???if(top=-1) return true;else return false;int Depth() return top+1; /返回棧的深度void Print(); /按照后進(jìn)先出原則依次輸出棧中每個(gè)元素,直到??諡橹筽r

13、ivate:int elemARRAY_SIZE; /用于保存棧元素的數(shù)組int top; /指明棧頂元素位置的指針;void Stack:Push(int newElem) if(_(1)_) cout<<"棧滿!"<<endl;exit(1); /中止運(yùn)行_(2)_;elemtop=_(3)_;(1) (2) (3) 30. 已知一個(gè)利用數(shù)組實(shí)現(xiàn)棧的類定義如下:const int ARRAY_SIZE=10;class Stack public:void Init() top=-1; /初始化棧為空 void Push(int newElem);

14、 /向棧中壓入一個(gè)元素int Pop(); /從棧頂彈出一個(gè)元素bool Empty() /判???if(top=-1) return true;else return false;int Depth() return top+1; /返回棧的深度void Print(); /按照后進(jìn)先出原則依次輸出棧中每個(gè)元素,直到??諡橹筽rivate:int elemARRAY_SIZE; /用于保存堆棧元素的數(shù)組int top; /指明棧頂元素位置的指針;該類的Pop和Print函數(shù)的實(shí)現(xiàn)分別如下:_(1)_ if(top=-1) cout<<"???"<<

15、endl;exit(1); /中止運(yùn)行return _(2)_;void Stack:Print() while(!Empty() cout<<_(3)_ <<' '(1) (2) (3)31class A int a; public:A() a=0; _(1)_ /定義構(gòu)造函數(shù),用參數(shù)aa初始化數(shù)據(jù)成員a ; main() _(2)_; /定義類A的指針對(duì)象p _(3)_; /用p指向動(dòng)態(tài)對(duì)象并初始化為整數(shù)5 (1) (2) (3)32class A char *a; public: _(1)_ /定義無(wú)參構(gòu)造函數(shù),使a的值為空 A(char *aa)

16、 a=_(2)_; strcpy(a,aa); /用aa所指字符串初始化a所指向的動(dòng)態(tài)存儲(chǔ)空間 _(3)_ /定義析構(gòu)函數(shù),刪除a所指向的動(dòng)態(tài)存儲(chǔ)空間 ;(1) (2) (3)33class A int a,b; public: A(int aa=0, int bb=0) _(1)_ /分別用aa和bb對(duì)應(yīng)初始化a和b ;main() _(2)_ ; /定義類A的對(duì)象x并用5初始化,同時(shí)定義y并用x初始化 _(3)_ ; /定義p指針,使之指向?qū)ο髕(1) (2) (3)34class A int a,b; public: _(1)_ /定義構(gòu)造函數(shù),使參數(shù)aa和bb的默認(rèn)值為0, /在函數(shù)體

17、中用aa初始化a,用bb初始化b ;main() A *p1, *p2; _(2)_ ; /調(diào)用無(wú)參構(gòu)造函數(shù)生成由p1指向的動(dòng)態(tài)對(duì)象_(3)_ ; /調(diào)用帶參構(gòu)造函數(shù)生成由p2指向的動(dòng)態(tài)對(duì)象, /使a和b成員分別被初始化為4和5(1) (2) (3)35. #include<iostream.h>#include<stdlib.h>class A int *a; int n; int MaxLen; public: A(): a(0), n(0), MaxLen(0) A(int *aa, int nn, int MM) n=nn; MaxLen=MM; if(n>

18、;MaxLen) exit(1);_(1)_; /由a指向長(zhǎng)度為MaxLen的動(dòng)態(tài)數(shù)組for(int i=0; i<n; i+) ai=aai; A() delete a; int GetValue(int i) _(2)_ /函數(shù)體返回ai的值 ;void main()int b10=1,2,3,4,5,6,7,8,9,10;A r(b,10,10);int i,s=0;for(i=0; i<10; i+); _(3)_ /把r對(duì)象的a數(shù)據(jù)成員中的每個(gè) /元素值依次累加到s中cout<<"s="<<s<<endl;(1) (

19、2) (3)36. #include<iostream.h>#include<stdlib.h>class A int *a; int n; int MaxLen; public: A(): a(0), n(0), MaxLen(0) A(int *aa, int nn, int MM) n=nn; MaxLen=MM; if(n>MaxLen) exit(1); a=new intMaxLen;_(1)_; /以i為循環(huán)變量把a(bǔ)a數(shù)組中每個(gè)元素值 /傳送給a數(shù)組的對(duì)應(yīng)元素中 A(); int GetValue(int i) return ai; /函數(shù)體返回ai

20、的值;_(2)_ /析構(gòu)函數(shù)的類外定義 void main()int b10=1,2,3,4,5,6,7,8,9,10;A r(b,10,10);int i,s=0; _(3)_ ; /以i為循環(huán)變量,把r對(duì)象的a數(shù)據(jù)成員中的 /每個(gè)元素值依次累加到s中cout<<"s="<<s<<endl;(1) (2) (3) 37. 一種類定義如下:class Goodsprivate:char gd_name20; /商品名稱int weight; /商品重量 static int totalweight; /同類商品總重量public:Good

21、s (char*str,int w) /構(gòu)造函數(shù) strcpy(gd_name,str); weight=w;totalweight+=weight; Goods ()totalweight -= weight;char* GetN()_(1)_; /返回商品名稱int GetW()return weight;_(2)_ GetTotal_Weight() /定義靜態(tài)成員函數(shù)返回總重量_(3)_;(1) (2)(3) 38.class Pointprivate:int x, y;public:Point()x=y=0;Point(int x0,int y0) x=x0;y=y0;int Get

22、X() return x; int GetY() return y; void Print()cout<<"Point("<<x<<","<<y<<")"<<endl;_(1)_; /友元函數(shù)聲明_(2)_; /友元函數(shù)聲明;Point operator+(Point& pt,int dd) /加號(hào)操作符重載函數(shù),實(shí)現(xiàn)Point類對(duì)象與整數(shù)加法Point temp=pt;temp.x+=dd;temp.y+=dd;return temp;Point ope

23、rator+(Point& pt1,Point& pt2) /加號(hào)操作符重載函數(shù),實(shí)現(xiàn)兩個(gè)Point類對(duì)象的加法Point temp=pt1;temp.x+=pt2.x;_(3)_;return temp;(1) (2) (3) 39. 在下面一段類定義中, Derived類是由直接基類Base 1和Base 2所派生的,Derived類包含有兩個(gè)間接基類BaseBase,在初始化函數(shù)Init中,需要把x1和x2的值分別賦給屬于基類Base1的x成員和屬于基類Base2的x成員。class BaseBase protected: int x; public: BaseBase(

24、) x = 1;class Base1: public BaseBase public: Base1();class Base2: public BaseBase public: Base2();class Derived: _(1)_ public: Derived() void Init(int x1, int x2) _(2)_; _(3)_; void output() cout<<Base1:x<<' '<<Base2:x<<endl;(1)(2)(3) 40. 在下面一段類定義中, Derived類公有繼承了基類Bas

25、e。需要填充的函數(shù)由注釋內(nèi)容給出了功能。class Base private: int mem1,mem2; /基類的數(shù)據(jù)成員 public: Base(int m1,int m2) mem1=m1; mem2=m2; void output()cout<<mem1<<' '<<mem2<<' ' /.;class Derived: public Base private: int mem3; /派生類本身的數(shù)據(jù)成員 public: /構(gòu)造函數(shù),由m1和m2分別初始化mem1和mem2,由m3初始化mem3 Der

26、ived(int m1,int m2, int m3); /輸出mem1,mem2和mem3數(shù)據(jù)成員的值 void output() _(1)_;cout<<mem3<<endl;/.;Derived:Derived(int m1,int m2, int m3): _(2)_ _(3)_;(1)(2)(3) 41. 在下面一段類的定義中,需要填充的函數(shù)由注釋內(nèi)容給出了功能。class Point /定義坐標(biāo)點(diǎn)類 public: int x,y; /點(diǎn)的橫坐標(biāo)和縱坐標(biāo) Point()x=0;y=0; Point(int x0,int y0) x=x0; y=y0; int

27、 X()return x; int Y()return y;void PrintP()cout<<"Point:("<<x<<","<<y<<")"<<endl;class Line: public Point /利用坐標(biāo)點(diǎn)類定義直線類 private: class Point pt1,pt2; /直線的兩個(gè)端點(diǎn) public:Line(Point pts, Point pte); /構(gòu)造函數(shù),分別用參數(shù)初始化對(duì)應(yīng)的端點(diǎn) double Dx()return pt2

28、.x-pt1.x;double Dy()return pt2.y-pt1.y;double Length() /計(jì)算直線的長(zhǎng)度return sqrt(_(1)_); void PrintL(); /輸出直線的兩個(gè)端點(diǎn)和直線長(zhǎng)度;Line:Line(Point pts, Point pte) _(2)_ void Line:PrintL() cout<<"1st " pt1.PrintP(); cout<<"2nd " pt2.PrintP(); cout<<"The Length of Line: "

29、;<<_(3)_ <<endl;(1)(2)(3) 42. 在下面一段類的定義中,自行車類的虛基類為車輛類,機(jī)動(dòng)車類的虛基類也為車輛類,摩托車類的基類為自行車類和機(jī)動(dòng)車類,類之間均為公有繼承。class vehicle /車輛類 private: int MaxSpeed; /最大車速 int Weight; /車重 public: vehicle()MaxSpeed=0; Weight=0; virtual void Run() cout<<"A vehicle is running!"<<endl;class bicycl

30、e : _(1)_ /自行車類 private: int Height; /車高 public: bicycle(); void Run() cout<<"A bicycle is running!"<<endl;class motorcar : _(2)_ /機(jī)動(dòng)車類 private: int SeatNum; /乘人數(shù) public: motorcar(); void Run() cout << "A motorcar is running!" << endl; ;class motorcycle: _

31、(3)_ /摩托車類 public: motorcycle (); void Run() cout<<"A motorcycle is running!"<<endl;(1)(2)(3)五、讀程序?qū)懗鲞\(yùn)行結(jié)果1. #include<iostream.h>#include<stdlib.h>void main() int a8=25,48,32,85,64,18,48,29;int max,min;max=min=a0;for(int i=0; i<8; i+) if(x>ai) max=ai;if(x<ai)

32、 min=ai;cout<<"max:"<<max<<endl;cout<<"min:"<<min<<endl; 24. #include<iostream.h>#include<string.h>void main() char a510="student","worker","soldier","cadre","peasant"char s110, s210

33、; strcpy(s1,a0); strcpy(s2,a0);for(int i=1;i<5;i+) if(strcmp(ai, s1)>0) strcpy(s1,ai);if(strcmp(ai, s2)<0) strcpy(s2,ai);cout<<s1<<<<s2<<endl; 25. #include<iostream.h>const int N=5;void fun();void main()for(int i=1; i<N; i+)fun();void fun() static int a;int

34、b=2;cout<<(a+=3,a+b)<<' '28. #include<iostream.h>#include<string.h> class CD char* a; int b; public: void Init(char* aa, int bb) a=new charstrlen(aa)+1; strcpy(a,aa); b=bb; char* Geta() return a; int Getb() return b; void Output() cout<<a<<' '<&

35、lt;b<<endl; dx;void main()CD dy;dx.Init("abcdef",30);dy.Init("shenyafen",3*dx.Getb()+5);dx.Output();dy.Output();29#include<iostream.h>#include<string.h> class CD char* a; int b; public: void Init(char* aa, int bb) a=new charstrlen(aa)+1; strcpy(a,aa); b=bb; char

36、* Geta() return a; int Getb() return b; void Output() cout<<a<<' '<<b<<endl; ;void main()CD dx,dy;char a20;dx.Init("abcdef",30);strcpy(a,dx.Geta();strcat(a,"xyz");dy.Init(a,dx.Getb()+20);dx.Output();dy.Output();30. #include<iostream.h>class C

37、E private: int a,b; int getmax() return (a>b? a:b); public: int c; void SetValue(int x1,int x2, int x3) a=x1; b=x2; c=x3; int GetMax(); ;int CE:GetMax() int d=getmax();return (d>c? d:c);void main()int x=5,y=12,z=8;CE ex, *ep=&ex;ex.SetValue(x,y,z);cout<<ex.GetMax()<<endl;ep->

38、;SetValue(x+y,y-z,20);cout<<ep->GetMax()<<endl;31. #include<iostream.h>class CE private: int a,b; int getmin() return (a<b? a:b); public: int c; void SetValue(int x1,int x2, int x3) a=x1; b=x2; c=x3; int GetMin(); ;int CE:GetMin() int d=getmin();return (d<c? d:c);void main

39、()int x=5,y=12,z=8;CE *ep;ep=new CE;ep->SetValue(x+y,y-z,10);cout<<ep->GetMin()<<endl;CE a=*ep;cout<<a.GetMin()*3+15<<endl;32. #include<iostream.h> class Franction /定義分?jǐn)?shù)類 int nume; /定義分子 int deno; /定義分母 public: /把*this化簡(jiǎn)為最簡(jiǎn)分?jǐn)?shù),具體定義在另外文件中實(shí)現(xiàn)void FranSimp(); /返回兩個(gè)分?jǐn)?shù)*t

40、his和x之和,具體定義在另外文件中實(shí)現(xiàn)Franction FranAdd(const Franction& x); /置分?jǐn)?shù)的分子和分母分別0和1 void InitFranction() nume=0; deno=1; /置分?jǐn)?shù)的分子和分母分別n和d void InitFranction(int n, int d) nume=n; deno=d; /輸出一個(gè)分?jǐn)?shù)void FranOutput() cout<<nume<<'/'<<deno<<endl; ;void main() Franction a,b,c,d; a

41、.InitFranction(7,12); b.InitFranction(-3,8); c.InitFranction(); c=a.FranAdd(b); d=c.FranAdd(a);cout<<"a: " a.FranOutput(); cout<<"b: " b.FranOutput(); cout<<"c: " c.FranOutput(); cout<<"d: " d.FranOutput(); 33. #include<iostream.h>

42、; class Franction /定義分?jǐn)?shù)類 int nume; /定義分子 int deno; /定義分母 public: /把*this化簡(jiǎn)為最簡(jiǎn)分?jǐn)?shù),具體定義在另外文件中實(shí)現(xiàn)void FranSimp(); /返回兩個(gè)分?jǐn)?shù)*this和x之和,具體定義在另外文件中實(shí)現(xiàn)Franction FranAdd(const Franction& x); /置分?jǐn)?shù)的分子和分母分別0和1 void InitFranction() nume=0; deno=1; /置分?jǐn)?shù)的分子和分母分別n和d void InitFranction(int n, int d) nume=n; deno=d; /

43、輸出一個(gè)分?jǐn)?shù)void FranOutput() cout<<nume<<'/'<<deno<<endl; ;void main() Franction a,b,c,d; a.InitFranction(6,15); b.InitFranction(3,10); c.InitFranction(); c=a.FranAdd(b); d=c.FranAdd(a);cout<<"a: " a.FranOutput(); cout<<"b: " b.FranOutput();

44、 cout<<"c: " c.FranOutput(); cout<<"d: " d.FranOutput(); 34. #include<iostream.h>#include<string.h>class A char *a;public: A(char *s) a=new charstrlen(s)+1; strcpy(a,s); cout<<a<<endl; A() delete a; cout<<"Destructor!"<<en

45、dl; ;void main() A x("xuxiaokai"); A *y=new A("weirong"); delete y; 35. #include<iostream.h>class A int *a;public: A(int x=0):a(new int(x) A() delete a; int getA() return *a; void setA(int x) *a=x;void main() A x1,x2(3);A *p=&x2;p->setA(x2.getA()+5); x1.setA(15+x1.ge

46、tA();cout<<x1.getA()<<' '<<x2.getA()<<endl; 36. #include<iostream.h>class A int a;public: A(int aa=0): a(aa) cout<<a<<' ' A() cout<<"Xxk"void main() A *p; A x3=1,2,3,y=4;cout<<endl;p=new A3; cout<<endl;delete p;cou

47、t<<endl; 37. #include<iostream.h>class A int a,b;public: A() a=b=0; A(int aa, int bb) a=aa; b=bb;int Sum() return a+b;int* Mult() int *p=new int(a*b);return p;void main() int *k;A x(2,3), *p; p=new A(4,5); cout<<x.Sum()<<' '<<*(x.Mult()<<endl; cout<<

48、p->Sum()<<' '<<*(k=p->Mult()<<endl; delete k; 38. #include<iostream.h>class A int a10; int n; public: A(int aa, int nn): n(nn) for(int i=0; i<n; i+) ai=aai; int Get(int i) return ai;int SumA(int n) int s=0;for(int j=0; j<n; j+) s+=aj;return s;void main() int a=2,5,8,10,15,20; A x(a,4); A y(a,6); int d=1;for(int i=0; i<4; i+) d*=x.Get(i);int f=y.SumA(5);cout<<"d="<<d<<endl;cout<<"f="<<f<<endl; 39. #include<iostream.h>class A int a,b; public: A(int aa, int bb) a=aa; b=bb;float

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論