注册一亩三分地论坛,查看更多干货!
您需要 登录 才可以下载或查看附件。没有帐号?注册账号 
x
新人求米, 帖子评分加米不扣米,
1.Which of the following conversions is Implicit in C++17 and C++20? Select all that apply.
Pick ONE OR MORE options
conversion of a pointer-to-derived to a pointer-to-base
conversion of an Integer to an enumerator of an enum class
conversion of an array-of-T to a pointer-to-T
conversion of a non-const reference-to-T to a const reference-to-T
conversion of a function pointer to void*
conversion of a Boolean to an integer
2.Implicit Conversions
Which of the following conversions is Implicit in C++17 and C++20? Select all that apply.
Pick ONE OR MORE options
conversion of a pointer-to-derived to a pointer-to-base
conversion of an Integer to an enumerator of an enum class
conversion of an array-of-T to a pointer-to-T
conversion of a non-const reference-to-T to a const reference-to-T
conversion of a function pointer to void*
conversion of a Boolean to an integer
3. Structure Sizes
On a 64-bit architecture (i.e. one on which a memory address is represented by 8 bytes), what is the output of the following C++20 program?
#include <iostream>
struct Foo final
{
int x;
char c1;
union { int y; bool z; } u;
char c2;
void *z;
char c3;
char c4[6];
char c5;
};
int main() {
std::cout << sizeof(Foo) << std::endl;
return 0;
}
Pick ONE option
19
24
24
28
28
32
22
36
none of the above
4. Template Member Functions
Which of the following statements is true about a member function of a templated class In C++17 and C++20? Select all that apply.
Pick ONE OR MORE options
its implementation must be visible to the compiler at each point of invocation
it cannot be virtual
it cannot be constexpr
the machine code for its implementation may appear multiple times in a binary that uses it
calls to the function will always be inlined
if the function is never invoked, it is possible that its implementation contains a syntax error
5. Locking
Which of the following is true about the C++20 function fn defined below?
#include <array>
#include <mutex>
extern std::array<bool, 1000> dataj
int fn(int k, bool f) {
static std::mutex mutex();
std::lock_guard<std::mutex> guard (mutex);
data[k] = fi
return data[k]}
}
Pick ONE option
assuming there are no other functions Interacting with data, fn cannot deadlock
a call to fn will always return Its second argument
the read of data[k] In the return statement may Induce a segmentation fault if a different thread is writing to that array Index at the same time
the destructor of the mutex variable will run each time the function exits
6. Move Semantics
Which of the following is true about the assignment x = std::move (y) In C++17 and C++20, assuming x and y are both of the same type and that the appropriate header files are visible? Pick ONE option
it is always strictly faster than the assignment x=y
it may induce a compiler error
reading from y after the assignment is undefined behavior
after the assignment, it is guaranteed that x = y, assuming that operatorl= is defined for the type of the variables
7. Small-String Optimization
What is the small-string optimization in C++?
Pick ONE option
a faster implementation of certain Standard Library algorithms that is used when the length of a string is under some
constant
a feature of modern linkers whereby "short" strings are placed in a special segment of memory that is physically closer to the program's instruction stack
that fact that only one copy of a string literal is stored in memory even if the same string literal is used multiple times throughout a program is
the fact that, for strings of sufficiently few characters, std::string does not require any heap-allocated memory
the fact that converting a std::string to a std::string_view (in C++17 and later) has average time complexity O(N) in the length of the string, and is therefore more efficient for shorter strings
8. Template Instantiations
Which of the following Instantiations of the templated struct C will compile in C++17 and C++20, assuming the proper headers are available? Select all that apply.
#include <type_traits>
template <typename T, template <typename> typename U, int V>
struct C final
{
};
static_assert(std::is_copy_constructible_v<T>);
Pick ONE OR MORE options
C<int, std::optional, 100>
C<std::string, std::vector, 0
C<void*, std::map, 18274124>
C<std::tuple<int, char&>, std::atomic, 300>
C<std::stringstream, std:initializer_list, ->>>
C<std::unique_ptr<int>, std::list, 17>
C<std::shared_ptr<int>, std::d4 points on her first bake, leaving her with 4 points outstanding:
■She could then bake with W₁, with a 30% chance of earning the 4 points she needs
■She could then bake with W₂ again, with a 10% chance of earning the 4 points she needs
■She could then bake with W3, with a 10% chance of earning the 4 points she needs
• There is a 45% chance that she earns 3 points on her first bake, leaving her with 4 points outstanding
■She could then bake with W₁, with a 10% chance of earning the 5 points she needs
■ She could then bake with W3, with a 20% chance of earning the 5 points she needs
•If she starts with W3, then she has 8 ways to earn exactly 8 points:
• There is a 20% chance that she earns 5 points on her first bake, leaving her with 3 points outstanding:
■ She could then bake with W₁, with a 20% chance of earning the 3 points she needs
■ She could then bake with W2, with a 45% chance of earning the 3 points she needs
■ She could then bake with W3 again, with a 10% chance of earning the 3 points she needs
• There is a 10% chance that she earns 4 points on her first bake, leaving her with 4 points outstanding:
■She could then bake with W₁, with a 30% chance of earning the 4 points she needs
■ She could then bake with W2, with a 10% chance of earning the 4 points she
needs
■ She could then bake with W3 again, with a 10% chance of earning the 4 points
she needs
• There is a 10% chance that she earns 3 points on her first bake, leaving her with 5 points outstanding:
■ She could then bake with W₁, with a 10% chance of earning the 5 points she needs
■ She could then bake with W3 again, with a 20% chance of earning the 5 points she needs
/// @param pointsNeeded The e /// @param bakes The number o /// @param probabilities The /// probability of earning /// @pre pointsNeeded >= 1 /// @pre bakes >= 1
/// @pre probabilities [x][y] /// @pre the sum of probabili /// @returns The probability 1 /// her waffle mixes, given /// the exact requisite numb double championshipProbability // implement me!
38 > #include <fstream> ...
The final probabilities break down like this:
• Choosing W₁ to bake with first - (10% x 45% ) + ( 30% x 30% )+(20% x 20%) = 17.5%
• Choosing W₂ to bake with first- (10% x 30 %) + (45% x 20%)
= 12.0%
• Choosing W3 to bake with first - (20% x 45% ) + ( 10% x 30% ) + ( 10% x 20%) = 14.0%
The function should therefore return 0.175. |