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

2023-12-17 12:52

本文主要是介绍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__________________

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

这篇关于C++试卷(华南理工大学)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/504432

相关文章

从入门到精通C++11 <chrono> 库特性

《从入门到精通C++11<chrono>库特性》chrono库是C++11中一个非常强大和实用的库,它为时间处理提供了丰富的功能和类型安全的接口,通过本文的介绍,我们了解了chrono库的基本概念... 目录一、引言1.1 为什么需要<chrono>库1.2<chrono>库的基本概念二、时间段(Durat

C++20管道运算符的实现示例

《C++20管道运算符的实现示例》本文简要介绍C++20管道运算符的使用与实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧... 目录标准库的管道运算符使用自己实现类似的管道运算符我们不打算介绍太多,因为它实际属于c++20最为重要的

Visual Studio 2022 编译C++20代码的图文步骤

《VisualStudio2022编译C++20代码的图文步骤》在VisualStudio中启用C++20import功能,需设置语言标准为ISOC++20,开启扫描源查找模块依赖及实验性标... 默认创建Visual Studio桌面控制台项目代码包含C++20的import方法。右键项目的属性:

c++中的set容器介绍及操作大全

《c++中的set容器介绍及操作大全》:本文主要介绍c++中的set容器介绍及操作大全,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录​​一、核心特性​​️ ​​二、基本操作​​​​1. 初始化与赋值​​​​2. 增删查操作​​​​3. 遍历方

解析C++11 static_assert及与Boost库的关联从入门到精通

《解析C++11static_assert及与Boost库的关联从入门到精通》static_assert是C++中强大的编译时验证工具,它能够在编译阶段拦截不符合预期的类型或值,增强代码的健壮性,通... 目录一、背景知识:传统断言方法的局限性1.1 assert宏1.2 #error指令1.3 第三方解决

C++11委托构造函数和继承构造函数的实现

《C++11委托构造函数和继承构造函数的实现》C++引入了委托构造函数和继承构造函数这两个重要的特性,本文主要介绍了C++11委托构造函数和继承构造函数的实现,具有一定的参考价值,感兴趣的可以了解一下... 目录引言一、委托构造函数1.1 委托构造函数的定义与作用1.2 委托构造函数的语法1.3 委托构造函

C++11作用域枚举(Scoped Enums)的实现示例

《C++11作用域枚举(ScopedEnums)的实现示例》枚举类型是一种非常实用的工具,C++11标准引入了作用域枚举,也称为强类型枚举,本文主要介绍了C++11作用域枚举(ScopedEnums... 目录一、引言二、传统枚举类型的局限性2.1 命名空间污染2.2 整型提升问题2.3 类型转换问题三、C

C++链表的虚拟头节点实现细节及注意事项

《C++链表的虚拟头节点实现细节及注意事项》虚拟头节点是链表操作中极为实用的设计技巧,它通过在链表真实头部前添加一个特殊节点,有效简化边界条件处理,:本文主要介绍C++链表的虚拟头节点实现细节及注... 目录C++链表虚拟头节点(Dummy Head)一、虚拟头节点的本质与核心作用1. 定义2. 核心价值二

C++ 检测文件大小和文件传输的方法示例详解

《C++检测文件大小和文件传输的方法示例详解》文章介绍了在C/C++中获取文件大小的三种方法,推荐使用stat()函数,并详细说明了如何设计一次性发送压缩包的结构体及传输流程,包含CRC校验和自动解... 目录检测文件的大小✅ 方法一:使用 stat() 函数(推荐)✅ 用法示例:✅ 方法二:使用 fsee

Windows下C++使用SQLitede的操作过程

《Windows下C++使用SQLitede的操作过程》本文介绍了Windows下C++使用SQLite的安装配置、CppSQLite库封装优势、核心功能(如数据库连接、事务管理)、跨平台支持及性能优... 目录Windows下C++使用SQLite1、安装2、代码示例CppSQLite:C++轻松操作SQ