C++试卷(华南理工大学)

华南理工大学期末考试 

高级语言程序设计(I)》A

注意事项:    1. 考前请将密封线内各项信息填写清楚;

            2. 所有答案写在答题纸上,答在其它地方无效;

3.考试形式:闭卷;

           4. 试卷可做草稿纸,试卷必须与答题纸同时提交;

5. 本试卷共五大题,满分100分,考试时间120分钟

Question 1 (2 points for each, 20 points for total) Choose the correct answer

1) To initialize an array of characters which one is NOT correct? (       )

      A) char s1[3]={'a','b','c'};          B) char s2[5]="abc";

       C) char s3[]={'m','n','s','r'};     D) char s4[4]="ijkl";

D需要分配5个空间

A则不需要

2)    If the array name as an argument, the function call passed  (    A ) to the parameter.

A) the starting address of the array           

B) the value of the first element

     C) all the elements values of an array

D) the number of array elements

传递(A)数组的起始地址。

3)    If we have : int x=3, y=2;  double a=2.9, b=3.5;  the value of expression (x+y)/2+(int)a%(int)b   would be(      )。

A)  1                    B)  2                  C)   3                D)   4

D

4)    In the following statements about the overload function which one is correct? (      )

A) overload functions must have different return types

B) overload functions must have different numbers of parameters

C) overload functions must have a different parameter list

D) overload functions’ name can be different

C

5)    In the following data types which one does not belong to the basic data types in C ++. (      )

A)     int         B)   double         C) char      D) class     

D显而易见

6)    We have :  double fun( double l ); typedef double ft ( double ) ;

 ft * pfun[2];    pfun[0]=fun;,in the following function calls which one is NOT correct (     )?

A)( *pfun[0] )(3.14)                      B)fun(3.14)

C)   ( pfun[0] )(3.14)                     D)( &pfun[0] )(3.14)

D

7)    in the following identifiers groups, which one is both legitimate user identifiers? (      )

A)    _0123  ssiped                B)   del-word  signed

C)      list  *jer                          D) keep%  wind

 A

8)    The operand data type on both sides of logical operators is (      )

A) can only be 0 or 1

B) can only be a positive integer or 0

C) can only be an integer or character data

D) can be any type of legitimate data

D

9)    In the following statements, which one is correct to initialize a two-dimensional array? (   B,D   )

A)   int a[2][]={{1,0,1},{5,2,3}};

B)    int a[][3]={{1,2,3},{4,5,6}};

C)    int a[2][4]={{1,2,3},{4,5},{6}};

D)   int a[][3]={{1,0},{},{1,1}};

10)  For the members of class, the implies access is ( )

(A) public;   (B)private;   (C) protected;    (D) static;

默认私有

Question 2: ( 20 points )

What is the output of the following code fragment?

Part1 (3 points)

#include  <iostream>

using namespace std;

main()

{  int  x=1,y=0,a=0,b=0;

        switch(x)

        {  case  1:

                switch(y)

{   case  0:a++;  break;

                case  1:b++;  break;

}

case 2:a++; b++; break;

case 3:a++; b++;

}

cout<<"a="<<a<<",b="<<b<<endl;

}

 

Output

a=2,b=1

Part2( 3 points)

#include <iostream>

int f1(int a,int b) {return a%b*5;}

int f2(int a,int b) {return a*b;}

int f3(int(*t)(int, int),int a,int b) { return (*t)(a, b);}

void main()

{      int (*p)(int, int) ;

    p=f1 ;  cout<<f3(p, 5, 6)<<endl ;

    p=f2 ;  cout<<f3(p, 7, 8)<<endl ;

}

Output

25

56

Part3 (3 points)

#include  <iostream>

using namespace std;

int fun(int n)

{      if(n==1)return 1;

      else

    return(n+fun(n-1));

}

main()

{      int x;

cin>>x; x=fun(x);

cout<<x;

}

Output

55

When the input for x is 10,the output is

Part4 (3 points)

#include<iostream>

using namespace std;

void fun(int a,int b)

{      int k;

        k=a;a=b;b=k;

}

void main()

{      int a=4,b=7,*x,*y;

x=&a;y=&b;

fun(*x,*y);

cout<<"No.1:"<<a<<','<<b<<endl;

fun(a,b);

cout<<"No.1:"<<a<<','<<b<<endl;

}

No.1:4,7

No.1:4,7

Part 5( 4 points)

#include<iostream>

using namespace std;

int fun(int n)

{     static int a=3;

        int t=0;

        if(n%2)

{      static int a=5; t+=a++; }

    else

{      static int a=5;  t+=a++; }

    return t+=a++;

}

void main()

{ int i,s=0;

  for(i=0;i<3;i++) s+=fun(i);

  cout<<s<<endl;

}

Output

28

Part 6( 4 points)

#include<iostream>

using namespace std;

void main()

{      char ch[2][6]={"2100","0846"},*pch[2];

        int i,j,s=0;

        for(i=0;i<2;i++)

                 pch[i]=ch[i];

        for(i=0;i<2;i++)

                 for(j=0;pch[i][j]>='0' && pch[i][j]<='9';j+=2)

                         s=10*s+pch[i][j]-'0';

        cout<<s<<endl;

Output

2004

}

Question 3    Short answers (20 points)

Part 1 (2 points)

In the function prototype int fun(int, int=0);  what does the “int=0” mean?

参数默认值是0

Part 2 (2 points)

After executing the following statements, what is the values of x and y ?

int x, y; x=y=1;    ++x||++y;

__x=2,y=1____________

Part 3 (2 points)

When the following statements are running, how many times does the loop execute?

int i=0, x=1;  do {  x++;   i++;  }  while ( !x&&i<=3 );

_1次__

Part 4  (8 points,2 points for each)

Insert the braces in the following code to produce a specified output. Please NOTE that the program may not make any other changes except braces.

if (y==8)

if (x==5)

cout << “@@@@” << endl;

else

cout << “####” <<endl;

cout << “$$$$” <<endl;

cout << “&&&&” <<endl;

  1. When x=5 and y=8, The output is:

@@@@

$$$$

&&&&

  1. When x=5 and y=8, The output is:

@@@@

  1. When x=5 and y=8, The output is:

@@@@

&&&&

  1. When x=5 and y=7, The output is:

####

$$$$

&&&&

{ } 可有可无,{ }必须有

  1. if (y==8)

if (x==5)

cout << “@@@@” << endl;  }

else

{   cout << “####” <<endl;  }

cout << “$$$$” <<endl;

cout << “&&&&” <<endl;

2) if (y==8)

if (x==5)

{   cout << “@@@@” << endl;  }

else

{  cout << “####” <<endl;

cout << “$$$$” <<endl;

cout << “&&&&” <<endl;   }

  1. if (y==8)

if (x==5)

cout << “@@@@” << endl;  }

else

{    cout << “####” <<endl;

cout << “$$$$” <<endl;    }

cout << “&&&&” <<endl;

4) if (y==8)

if (x==5)

cout << “@@@@” << endl;  }

else

{   cout << “####” <<endl;

cout << “$$$$” <<endl;

cout << “&&&&” <<endl;   }

Part 5  (6 points,1 point for each)

Find the errors and fix it in each of the following program segments. Assume the following declarations and statements:

void * sPtr = 0;

int number;

int z[5] = {1,2,3,4,5};

int * zPtr;

fix each statement.

  1. // use pointer point the starting address of the array z

zPtr=z[0];

  1. // use pointer to get first value of array

number = zPtr;

  1. // assign the third element of array z (the value 3) to number

number = *zPtr[ 2 ];

  1. // print entire array z

for( int i=0; i<=5; i++)

       cout<<zPtr[i] <<endl;

  1. //let the pointer point the second element of the array

zPtr=2;

  1. // assign the value pointed by zPtr to number

number = zPtr;

zPtr=z / zPtr=&z[0]

_________________________________________________________

   number=zPtr[0]  /  number=*zPtr

_________________________________________________________

   Number=zPtr[2]  /  number = *(zPtr+2)

_________________________________________________________

  1.  

i<5

_________________________________________________________

   zPtr=z+1   /  zPtr=&a[1]

_________________________________________________________

   Number=*zPtr

__________________________

Question 4: Fill in the blanks ( 20 Point,2 points for each blank)

  1. The following program calculates values of e according to the formula 1!+3!+5!+……+n! .

#include<iostream>

using namespace std;

void main()

{   long int f,s;

     int i,j,n;

     cin>>n;

     s=0,f=1;

     for(i=1;i<=n;       (1)       )

     {

              f=1;

              for(j=1; j<=i; j++)       (2)       ;

                   (3)       ;

     }

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

}

1______i+=2 / i=i+2______________2_____f*=j / f=f*j__________

2.The main function get a string, then call other function to change the numbers 0~9 to lower case letter a~j;And change all the lower case letters to up case letters, then output the result in function main.

#include<iostream>

using namespace std;

_____(4)_____

void main()

{   char str1[20], str2[20];

   cin>>str1;

 change(str1,str2);

 cout<<str2<<endl;

}

void change(char *s1, char *s2)

{   while(_____(5)_____)

 {     if(*s1>='0'&&*s1<='9')

                  *s2=_____(6)_____;

          else *s2=toupper(*s1);

          _____(7)_____

 }

 *s2='\0';

}

#include<iostream>

#include<cctype>

using namespace std;

void change(char *s1, char *s2);

int main()

{

    char str1[20], str2[20];

    cin >> str1;

    change(str1, str2);

    cout << str2 << endl;

    return 0;

}

void change(char *s1, char *s2)

{

    while (*s1)

    {

        if (*s1 >= '0' && *s1 <= '9')

            *s2 = *s1 - '0' + 'a';

        else

            *s2 = toupper(*s1);

        s1++;

        s2++;

    }

    *s2 = '\0';

}

3.    Output matrix as the Figure right of the code:

main()

{ int a[7][7];

 int i,j;

 for (i=0;i<7;i++)

   for (j=0;j<7;j++)

     { if (_____(8)___________) a[i][j]=1;

       else if (i<j&&i+j<6) _____(9)___________;

       else if (i>j&&i+j<6) a[i][j]=3;

       else if (____(10)____ ___) a[i][j]=4;

       else a[i][j]=5;

      }

   for (i=0;i<7;i++)

     {         for (j=0;j<7;j++)   cout<<setw(3)<<a[i][j];

                 cout<<endl;

     }

}

9____a[i][j]=2__________10 ____i<j &&i+j>6__________________

世间温柔,不过是芳春柳摇染花香,槐序蝉鸣入深巷,白茂叶落醉故乡。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/227413.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

GC root 有哪些

文章目录 GC root 有哪些? GC root 有哪些? Thread-存活的线程。Java 虚拟机栈中的引用的对象。方法区中的类静态属性引用的对象。 &#xff08;一般指被 static 修饰的对象&#xff0c;加载类的时候就加载到内存中。&#xff09;方法区中的常量引用的对象。本地方法栈中的 …

基于SpringBoot的在线疫苗预防小程序

文章目录 项目介绍主要功能截图:部分代码展示设计总结项目获取方式🍅 作者主页:超级无敌暴龙战士塔塔开 🍅 简介:Java领域优质创作者🏆、 简历模板、学习资料、面试题库【关注我,都给你】 🍅文末获取源码联系🍅 项目介绍 基于SpringBoot的在线疫苗预防小程序,ja…

分数约分-第11届蓝桥杯选拔赛Python真题精选

[导读]&#xff1a;超平老师的Scratch蓝桥杯真题解读系列在推出之后&#xff0c;受到了广大老师和家长的好评&#xff0c;非常感谢各位的认可和厚爱。作为回馈&#xff0c;超平老师计划推出《Python蓝桥杯真题解析100讲》&#xff0c;这是解读系列的第20讲。 分数约分&#xf…

LeetCode:967连续查相同的数字(DFS)

题目 返回所有长度为 n 且满足其每两个连续位上的数字之间的差的绝对值为 k 的 非负整数 。 请注意&#xff0c;除了 数字 0 本身之外&#xff0c;答案中的每个数字都 不能 有前导零。例如&#xff0c;01 有一个前导零&#xff0c;所以是无效的&#xff1b;但 0 是有效的。 …

Google Gemini Pro:AI模型的新里程碑,开放API访问;Octo: 一个开源通用的机器人策略

&#x1f989; AI新闻 &#x1f680; Google Gemini Pro&#xff1a;AI模型的新里程碑&#xff0c;开放API访问 摘要&#xff1a;Google宣布推出了名为Gemini的AI模型&#xff0c;旨在使AI更加有用。Gemini分为Ultra、Pro和Nano三个版本&#xff0c;并已开始在产品中使用。Ge…

openEuler社区与9大海外开源基金会深入合作,构建全球开源新生态

数字经济高速发展下&#xff0c;国产操作系统开源生态建设近年来取得里程碑式的重要进展。其中以openEuler为代表的开源系统正走向国际&#xff0c;在全球化方面取得实质性突破。 12月15日&#xff0c;以“崛起数字时代&#xff0c;引领数智未来”为主题的操作系统大会2023在北…

阿赵的虚幻引擎(UE)学习笔记

大家好&#xff0c;我是阿赵。   作为国内最早一批的Unity引擎使用者&#xff0c;Unity引擎我已经用了15年了。不过自从上次的Unity收费风波之后&#xff0c;估计很多Unity的使用者都有种危机感&#xff0c;假如有一天&#xff0c;Unity真的被游戏厂商所抛弃之后&#xff0c;…

TCP/IP详解——HTTPS 协议

文章目录 1. HTTPS 协议1.1 HTTPS 原理1.2 HTTPS 过程1.3 从数据包角度看 HTTPS 交互过程1.4 常见的 HTTPS 数据包解码1.4.1 ClientHello 数据包1.4.2 ServerHello 数据包 1.5 思考 1. HTTPS 协议 1.1 HTTPS 原理 HTTPS概念 HTTPS 是以安全为目标的HTTP通道&#xff0c;并不…

Python到机器学习再到深度学习:一条完整的人工智能学习之路

Python到机器学习再到深度学习&#xff1a;一条完整的人工智能学习之路 引言第一部分&#xff1a;Python基础第二部分&#xff1a;机器学习基础第三部分&#xff1a;深入深度学习 引言 简短介绍Python在数据科学和机器学习领域的重要性。概述本文的目标&#xff1a;提供一个清…

【MCAL】AUTOSAR架构下TC3xx平台的MCAL时钟系统配置实践

目录 前言 正文 1. MCU模块介绍 2. MCAL上的时钟Clock配置 2.1 AUTOSAR标准关于时钟的描述

Node.js 工作线程与子进程:应该使用哪一个

Node.js 工作线程与子进程&#xff1a;应该使用哪一个 并行处理在计算密集型应用程序中起着至关重要的作用。例如&#xff0c;考虑一个确定给定数字是否为素数的应用程序。如果我们熟悉素数&#xff0c;我们就会知道必须从 1 遍历到该数的平方根才能确定它是否是素数&#xff…

RabbitMq基本使用

目录 SpringAMQP1.准备Demo工程2.快速入门1.1.消息发送1.2.消息接收1.3.测试 3.WorkQueues模型3.1.消息发送3.2.消息接收3.3.测试3.4.能者多劳3.5.总结 SpringAMQP 将来我们开发业务功能的时候&#xff0c;肯定不会在控制台收发消息&#xff0c;而是应该基于编程的方式。由于R…

Ubuntu安装蓝牙模块pybluez以及问题解决方案【完美解决】

文章目录 简介问题及解决办法总结 简介 近期因工程需要在Ubuntu中使用蓝牙远程一些设备。安装Bluetooth的Python第三方软件包pybluez时遇到很多问题&#xff0c;一番折腾后完美解决。此篇博客进行了梳理和总结&#xff0c;供大家参考。 问题及解决办法 pip install pybluez安…

Kotlin 协程库v1.7.1的核心模块(kotlinx-coroutines-core)-- kotlinx.coroutines篇

asContextElement&#xff1a; 创建一个协程上下文元素(CoroutineContext.Element)&#xff0c;该元素可以被添加到协程上下文中&#xff0c;以便在特定的协程中检索和使用 注意&#xff1a;上下文元素不跟踪线程局部变量的修改 示例 val myThreadLocal ThreadLocal<Str…

大规模数据可视化(纯文字干货科普)

导读&#xff1a;探讨在处理大规模数据集时如何有效地进行数据可视化&#xff0c;如何在大数据分析中有效传达信息&#xff0c;包括交互式探索、实时仪表板和复杂数据故事讲述。 目录 大规模数据可视化的挑战 数据量问题 性能考量 实时数据 数据可视化的关键技术 数据预…

【算法Hot100系列】最长回文子串

&#x1f49d;&#x1f49d;&#x1f49d;欢迎来到我的博客&#xff0c;很高兴能够在这里和您见面&#xff01;希望您在这里可以感受到一份轻松愉快的氛围&#xff0c;不仅可以获得有趣的内容和知识&#xff0c;也可以畅所欲言、分享您的想法和见解。 推荐:kwan 的首页,持续学…

springboot(ssm川剧科普平台 川剧交流系统 Java系统

springboot(ssm川剧科普平台 川剧交流系统 Java系统 开发语言&#xff1a;Java 框架&#xff1a;ssm/springboot vue JDK版本&#xff1a;JDK1.8&#xff08;或11&#xff09; 服务器&#xff1a;tomcat 数据库&#xff1a;mysql 5.7&#xff08;或8.0&#xff09; 数据库…

NNDL 循环神经网络-梯度爆炸实验 [HBU]

目录 6.2.1 梯度打印函数 6.2.2 复现梯度爆炸现象 6.2.3 使用梯度截断解决梯度爆炸问题 【思考题】梯度截断解决梯度爆炸问题的原理是什么&#xff1f; 总结 前言&#xff1a; 造成简单循环网络较难建模长程依赖问题的原因有两个&#xff1a;梯度爆炸和梯度消失。 循环…

凸函数笔记(1)

目录 1. 凸函数基本概念2.可微函数的凸性判定2.1 函数凸性的微分判据2.2 可微凸函数的例子 3. 保凸运算3.1 复合函数的凸性3.2 几种保凸运算 1. 凸函数基本概念 记 R ‾ : R ∪ { ∞ } . 对函数 f : R n → R ‾ , 称 记\overline{\mathbb{R}}:\mathbb{R}\cup\{\pm\infty\}.…

【MySQL】(DDL) 表操作-查询

查询&#xff1a; show tables ; //查询所有表名称 desc 表名称 ; //查询表结构 show create table 表名称; //查看创建表语句 create table 表名 ( 字段名1 字段类型1,字段名2 字段类型2) ; //创建表结构 示列&#xff1a; 1. show tables; use 数据库名; show tables …