C++课后复习思考题(5)

2019-03-28 18:27

}

}

B.fund(int x,int y) }

{ *x=*x+*y; *y=*x-*y; *x=*x-*y;

A.func(int *x,int *y) {

*x=*y; *y=*x; }

(7)以下程序的输出结果是( )。

#include void main() { }

A.4,2,1,1 B.4,9,3,1 int (*ptr)();

A.ptr是指向一维数组的指针变量 B.ptr是指向int 型数据的指针变量

C.ptr是指向函数的指针,该函数返回一个int型数据 D.ptr是一个函数名,该函数的返回值是指向int型数据的指针

(9)若有如下语句:

int **pp,*p,a=10,b=20; pp=&p; p=&a; p=&b;

cout<<*p<<”,”<<**p<

B.10,10

C.20,10

D.20,20

(10)设char **s;以下正确的表达式是( )。

A.s=”computer”;

B.*s=”computer”; C.**s=”computer”; D.*s=?c?;

2.编写程序,在堆内存中申请一个float型数组,把10个float型数据0.1、0.2、0.3、?、1.0赋予该数组,然后使用float型指针输出该数组的各元素值并求出其累加和。

3.编写一个函数f,将传入此函数的直角坐标值转换为极坐标值,并返回主调函数中。求极坐标的公式是:

c=

C.5,8,6,1

D.8,8,8,8

(8)设有如下定义,下面关于ptr正确叙述是( )。

char *s=\int v1=0,v2=0,v3=0,v4=0; for (int k=0;s[k];k++)

switch(s[k]) { }

default:v4++; case '1':v1++; case '3':v3++; case '2':v2++;

cout<

x2?y2 q=arctan(y/x)

若要将两值返回主调函数,有多种方式可以完成,请试之: (1)两值均以指针形参带回。

(2)由指针形参带回一个值,函数值返回另一个值。 (3)两值均以引用形参返回。

(提示:程序中可以使用C库函数sprt、pow及atan,它们的头文件为stdlib.h)

4.使用指针编写函数strcat(),实现两个字符串的首尾连接(将字符串str2接到str1的后面,str1最后面的‘\\0’被取消)。

5.编写从多个字符串中寻找最长串的函数 char *maxstr(char *str[ ],int n)

其中,str是字符串数组,n是字符串个数。函数返回值为最长串地址。 6.写一个函数,将一个n阶方阵转置。具体要求如下:

(1)初始化一个矩阵A(5×5),元素值取自随机函数,并输出。 (2)将其传递给函数,实现矩阵转置。 (3)在主函数中输出转置后的矩阵。

(提示:程序中可以使用C++库函数rand( ),其功能是产生一个随机数0~65535,其头文件为stdlib.h) 7.编写一个程序,实现在命令行中以参数的形式接收两个整数,输出这两个整数的和。

(提示:程序中可以使用C++库函数atoi(),其功能是将字符串转换成整型值,其头文件为stdlib.h) 8.使用引用参数编制程序,实现两个字符串变量的交换。例如开始时:

char *ap=”hello”; char *bp=”how are you”;

交换后使ap和bp指向的内容别是: ap:”how are you” bp:”hello”

9.下列程序能够生成由10个整数组成的安全数组。其中put()函数的作用是将值放入数组中,get()函数的作用是取出数组中某元素的值,如果在put()函数和get()函数中遇到下标越界则给出提示信息 “range error!”并退出程序。请完成put()函数和get()函数的定义。

#include #include int &put(int n); int get(int n); int array[10]; int error=-1; void main() { put(0)=10; put(1)=20; put(9)=40; cout<

运行结果是: 10

20 30

range error!

第7章 复习思考题

1.选择题

(1)下列关于结构体的说法错误的是( )。

A.结构体是由用户自定义的一种数据类型 B.结构体中可设定若干个不同数据类型的成员

C.结构体中成员的数据类型可以是另一个已定义的结构体 D.在定义结构体时,可以为成员设置默认值 (2)下列结构体定义,正确的是( )。

A. B.

record { struct record { int no; int no; char num[16]; char num[16]; float score ; float score ; } ; } C. D.

struct record { struct record { int no; int no char num[16]; char num[16] float score ; } ; float score } (3)下列声明结构体变量错误的是( )。

A.struct student { B. struct student{ int no; int no;

char name[16]; char name[16]; } st1,st2; }; struct student st1,st2;

C. D.

struct student { struct student {

int no; int no;

char name[16]; char name[16]; } ; }; student st1,st2; struct st1,st2; (4)若有同下[定义,下列说法错误的是( )。

struct em { char a; char b;

}

A.struct是结构体类型关键字 B.em 是结构体类型名 C.em 是用户声明的结构体变量 D.a,b是结构体成员名 (5)若有下列定义,则对结构体变量的成员引用错误的是( )。

struct date { int year; int month; int day;} struct student{ int no;

char name[16]; date birthday; } stud;

A. stud.no B. stud.name C. stud.birthday D. stud.birthday.year (6)若有下列定义,则错误的赋值语句是( )。

enum color {red,yellow,blue,green} col; int k;

A. col=red B. col=3 C. k=red+2 D. k=red+blue 2.写出下列程序的运行结果 (1)#include

struct ab {

char a[5]; float b; };

void main() {

ab x={\

cout<

(2) #include

struct ab {char a ; float b; };

void f(ab &y) { y.a='W'; y.b=90.5; }

void main() {

ab x={'L',89.5}; f(x);

cout<

(3) #include

union data { int m; char ch; float x; } a;


C++课后复习思考题(5).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:全国2014年4月自考高等数学(一)00020试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: