水一篇清朝老卷
?
?
诚信应考,考试作弊将带来严重后果!
?华南理工大学期末考试
《C++程序设计(I)》试卷 A
- Which of the following is true? (??? )
A)Structures may contain many data types.
B)Members of different structures must have unique names.
C)Keyword typedef is used to define new data types.
D)Structures are always passed to functions by reference.
1) 以下哪项是正确的?(??? )
A)结构体(Structures)可以包含多种数据类型。
B)不同结构体的成员必须具有唯一的名称。
C)关键字typedef用于定义新的数据类型。
D)结构体总是通过引用传递给函数。
答案:
A)结构体(Structures)可以包含多种数据类型。
- Which of the following is false? ( D?? )
?A) char a[20]=”abcdefg”;????? B) char a[]=”x+y=55.”;
?C) char a[15]={’1’,’2’};? ?????D) char a[10]=’5’;
2) 以下哪项是错误的?( D?? )
A) char a[20]=”abcdefg”;?????
B) char a[]=”x+y=55.”;
C) char a[15]={’1’,’2’};??????
D) char a[10]=’5’;
答案:
D) char a[10]=’5’;
- Which of the following logical expression is equal to? !(x>0 || y==5)(? B )。
A) x<=0 || y!=5??????? B) x<=0 && y!=5
C) x>0 || y!=5???????? D) x>0 && y==5
3) 以下哪个逻辑表达式等价于 !(x>0 || y==5)( B )。
A) x<=0 || y!=5???????
B) x<=0 && y!=5??????
C) x>0 || y!=5???????
D) x>0 && y==5???????
答案:
B) x<=0 && y!=5
- How many errors in the following statements? (???? )
struct d {
????? ??????int a;
??? ????????double a;
} a,d;
A)1???????????? B)2??????? C)3????????????? D)4
#include<iostream>
using namespace std;
struct d {
??? int a;
} ;
int main()
{
??? d d;
}
这是能运行的
- Assume i=2,j=2,the result of the expression (i++)+(++j) is( ?B ??)。
A)4???? ??????????B)5????????? C)6???? ?????????D) 7
- Assume a=1,b=2,c=3,d=4,the result of the expression ?a>b?a:c>d?c:d is(? ???)
A)1??????? B)2????????? C)3??????? D)4
D
- After the following statements is performed, the value of x is ( ???)。
unsigned x=10;? x<<=2;
A) 10??? ??????B)20?? ????????C)30??? ??????D)40
D
- Which of the following is false (?? ?)
- Recursive calls take time and consume additional memory.
B) Recursive functions are the functions that call themselves directly. - 递归可以间接调用
C) One advantage of the recursive functions is easy to understand.
D) If no base case,the recursive function will infinite loops.
- Which operator has the highest precedence?( ????)
A)!??????? B)&&????? ?C)!=?????? D)?:
A
?????????????????????????????????????????
- Assume? which program is correct ( ?C? ?)
A)y=3*x*x*x;?????????????????????????????????????????????? B) y = 3*x*x*x;
?? if ( x ! = 0)??????????????????????????? if ( x <= 0)
?? else? if ( x >=0) y=5*x;???????????????? else if ( x = = 0) y = 3*x*x+7;
?? else y = 3*x*x+7;?????????????????????? else? y = 5*x;
C)if ( x >= 0)????????????????????????????????????????????????? D)? y = 3*x*x+7;
??? if ( x > 0) y = 5*x ;??????????????????? if ( x <= 0 )
??? else? y = 3*x*x+7 ;??????????????????? else if( x < 0 ) y = 3*x*x*x;
????? else?? y = 3*x*x*x;?????????????????????? else? y = 5*x;
- After the following statements is performed, the value of a[0],a[1],a[2] are ( 10.12.12? ?)
int a[ ]={10,11,12}, *p=&a[0];p++;(*p)++;
?A)10,11,12????? ???????B)11,12,12???
?C)10,12,12 ????????????D)11,11,12
- Assume i=1,after the following statements is performed, the value of i is( ???4 ?)。
switch(i)
{case 1:i++;
?case 2:i++;
?case 3:++i;break;
?case 4:--i;
?default:i++;
}
A) 1????? ????B) 2???????? C) 3???? ??????D) 4
- Which of the following is ture ( D??? )
A)The default case is required in the switch selection structure.
B)The break statement is required in the default case of switch selection structure to exit the structure properly.
C)The expression (x>y && a<b ) is true if either the expression x>y is true or a<b is true.
D)An expression containing the || operator is true if either or both of its operands are true.
- Which of the following is ture (???? )
A)An array can store many different types of values.
B)An array subscript should normally be of data type float.
C)If there are fewer initializers in an initializer list than the number of elements in the array, the remaining elements are initialized to the last value in the list of initializers.??
D)It is an error if an initializer list contains more initializers than the number of elements in the array.
翻译:
A)一个数组可以存储许多不同类型的值。
B)数组的下标通常应该是浮点型数据类型。
C)如果在初始化列表中的初始化器数量比数组中元素的数量少,剩余的元素会被初始化为初始化列表中的最后一个值。
D)如果初始化列表中包含的初始化器数量超过数组中元素的数量,这将是一个错误。
解答:
A)正确。数组可以存储相同数据类型的元素,但这些元素可以是任何合法的数据类型,包括基本数据类型和用户定义的数据类型。
B)错误。数组的下标应该是整数类型,通常是int。浮点型数据类型不是合法的数组下标。
C)正确。如果初始化列表中的初始化器数量少于数组中元素的数量,剩余的元素会被初始化为初始化列表中的最后一个值。
D)错误。C选项已经说明了如果初始化器列表中的初始化器数量少于数组中元素的数量,这是允许的。然而,如果初始化列表中的初始化器数量超过数组中元素的数量,这将是一个错误。
- Which of the following is ture (? A?? )
A)Pointers of any type can be assigned to void pointers.
B)The address operator & can be applied only to constants and to expressions
C)A pointer that is declared to the type void can be dereferenced.??
D)Pointers of different type may not be assigned to one another without a cast operation.
The correct answer is:
A)Pointers of any type can be assigned to void pointers.
解释:
A)正确。`void`指针是一种特殊类型的指针,可以用来存储任何类型的指针。因此,任何类型的指针都可以赋值给`void`指针。
B)错误。地址运算符`&`可以应用于变量和表达式,而不仅仅是常量。
D)错误。指针之间的赋值通常需要进行类型匹配,但可以通过强制类型转换来实现指针类型的转换。
- Assume
struct? worker
{ int? no ;
char name[ 20 ] ;
};
worker w,*p = &w ;
which of the following is false (? ?????)。
A) w.no?? ??? ??????B) p -> no???????? C) ( *p ).no?????? ?????D) *p.no
D
- Which of the following is false( C? ?)
A)int a[2][3]={0}??????????????????????????????????? B)int a[][3]={{0,1},{0}}
C)int a[2][3]={{0,1},{2,3},{4,5}}???????? D)int a[][3]={0,1,2,3,4,5} - The function prototype of fun3 is: void? fun3(int &),which of the following is true:( ????)
A)int? x=2.17; fun3(&x)?????????????????????? B)int a =15;? fun3(a*3.14)
C)int? b=100;? fun3(b)???????????????????????? D)fun3(256) - C
- Assume the statement using std::cout; is used, which of the following is false ( D ??)
A)All variables must be declared before they are used.
B)All variables must be given a type when they are declared.
C)Declarations can appear almost any where in the body of a C++ function.
D)A C++ program that prints three lines of output must contain three out statements using cout.
- 2. Please write out the performed results of the following programs。(24 scores)
- #include <iostream>
using namespace std;
void? main()
{?? int i, j, k=0;
for(i=0;i<3;i++){
?? k++;
?????????? ? for(j=0;j<3;j++){
?if(!(j%2)) continue;
? ????????? k++;
??????? }
?????????? ? if(!(j%2)) break;???
???? }
? cout<<"k="<<k<<endl;
}
显而易见
- #include <iostream>
using? namespace std;
void? main()?????????????????????????????
{ char *p, a[]= "I Love C++" ;
????? for(p=a; *p!='\0' ;)
?????? { cout<<p<<endl;
? ?????? p++;
? ?????? if(*p != '\0' ) p++ ;
? ?????? else? break;?
?????? }
}
I Love C++
Love C++
ve C++
?C++
++
- #include <iostream>
using namespace std;
int? f(int);
void? main()
{? int x=4,i;
?? for(i=0;i<2;i++)?
?????? cout<<f(x)<<endl;
}
int f(int a)
{? int b=0;
?? static int c=3;
?? b*=a;? c*=a;
?? return (a+b+c);
}
- #include<iostream>
using? namespace std;
void main()
{
? int temp,value,a,b,c,d;
? value=temp=a=b=c=d=0;
?do
? {?? cout<<"Enter a four-digit integer :";
??????? a=cin.get()-48;
? ??? b=cin.get()-48;
? ??? c=cin.get()-48;
? ??? d=cin.get()-48;
?????????? if ((a>=0)&&(a<=9)&&(b>=0)&&(b<=9)&&(c>=0)&&(c<=9)&&(d>=0)&&(d<=9))
?????????? ??? value=a*1000+b*100+c*10+d;?????????????
? }while (!value);
? ?a=(a+7)%10;b=(b+7)%10;?? c=(c+7)%10;?? d=(d+7)%10;
? ?temp=a;? a=c;? c=temp;
? temp=b;? b=d;????? d=temp;
? ?cout<<"The orginal number is : "<<value<<endl;
? ?cout<<"The encrypt number is : "<<a<<b<<c<<d<<endl;
}
Input:1234
Output:
- #include <iostream>
using namespace std;
int function1(int, int);
int main()
{
? cout<<"The result is:"<< function1(2,10) <<endl;
? return 0;
}
int function1(int a, int b)
{? if ( b<=1)
? ???return a;
?else
?? ??return a* function1(a,b/2);
}
- 3.Fill in 【??? ???】 according to the request of the subjects(20 scores).
- The following program finds the maximum in a matrix and gives the position of the maximum. ?
#include <iostream>
using namespace std;
【 ???????????????????????????????????????????????】
【 ???????????????????????????????????????????????】
void findmax ( int a[ ][n]);
void main()
{ int a[m][n]={1,2,3,4,5,6,7,8,9,10,1,2};
? ?findmax(a);
}
void findmax( int b[][n])
{ int max,maxrow,maxcol;
? 【?
???????????????????????????????????????????????????????? 】
? for (int i=0;i<m;i++)
??? for (int j=0;j<n;j++)
? ??? ?if (b[i][j]>max)
?????????? ?{
?????????? ?? 【???????????????????????????????????????????????????? 】
?????????? ?}
??cout<<"The maximum in the matrix is "<<max<<endl;
cout<<"The maximum position is row:"<<maxrow<<"column:"<<maxcol<<endl;
}
#include <iostream>
using namespace std;
const int m = 3;
const int n = 4;
void findmax(int a[][n]);
void main()
{
??? int a[m][n] = { 1,2,3,4,5,6,7,8,9,10,1,2 };
??? findmax(a);
}
void findmax(int b[][n])
{
??? int max, maxrow, maxcol;
??? max = 0;
??? maxrow = 0;
??? maxcol = 0;
??????? for (int i = 0; i < m; i++)
???????????? for (int j = 0; j < n; j++)
???????????????? if (b[i][j] > max)
???????????????? {
???????????????????? maxrow = i;
???????????????????? maxcol = j;
???????????????? }
??? cout << "The maximum in the matrix is " << max << endl;
??? cout << "The maximum position is row:" << maxrow << "column:" << maxcol << endl;
}
- The following program sorts the strings in descending order and prints out the result.
#include <iostream>
using std::cout;
using std:endl;
#include <cstring>
void? sortstr(【????????????? ?????????????????????】, int n)?
{ int i, j, k;
? char * temp;
? for(i=0; i<n-1; i++)
??? { k=i;
???? for( j=i+1;j<n; j++)????????????????? ??
? ?? ??if? (【???????????????? ??????????????????????】 )
?k=j;
}
}
void? main()
{ int? i;
?char *pname[4]={"pascal",? "Visual Basic",? "Visual C++",? "lisp"};
?sortstr(【??????????? ?????????????????????????】); ??????? ??????????
?for(i=0;i<4;i++)
?cout<<pname[i]<<endl;
}
#include <iostream>
using std::cout;
using std::endl;
#include <cstring>
void sortstr(char **arr, int n)?
{
??? int i, j, k;
??? char *temp;
??? for(i = 0; i < n - 1; i++)
??? {
??????? k = i;
??????? for(j = i + 1; j < n; j++)
??????? {
??????????? // Compare strings in descending order
??????????? if (strcmp(arr[j], arr[k]) > 0)
??????????????? k = j;
??????? }
??????? // Swap strings if needed
??????? if (k != i)
??????? {
??????????? temp = arr[i];
??????????? arr[i] = arr[k];
??????????? arr[k] = temp;
??????? }
??? }
}
int main()
{
??? int i;
??? char *pname[4] = {"pascal", "Visual Basic", "Visual C++", "lisp"};
???
??? // Call the sortstr function to sort the strings in descending order
??? sortstr(pname, 4);
??? // Print the sorted strings
??? for (i = 0; i < 4; i++)
??????? cout << pname[i] << endl;
??? return 0;
}
- The following program is binary search of an array.
#include <iostream>
#include <iomanip>
using namespace std;
int binarySearch( const int [], int, int, int, int );
int main()
{ ?????const int arraySize = 15;?
?????? int a[ arraySize ], key;???????????????
?????? for ( int i = 0; i < arraySize; i++ )? // create some data
????????? a[ i ] = 2 * i;??
?????? cout << "Enter a number between 0 and 28: ";
?????? cin >> key;
?????? int result = binarySearch( a, key, 0, arraySize - 1, arraySize );
?????? if ( result != -1 )
????????? cout << '\n' << key << " found in array element "<< result << endl;
?????? else
????????? cout << '\n' << key << " not found" << endl;
?????? return 0;
??? }???
??? int binarySearch( const int b[], int searchKey, int low, int high, int size )
??? { ?int middle;
???? ??while (【?????????????????????????? 】 ) {
???????? ???【???????????????????????????????? 】 ;?
????? ??????if (【 ???????????????????????????????】 )? // match
??????????? ?????return middle;
??????? ????else ?if (【? ?????????????????????????????】)
?????????????? ???high = middle - 1;
???????????? ????else
??????????????? ???low = middle + 1;
???? ???}
?????? return -1;?
?? } // end function binarySearch
#include <iostream>
#include <iomanip>
using namespace std;
int binarySearch(const int[], int, int, int, int);
int main()
{
??? const int arraySize = 15;
??? int a[arraySize], key;
??? for (int i = 0; i < arraySize; i++) // create some data
??????? a[i] = 2 * i;
??? cout << "Enter a number between 0 and 28: ";
??? cin >> key;
??? int result = binarySearch(a, key, 0, arraySize - 1, arraySize);
??? if (result != -1)
??????? cout << '\n' << key << " found in array element " << result << endl;
??? else
??????? cout << '\n' << key << " not found" << endl;
??? return 0;
}
int binarySearch(const int b[], int searchKey, int low, int high, int size)
{
??? int middle;
??? while (low <= high)
??? {
??????? middle = (low + high) / 2;
??????? if (b[middle] == searchKey) // match
??????????? return middle;
??????? else if (b[middle] > searchKey)
??????????? high = middle - 1;
??????? else
??????????? low = middle + 1;
??? }
??? return -1;
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!