WorksheetsNNLT C++
Total questions: 61
Worksheet time: 3610secs
Thiếu dấu nháy kép (“) khi soạn thảo chương trình là lỗi gì?
Cú pháp.
Ngữ nghĩa.
Không có lỗi.
Lỗi sai NNLT
Trong C++, hãy chọn câu đúng trong bài toán có 2 tên được đặt sau đây?
1b , 2b
BT , Bai tap
bai*tap , bai_tap
bt , BT
Cho đoạn chương trình sau sau: int a,x,b;
cin>>a>>b>>x;
Tên nào là tên do người lập trình đặt?
a và b
a, b và x
cin
cout
Bảng chữ cái của C++, khác với Pascal là có sử dụng thêm kí tự:
dấu nháy đơn (')
dấu sổ xuôi (/)
dấu sổ ngược (\)
không thêm kí tự nào
Trong C++, “từ khóa” dùng để chỉ?
Tên
Tên dành riêng
Tên chuẩn
Tên do người lập trình đặt
“iostream” là loại tên gì trong C++?
Tên thường.
Tên dành riêng.
Tên chuẩn.
Tên do người lập trình đặt.
What does <= mean?
less than
greater than
less than or equal to
greater than or equal to
What is the only function all C++ programs must contain?
start()
system()
main()
program()
What punctuation is used to signal the beginning and end of code blocks?
{ }
-> and <-
BEGIN and END
( and )
Which of the following is a correct comment?
*/ Comments */
** Comment **
/* Comment */
{ Comment }
What does <= mean?
less than
greater than
less than or equal to
greater than or equal to
y = 3;
x = 5 * y;
Program
int main()
{
cout<<"Hi everybody";
return 0;
}
Which of the following is NOT a logical operator in C++ language?
&
&&
||
!
Which of the following is NOT a comparison operator in C++ language?
>
<=
=
==
Evaluate the following expressions to true or false
3!=4-1
true
False
Evaluate the following expressions to true or false
5 >= (1+6)-4
True
False
Evaluate the following expressions to true or false
5+1==6 || 8-1>4
True
False
If originally x=2,y=0, and z=1, what is the value of x, y, and z after executing the following code?
if (x>y)
y=x;
else
z=x;
x=2 y=2 z=1
x=0 y=2 z=0
x=2 y=1 z=1
x=2 y=0 z=1
If-else
Optional value for the program to execute
Is a condition followed by a statement or a set of statements
Is a statement followed by a condition or a set of conditions
Function with a value
What happens if an exception is thrown in a function, but not caught?
The program continues executing and it is ignored.
The function that throws the exception is exited.
The program terminates.
The compiler will find the error and the program would not compile.
What is the difference between an array and STL, Standard Template Library, array?
They are the same thing.
STL array is a dynamic array
Array size must be known at compile time but, STL array size does not.
Array is a data structure and STL array is an instance of a class.
There can only be one catch block in a program
True
False
The compiler creates an instance of a function template in memory as soon as it encounters the template.
True
False
When a class becomes a friend of another class they are additionally getting access to:
Private
Protected
Public
None of the above
When a class is derived from a base class it gets access to:
Private
Protected
Private and Protected
Protected and Public
Private, Protected and Public
In a class the access specifiers are _______ by default:
Private
Protected
Public
What does the word const do when placed at the end of a member function in a class?
It is required for C++
States the return type is constant
States the input arguments are constant
States the member variables will not change
None of the above
Equal strings
There will be a compile error and it will not run
Nothing will be output on the console
None of the above
I only
II only
III only
I and II only
II and II only
When class B is inherited from class A, what is the order in which the destructors are called.
Class A first Class B next
Class B first Class A next
Class B's only as it is the child class
Class A's only as it is the parent class
What does the word virtual do when placed in front of a member function in C++?
Forces derived classes to define the function to compile.
Allows derived classes, not required, to define the function.
Does not place the function in text segment if it is not called.
None of the above.
What happens if the word static is placed in front of a member function in C++?
The member function can be called even if we do not create an instance of the class.
It places the member function in the static part of memory
It will cause an error and the program will not compile.
None of the above.
When overloading a function, the signature of the function is determined by:
The name of the function
The name of the function and number of argument and types
The return type, name and number of arguments and types.
The derived class can not call the base class func().
Must place “using namespace Base” at the top of the file.
Base::d.func();
d.Base::func();
1
6
12
24
What is the difference when allocating the following memory?
int array1[15];
int array2[3][5];
array1 is larger
array2 is larger
The size allocated is the same
1
2
4
8
0
5
-5
10
-10
0
1
2
3
There are two count variables. Not enough info
Compile Error
Inside Fun1()
Inside Fun2()
Inside Fun1() Inside Fun2()
Inside Fun2() Inside Fun1()
Inside try
Exception Caught
After throw
After catch
Inside try
Exception Caught
After catch
Inside try
Exception Caught
Inside try
After throw
After catch
A function can have _____ inside the parenthesis
loops
Arguments/Parameters
Braces
Types
A function that has no return type starts with:
int
void
Arguments
Braces
A function that returns a whole number starts with the word
int
void
string
{ }
Fill in the blank to have this function work properly
_____ function ( ) {
int a = 4;
int b = 5;
cout<<a*b;
}
string
int
void
variable
Fill in the blank to have this function work properly
_____ function ( ) {
string greeting = "Welcome to my game";
return greeting;
}
string
void
int
variable
Fill in the blank to have this function work properly
_____ function ( ) {
int a;
cin >> a;
cout<<"You chose " << a <<endl;
}
string
void
int
variable
True or False. We can call functions inside of other functions.
True
False
True or False. A function that returns a string starts with the word void.
True
False
Select all of the types you may have for a function
string
bool
void
variable
int
A function that is not void needs to have a _____ _______
variable calculation
printing statement
Return statement
cout statement
Fill in the blank to have this function work properly
double function ( ) {
int a;
cin >> a;
cout<<"You chose " << a <<endl;
return ____ ;
}
"a"
a
a * 3.14
cin
Choose a right C Statement.
Loops or Repetition block executes a group of statements repeatedly.
Loop is usually executed as long as a condition is met.
Loops usually take advantage of Loop Counter
All the above.
