假期作业 2.2

第一章 命名空间

一.选择题

1、编写C++程序一般需经过的几个步骤依次是(   B   )

A. 编辑、调试、编译、连接

B. 编辑、编译、连接、运行

C. 编译、调试、编辑、连接

D. 编译、编辑、连接、运行

   2、所谓数据封装就是将一组数据和与这组数据有关操作组装在一起,形成一个实体,这实体也就是(   A )

A. 

B. 对象

C. 函数体

D. 数据块

3、在C++中,使用流进行输入输出,其中用于屏幕输入(  A )

A. cin

B. cerr

C. cout

D. clog

   4、关于对象概念的描述中,说法错误的是(A

A. 对象就是C语言中的结构变量

B. 对象代表着正在创建的系统中的一个实体

C. 对象是类的一个变量

D. 对象之间的信息传递是通过消息进行的

   5、在C++语言中,数据封装要解决的问题是(D

A. 数据的规范化

B. 便于数据转换

C. 避免数据丢失

D. 防止不同模块之间数据的非法访问

6、在面向对象的程序设计中,首先在问题域中识别出若干个 (B

A. 函数     B. 类       C. 文件       D. 过程

   7、在下列成对的表达式中,运算结果类型相同的一对是(A

A. 7.0/2.0和7.0/2

B. 5/2.0和5/2

C. 7.0/2和7/2

D. 8/2和6.0/2.0

   8、函数调用func((exp1,exp2),(exp3,exp4,exp5))中所含实参的个数为(C

A. 5    B. 4       C. 2       D. 1

  9、执行语句

char ch[] = "Hello";

char * p = &ch[0];

cout << p;

结果是输出 _____C_________。

A. 一个地址    B. H     C. Hello      D. 乱码

   10、下列程序的输出结果是(A

#include 4<iostream.h>

void main()

{ int n[][3]={10,20,30,40,50,60 };

int (*p)[3];

p=n;

cout<<p[0][0]<<","<<*(p[0]+1)<<","<<(*p)[2]<<endl; }

A. 10,30,50

B. 10,20,30

C. 20,40,60

D. 10,30,60

二.填空题1、执行下列代码

cout<<“oct:”<<oct<<34;

程序的输出结果是__oct:34_

 

2、C++的流库预定义了4个流,它们是cin、cout、clog和__cout

 

3、表达式cout<<end1 还可表示为_cout << \n_

 

4、下面程序的输出结果为__5_。

#include <iostream.h>

void main()

{ int num=2,i=6;

do

{i--;

num++;

}while(--i);

cout<<num<<endl;

}

5、int n=0;

while(n=1)n++;

while循环执行次数是  0__

6、给出下面程序输出结果 1

#include <iostream.h>

int a[8]={1,2,3,4,5,6,7};

void fun(int *pa,int n);

void main()

{int m=8;

fun(a,m);

cout<<a[7]<<endl;

}

void fun(int *pa,int n)

{for (int i=0;i<n-1;i++)

*(pa+7)+=*(pa+i);

}

运行程序,写出程序执行的结果。

7、给出下面程序输出结果

#include <iostream.h>

void main()

{ int *p1;

int **p2=&p1;

int b=20;

p1=&b;

cout<<**p2<<endl;

}

20

8、 #include <iostream.h>

void main()

{ int a,b,c;

char ch;

cin>>a>>ch>>b>>c;//从键盘上输入1.5×c×10×20,×表示一个空格

cout<<a<<endl<<ch<<endl<<b<<endl<<c<<endl;

}

1.5

C

10

20

9、在下面程序横线处填上适当内容,使程序执行结果为:

S=2

S=5 

S=9

 

#include <iostream.h>

void sum(int i)

{ static int s;

__s = 4*i+1_______;

cout<<"s="<<s<<endl;

}

void main (void)

{ int i;

for (i=0;_i<3__;__i++__ )

sum(i);

}

10、下面是一个三角形三边,输出其面积C++程序,在下划线处填上正确的语句。

#include <iostream.h>

#include <math.h>

void area()

{double a,b,c;

cout<<"Input a b c:";

__cin << a << b << c;______

if(a+b>c&&a+c>b&&c+b>a)   // 三角形 任意2边大于第三边

{  double l=(a+b+c)/2;   // 半周长

   double s=sqrt(l*(l-a)*(l-b)*(l-c))  // 海伦公式

cout<<"The area is:"<<s<<endl;

}

else

cout<<"Error"<<endl;

}

void main()

{  area(); }

 

三、编程题

3.1 创建一个程序,输出8个随机大小写字母或数字组成的密码,允许输入重复的字符

#include <iostream>

#include <random>

#include <ctime>

using namespace std;

int main()

{

    string password;

    string str="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";

    int size=str.size();

    int flag=0;

    srand(time(NULL));

    while (flag<8)

    {

        int temp=rand();

        if(temp<size)

        {

            password+=str[temp];

            flag++;

        }

    }

    cout << password << endl;

    return 0;

}

相关推荐

  1. 假期作业 2.2

    2024-02-03 13:10:02       33 阅读
  2. 假期作业2

    2024-02-03 13:10:02       27 阅读
  3. 2.8 假期作业

    2024-02-03 13:10:02       28 阅读
  4. 假期作业8

    2024-02-03 13:10:02       33 阅读
  5. 假期作业 2月6号

    2024-02-03 13:10:02       28 阅读
  6. 假期作业 2月14日

    2024-02-03 13:10:02       31 阅读
  7. 假期刷题打卡--Day21

    2024-02-03 13:10:02       30 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-02-03 13:10:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-02-03 13:10:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-02-03 13:10:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-02-03 13:10:02       20 阅读

热门阅读

  1. clickhouse批量入库异常日志

    2024-02-03 13:10:02       29 阅读
  2. 前端工程化之:webpack1-11(其他配置)

    2024-02-03 13:10:02       32 阅读
  3. XML要点总结

    2024-02-03 13:10:02       25 阅读
  4. uniapp本地存储的几种方式localStorage

    2024-02-03 13:10:02       35 阅读
  5. 工厂模式与抽象工厂模式

    2024-02-03 13:10:02       26 阅读