Morgan Stanley OA题库

原地址:http://blog.csdn.net/donhao/article/details/5661039

【Q1】 Which of the following statements accurately describe unary operator overloading inC++?

A.    Aunary operator can be overloaded with one parameter when the operator functionis a class member.

B.    A unary operator can beoverloaded with one parameter when the operator function is free standingfunction (not a     class member).

C.    Aunary operator can only be overloaded if the operator function is a classmember.

D.    A unary operator can beoverloaded with no parameters when the operator function is a class member.

E.    A unary operator can beoverloaded with no parameters when the operator function is a free standingfunction (not a class member).

 

【Q2】 Which of the following statements correctly describe the code below in C++?

#definelanguage 437                   //Line1

#iflanguage < 400

#undeflanguage                          //Line2

#else                                          //Line3

#definelanguage850                   //Line4

#ifdeflanguage                           //Line5

printf("%d",language);        //Line 6

#endif

#endif

A.    Anerror or warning will occur on Line 6 because a macro cannot be used as part ofa preprocessor directive.

B.    Anerror or warning will occur on Line 2 because #undef is not a valid preprocessordirective.

C.    An error or warning willoccur on Line 4 because language has already been defined.

D.    IfLine 1 is changed to #define language 300, Line 6 will print "850".

E.    Anerror or warning will occur on Line 3 because #else can only be used as thelast conditional in the chain.

 

【Q3】 Whichof the following statements regarding the benefits of using template functionsover preprocessor #define macros are correct?

A.    Apreprocessor macro expansion cannot work when user-defined types are passed toit as arguments.

B.    Sincethe preprocessor does the macro expansion and not the compiler, the buildprocess takes a longer period of time.

C.    While expanding #definemacros, the preprocessor does no type checking on the arguments to the macro.

D.    Apreprocessor macro expansion incurs a performance overhead at runtime.

E.    It is simple to step into a template functioncode during the debugging process.

 

【Q4】 Whichof the following are container adapters in the STL (Standard Template Library)in C++?

A.    list

B.    map

C.    stack

D.    queue

E.    deque

 

【Q5】 Whichof the following correctly identify benefits of the getline() member functionfor cin over the extraction operator in C++?

A.    The getline()function by default, accepts whitespace, and returns on seeing the /ncharacter, whereas the extraction operator returns when it encounters anywhitespace character.

B.    Delimiters indicating end of input can be specified to the getline()function, whereas the extraction operator has no such facility.

C.    The getline() function can beoverloaded to accept different argument types, whereas the extraction operatorcannot be overloaded.

D.    The number of bytesto read can be specified to the getline() function, whereas it cannot be donewith the extraction operator.

E.    The getline() function can beused like a manipulator with cin, whereas the extraction operator cannot beused as a manipulator.

 

【Q6】 Inwhich of the following scenarios is a Copy Constructor called or invoked?

A.    Whenno conversion function exists for converting the class object to another classobject

B.    Whenan existing object is assigned an object of its own class

C.    When a function receives asan argument, an object of the class, by value

D.    When a function returns anobject of the class by value

E.    When creating an object andinitializing it with an object of its own class

 

【Q7】 Whichof the following statements describe the result when standard new cannotallocate the requested storage in C++?  (Note: older compilers maynot implement standard behavior).

A.    It throws a bad_allocexception.

B.    Itreturns null.

C.    Itreturns silently with no effect on the expression.

D.    Itthrows an insufficient_memory exception.

E.    Itlogs an error message to the mem_err.log file.

 

【Q8】 InC++, which of the following is the best declaration for an overloadedoperator[] to allow read-only access (and only read-only access) to the data?

template<typenameT>

classMyArray

{

//declaration goes here

};

 

A.    T&operator[](size_t i);

B.    constT& operator[](size_t i);

C.    const T&operator[](size_t i) const;

D.    T&operator[](size_t i)const;

E.    T&operator[](const size_t i);

 

【Q9】 Whichof the following declarations of function main are standard or standardconforming extensions? (Please note that some compilers accept ill-formed maindeclarations, these should be considered incorrect).

A.    int main()

B.    voidmain(char* argv[], int argc)

C.    int main(int argc, char*argv[])

D.    voidmain()

E.    intmain(int argc, char* argv[], char* arge[])

 

【Q10】 Whatis the correct declaration for a file stream insertion operator for a classmy_stuff::my_class as indicated in the C++ code snippet below?

#include<fstream>

 

namespacemy_stuff

{

class my_class

{

public:

int i;

};

 

//Declaration goes here

 

}//nsmy_stuff

 

A.    std::ofstream&operator<<(std::ofstream& ofs, const my_class&);

B.    constmy_class& operator<<(const my_class&)

C.    std::fstream&operator<<(std::fstream& fs, const my_class&)

D.    std::ifstream&operator<<(std::ifstream& ifs, const my_class&)

E.    voidoperator<<(const my_class&)

 

【Q1】 Which of thefollowing statements accurately describe the new[] operator in C++?

A.    It calls the class defaultconstructor for each element of the array.

B.    Itcalls the class copy constructor for each element of the array.

C.    It calls operatornew[](size_t).

D.    Itcalls operator new[](size_t, int).

E.    It stores the number of objects allocated.

 

【Q2】 What is theorder of destructor calls for an object of class Y inherited from class X thathas an object of class A as data member of class Y in C++?

A.    ~Y()

~X()

~A()

B.    ~X()

~A()

~Y()

C.    ~Y()

~A()

~X()

D.    ~A()

~Y()

~X()

E.    ~X()

~Y()

~A()

 

【Q3】 In C++, thereis a standard global object wcin of type wistream. What is the template type ofthe wistream typedef?

A.    std::basic_istream<wchar_t,char_traits<wchar_t> >

B.    std::basic_istream<char,char_traits<char> >

C.    std::istream<char,char_traits<char> >

D.    std::istream<wchar_t,char_traits<wchar_t> >

E.    std::wistream<char,char_traits<char> >

 

【Q4】 How can a C++developer use the placement new syntax to make new allocate an object of classSomeClass at a particular memory address stored in a pointer type variablenamed pmem?

A.    newSomeClass(pmem);

B.    new(pmem) SomeClass;

C.    newpmem SomeClass;

D.    newSomeClass pmem;

E.    new(pmem, SomeClass);

 

【Q5】 Under which ofthe following conditions will a C++ developer use polymorphism?

A.    Whenthere is a looping construct that uses a continue more than once

B.    When there is a needfor the code written today to call code written tomorrow

C.    When there is a needto check for the type of an object to determine which function must be called

D.    Whenthere is a need to check the value of a variable to determine which of two ormore functions to call

E.    Whenthere is a need to modify the existing interface of a class

 

【Q6】 Protected, orprivate, inheritance, as opposed to public inheritance, models which type ofrelationship in C++?

A.    Has-a

B.    Is-implemented-in-terms-of

C.    Was-a

D.    Can-only-have-one-of

E.    Shares-a-relationship-with

 

【Q7】 Which of thefollowing statements regarding functions' default arguments in C++ are correct?

A.    Defaultarguments cannot be of pointer type.

B.    Defaultarguments cannot be of a user-defined type.

C.    Default arguments cannever precede non-default arguments.

D.    Defaultarguments exist in the global heap and not on the function's stack.

E.    Defaultarguments are not considered for generating the function's signature.

 

【Q8】 In thedeclaration below, p is a pointer to an array of 5 int pointers:

int*(*p)[5];

Which ofthe following statements can be used to allocate memory for the first dimensionin order to make p an array of 3 arrays of 5 pointers to type int?

A.    p= new int [3][5]*;

B.    p= new int (*)[3][5];

C.    p= new int [3]*[5];

D.    p = new int *[3][5];

E.    p= new int (*[3])[5];

 

【Q9】 Which of thefollowing operators must be overloaded by function objects in the StandardTemplate Library?

A.    operator+()

B.    operator++()

C.    operator==()

D.    operator ()()

E.    operator[]()

 

【Q10】 A C++ developerwants to explicitly specialize the template function below for the char * type:

template<class T> void fn(T a){...}

Which ofthe following methods can the developer use to carry out this specialization?

A.    voidfn<char*>(char* a){...}

Stanley算法也被称为Stanley-Stembridge算法,主要用于计算可逆写作有限生成排列的生长函数。以下是一个基本的Stanley算法的MATLAB程序示例: ```matlab function sf = stanley(n) % 输入一个正整数n,计算Stanley算法的生长函数 sf = sym(zeros(1,n)); % 创建一个符号变量数组来存储生长函数的值 % 初始化第一个排列(1) p = 1; % 对于每个排列长度m从1到n-1 for m = 1:n-1 % 计算长度为m的排列的生成标志函数 gf = genFlag(p, m); % 计算长度为m的排列的生成多项式 gm = sum(gf); % 更新生长函数数组 sf(m+1) = gm; % 生成下一个长度为m+1的排列 p = nextPerm(p, m); end % 打印生长函数数组 disp(sf); end function gf = genFlag(p, m) % 输入一个排列p和排列的长度m,计算排列的生成标志函数 n = length(p); gf = sym(ones(1,m)); for i = 1:m for j = 1:m if p(i) < p(j) gf(i) = gf(i) * (n - j + 1); end end end end function np = nextPerm(p, m) % 输入一个排列p和排列的长度m,生成下一个长度为m+1的排列 n = length(p); np = [p, m+1]; indexes = 1:n; for i = 1:m indexes(p(i)) = []; end np = [np, indexes]; end ``` 在此程序中,我们首先定义了一个函数`stanley`,其中处理Stanley算法的主要步骤。我们创建一个符号变量数组`sf`来存储生长函数的值,并初始化第一个排列[1]。然后,我们使用一个循环来计算每个长度为m的排列的生成多项式,并将其存储在生长函数数组中。最后,我们输出生长函数数组。 我们还定义了两个辅助函数`genFlag`和`nextPerm`。`genFlag`函数用于计算排列的生成标志函数,`nextPerm`函数用于生成下一个长度为m+1的排列。 请注意,这只是一个基本的Stanley算法程序示例,可能需要根据具体应用进行修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值