辅导C++留学生编程、讲解program程序、辅导C++编程语言

- 首页 >> Matlab编程
C++ quiz
[ATTENTION]
1) All questions are single choice by default, except for those marked multiple choices.

1. Which module is not in the common layer? ( )
A. DB
B. Functions
C. TX/RX module
D. Trace, eLog


2. Which is not correct about the common layer? ( )
A. common layer Contains classes that are used by other layers, math functions, frameworks, etc.
B. All layers can depend on common layer
C. Modules in Common layer have dependencies to other layers
D. DB belongs to the common layer


3. The best way to get the control Hardware info in Service layer or above layers is? ( )
A. define a macro of control Hardware info in service layer directly
B. create a new interface to read from the DB.
C. Communicate with hardware directly
D. All above


4. Which interface is not in the O&M layer? ( )
A. TRDCI
B. RMCI
C. RFTI
D. Fault Manager


5. [Multiple choice] Find out all the right modules that belong to Common layer. ( )
A. RMCI
B. TRDCI
C. Libraries
D. DB

6. Regarding modern language features, which one of below options is not preferred? ( )
A. std::string
B. static_cast
C. typedef
D. new, delete


7. which one of below options is preferred in the new language features? ( )
A. struct
B. new []
C. nullptr
D. iterators



8. Which option about variable definition is correct? ( )
A. uint16_t m_deviceId;
B. Carrier_v1* m_lrciCarrier;
C. double pi {3.14};
D. None of the above


9. [Multiple choice] What are the correct descriptions about C++ standard library header files? ( )
A. Use the official header without a .h.
B. The legacy .h files do not place their symbols in the std namespace.
C. Using legacy .h may lead to unexpected behavior.
D. None of the above.


10. Which is not preferred way to define the array? ( )
A. char ccPortName[8][4];
B. static constexpr std::array NCPSEC_G{4, 5, 6, 5, 16}
C. std::array m_auxAdcCfg;
D. None of the above.


11. [Multiple choice] Which ones are the correct description about Naming rules? ( )
A. Use understandable names, avoid abbreviations.
B. A name is either a single word or a concatenation of words.
C. Type names shall begin with a lower-case letter.
D. File names shall begin with a lower-case letter.


12. Which below description is incorrect for goto? ( )
A. Usage of goto shall be avoided.
B. The goto complicates the code.
C. If it is needed, goto is recommended.


13. Which of following description regarding lvalue and rvalue is incorrect? ( )
A. User can write to lvalue reference
B. const lvalue is immutable constant to the user
C. rvalue reference is that the user can move the object referred to assuming it will never be used again.
D. lvalue and rvalue reference exist in C++ 98


14. [Multiple choice] Which of following definitions and assignments are correct? ( )
A. const int a = 10;
B. const int a = 10;
auto &b = a;
C. int a = 10;
int &b =a;
D. const int a = 10;
const auto b = a;
b = 20;
15. [Multiple choice] What kind of constructor or operator are used below? ( )
class Someclass
{
public:
Someclass(const Someclass &) = default;
Someclass & operator=(const Someclass &) = default;
};
A. Copy constructor
B. Move constructor
C. Copy assignment operator
D. Move assignment operator


16. Please select the proper lambda function to get the output 6? ( )
int a{5};
std::cout << f() << std::endl;

A. auto f = []{ return ++a;};
B. auto f = [a] {return ++a;};
C. auto f = [&] {return a;};
D. auto f = [=] () mutable {return ++a;};


17. What is the output of the following program? ( )
int a{};
auto f = [=]{ return a+2;};
a += 1;
std::cout << f() << std::endl;
A. 3
B. 2
C. 1
D. 0

18. Which expression can not pass the compilation? ( )
A. int a = 2.2;
B. int b = {2.3};
C. std::vector v{ 1, 2, 3, 4 };
D. std::array values {0.5, 1.0, 1.5, 2.0};


19. Which vector function is used to reversal iteration? ( )
A. vec.begin()
B. vec.cbegin()
C. vec.rbegin()
D. vec.cend()


20. Which description is right about variadic templates’ parameters? ( )
A. The numbers of parameters are restricted.
B. The types of parameters are restricted.
C. The numbers and types of parameters are unrestricted.
D. The numbers of parameters are unrestricted, but the types of parameters are restricted.


21. Which one is right format to use a variadic templates? ( )
A. template
B. template< typename T, typename, TRest>
C. template
D. template


22. [Multiple choice] Which of the following objects can use constexpr? ( )
A. functions;
B. variables
C. pointers
D. references


23. Related to sum calculation (don’t consider overflow), which of the following is true? ( )
A.
auto sum (int i)
{
if (i != 1)
return sum(i-1)+i;
return i;
}
B.
auto sum (int i)
{
if (i == 1)
return i;
return sum(i-1)+i;
}



24. About “alternate type deduction on declaration”, which of the following statements is wrong? ( )
int i;
int&& f();
auto x3a = i;
decltype(i) x3d = i;
auto x4a = (i);
decltype((i)) x4d = (i);
auto x5a = f();
decltype(f()) x5d = f();
A. decltype(x3a) is int, decltype(x4a) is int, decltype(x5a) is int
B. decltype(x3d) is int&
C. decltype(x4d) is int&
D. decltype(x5d) is int&&


25. Here is an example of “Variable templates”,
-----------------------------
template
constexpr T pi = T(3.141592653589793238462643383);
// Usual specialization rules apply:
template<>
constexpr const char* pi = "pi";
auto intPi = pi; //3
auto lessPi = pi; //3.14159274, lower precision
auto morePi = pi; //3.1415926535897931, higher precision
auto strPi = pi;//pi
-----------------------------
Which of the following statements is true? ( )
A. Since C++11, not only functions, classes or type aliases could be templated, but also allows the creation of variables that are templated.
B. Before C++14, only functions, classes or type aliases could be templated. C++14 now allows the creation of variables that are templated.


[Bonus question]

This question is about the using of std::function, std::bind, lambda, please fill in the blanks.

#include
#include

class Foo {
public:
void printSum(const int &n1, const int &n2)
{
std::cout << n1+n2 << std::endl;
}
};
double myDivide(const double &x, const double &y)
{
return x/y;
}

int main ()
{
// std::function + std::bind member function
// implement add by 5, using printSum of class Foo.
Foo foo;
std::function add = std::bind(Q2, Q3, 5, std::placeholders::_1);
add(5);

// std::function + std::bind normal function
// implement divide by 2, using the function myDivide.
auto half = std::bind (Q4,Q5, 2);
std::cout << half(10) << std::endl;

// lambda expression
int a{};
auto f = [&]{ return a+2;};
a += 1;
std::cout << f() << std::endl;//output will be Q6

return 0;
}

Please write down the answers to questions of Q1 ~ Q6 in the below:

Q1:

Q2:

Q3:

Q4:

Q5:

Q6:

站长地图