教学文库网 - 权威文档分享云平台
您的当前位置:首页 > 文库大全 > 教育文库 >

c++指针练习题答案

来源:网络收集 时间:2026-09-08
导读: 含有c++指针练习题的答案 第五章 程序结构 参 考 答 案 一、填空题 1.程序代码 2.快、文件、文件 3.整个类、任何一个对象、静态数据成员、非静态数据成员、类名、对象名 4.this 5.构造函数、析构函数 6.static 7.友元函数 8.friend class FriendClas

含有c++指针练习题的答案

第五章 程序结构 参 考 答 案

一、填空题

1.程序代码

2.快、文件、文件

3.整个类、任何一个对象、静态数据成员、非静态数据成员、类名、对象名 4.this

5.构造函数、析构函数 6.static 7.友元函数

8.friend class FriendClass 9.函数头、函数体 10.拷贝

11.成员初始化列表 12.main

13.外部连接、共享 14..* 、->* 15.之前 16.交换性

17.构造函数、析构函数 18.类、类外 19.友元函数

20.类定义文件、类实现文件、类使用文件二、选择题

1—5: ADCAB 6—10: CABDA 11—15:CBBDB 16—20: ACDCB 21--25:ACDAB 26—30:DBCAD 31—32:DB

三、阅读程序题

1.在main内的m:2 在main外的m:0 n=10 3.i=1,k=2 i=1,k=2 5.x=xx class A B &b 7.5 9.点:(2,2) 点:(5,6) 上述两点之间的距离:5

2.n=0 n=1 n=2 4.int n=10 int k return n

6.double x1,double y1

friend point setpoint(line l1,line l2) double x,y return p setpoint(a,b)

8.Point A,4,5 Object id=1

Point B,4,5 Object id=2

.disp1:x=6 disp2:x=4

10

含有c++指针练习题的答案

11.x=12,y=22 12.不能将一个对象复制到自己。

x=12,y=22 13.x=1,y=10,r=1 14.Constructor5

x=2,y=10,r=2 5

Destructor5 15.The student is Li Hu 16.2 The teacher is Wang Ping

17.stringX,stringY 18. 学号 姓名 成绩 1 Li 89 2 Chen 78 3 Zheng 94 平均分=87

19. Starting1: 20.Default Constructor called Default Constructor called Default Constructor called Default Constructor called Default Constructor called Default Constructor called Default Constructor called Ending1. Destructor called Starting2: Constructor1 called Constructor:a=5,b=6 Destructor called Constructor:a=7,b=8 Constructor2 called Ending2. Destructor called Destructor called.a=7,b=8 x=0,y=0 Destructor called.a=5,b=6 x=7,y=0 Destructor called.a=5,b=6 x=5,y=9

Destructor called.a=3,b=4 Destructor call Destructor called.a=1,b=2 Destructor call Destructor call

四、完成程序题

1.MyClass(MyClass &p) 2. ~MyClass() MyClass(MyClass &p) X=new int(a); p.X delete X; p.Y 3.friend class Distance float a=0,flaot b=0 float x,y;

result=sqrt((p.X-q.X)*(p.X-q.X)+(p.Y-q.Y)*(p.Y-q.Y)); 4.int n=10 int k return n 5.x=xx class A B &b

6.double x1,double y1

含有c++指针练习题的答案

friend point setpoint(Line l1,Line l2) double x ,y return p setpoint(a,b)

7.int x,y A label return length*width box small,medium,large

五、编程题

1.#include<iostream.h>

class Point {

public:

Point(int xx=0,int yy=0){x=xx;y=yy;} Point(Point &p); int x,y; };

Point::Point(Point &p) {

x=p.x; y=p.y; cout<<" "<<endl; }

class rectangle {

Point p1,p2; public:

rectangle(Point p_1,Point p_2){p1=p_1;p2=p_2;} void area(); };

void rectangle::area() {

cout<<(p2.x-p1.x)*(p2.y-p1.y)<<endl; }

void main() {

Point p1(12,12),p2(24,24); rectangle r(p1,p2); r.area(); }

2. #include<iostream.h>

struct list {

含有c++指针练习题的答案

int data; list *next; };

class Queue { list *ptrf,*ptrb; public: Queue() {

ptrf=ptrb=NULL; } void enqueue(int); int dequeue(); };

void Queue::enqueue(int x){ list *newnode=new list; newnode->data=x;

newnode->next=NULL; if(ptrb==NULL)

ptrf=ptrb=newnode; else {

ptrb->next=newnode; ptrb=newnode; } };

int Queue::dequeue() { list *tmp; int value;

value=ptrf->data; tmp=ptrf;

ptrf=ptrf->next; delete tmp; return value; }

void main() {

Queue A; int arr[]={3,12,8,9,11}; cout<<""; for(int i=0;i<5;i++) {

cout<<arr[i]<<" ";

含有c++指针练习题的答案

A.enqueue(arr[i]); }

cout<<endl<<""; for(i=0;i<5;i++)

cout<<A.dequeue()<<" "; cout<<endl; }

3. #include<iostream.h>

#include<string.h> class student {

char name[10]; int deg; public:

student(char na[],int d) {

strcpy(name,na); deg=d; }

char *getname(){return name;}

friend int compare(student &s1,student &s2) {

if(s1.deg>s2.deg) return 1; else if(s1.deg==s2.deg) return 0; else return -1; } };

void main() {

student st[]={student("王华",78),student("李明",92),

student("张伟",62),student("孙强",88)};

int i,min=0,max=0; for(i=1;i<4;i++ …… 此处隐藏:3965字,全部文档内容请下载后查看。喜欢就下载吧 ……

c++指针练习题答案.doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.jiaowen.net/wenku/1809621.html(转载请注明文章来源)
Copyright © 2020-2025 教文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:78024566 邮箱:78024566@qq.com
苏ICP备19068818号-2
Top
× 游客快捷下载通道(下载后可以自由复制和排版)
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
VIP包月下载
特价:29 元/月 原价:99元
低至 0.3 元/份 每月下载150
全站内容免费自由复制
注:下载文档有可能出现无法下载或内容有问题,请联系客服协助您处理。
× 常见问题(客服时间:周一到周五 9:30-18:00)