首页 新闻 论坛 群组 Blog 文档 下载 读书 Tag 网摘 搜索 .NET Java 游戏 视频 人才 外包 培训 数据库 书店 程序员
中国软件网
欢迎您:游客 | 登录 注册 帮助
  • 几道C++笔试题,不定项选择,我也不知道答案,高手解答,大家一起讨论吧 [已结帖,结帖人:George1227]
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    • 结帖率:
    发表于:2008-11-02 06:55:24 楼主
    1. Given the following program snippet, what can we conclude about the use of dynamic_cast in C++?
    C/C++ code
    #include <iostream> #include <memory> //Someone else's code, e.g. library class IGlyph { public: virtual ~IGlyph(){} virtual std::string Text()=0; virtual IIcon* Icon()=0; //... }; class IWidgetSelector { public: virtual ~IWidgetSelector(){} virtual void AddItem(IGlyph*)=0; virtual IGlyph* Selection()=0; }; //Your code class MyItem : public IGlyph { public: virtual std::string Text() { return this->text; } virtual IIcon* Icon() { return this->icon.get(); } void Activate() { std::cout << "My Item Activated" << std::endl; } std::string text; std::auto_ptr<IIcon> icon; }; void SpiffyForm::OnDoubleClick(IWidgetSelector* ws) { IGlyph* gylph = ws->Selection(); MyItem* item = dynamic_cast<MyItem*>(gylph); if(item) item->Activate(); }


    A. The dynamic_cast is necessary since we cannot know for certain what concrete type is returned by IWidgetSelector::Selection().

    B. The dynamic_cast is unnecessary since we know that the concrete type returned by IWidgetSelector::Selection() must be a MyItem object.

    C. The dynamic_cast ought to be a reinterpret_cast since the concrete type is unknown.

    D. The dynamic_cast is redundant, the programmer can invoke Activate directly, e.g. ws->Selection()->Activate();

    E. A polymorphic_cast should be used in place of the dynamic_cast.


    2. Which of the following declarations of function main are standard or standard conforming extensions?
    (Please note that some compilers accept ill-formed main declarations, these should be considered incorrect).


    A. void main(char* argv[], int argc)
    B. int main()
    C. void main()
    D. int main(int argc, char* argv[])
    E. int main(int argc, char* argv[], char* arge[])

    3. Which of the following statements accurately describe the condition that can be used for conditional compilation in C++?
    A. The condition can depend on the value of program variables.
    B. The condition can depend on the values of any const variables.
    C. The condition can use the sizeof operator to make decisions about compiler-dependent operations, based on the size of standard data types."
    D. The condition can depend on the value of environmental variables.
    E. The condition must evaluate to either a "0" or a "1" during pre-processing.

    4. In C++, which of the following are valid uses of the std::auto_ptr template considering the class definition below?

    class Object
    {
    public:
       virtual ~Object() {}
       //...
    };


    A.     std::auto_ptr <Object> pObj(new Object);
    B.     std::vector <std::auto_ptr <Object*> > object_vector;
    C.     std::auto_ptr <Object*> pObj(new Object);
    D.    std::vector <std::auto_ptr <Object> > object_vector;
    E.    
    std::auto_ptr <Object> source()
    {
    return new Object;
    }

    5. Which of the following statements correctly describe C preprocessor directives in C++?
    A. The #pragma directive is machine-independent.
    B. Preprocessor directives are processed before macros are expanded.
    C. The #import directive is used to copy code from a library into the program's source code.
    D. Any number of #else directives can be used between an #if and an #endif.
    E. The #include directive is used to identify binary files that will be linked to the program.

    6. Which of the following statements describe the results of executing the code snippet below in C++?
    C/C++ code
    int var = 1; void main() { int i = i; }

    A. The i within main will have an undefined value.
    B. The i within main will have a value of 1.
    C. The compiler will not allow this statement.
    D. The compiler will allow this statement, but the linker will not be able to resolve the declaration of i.
    E. The result is compiler-dependent.

    7. Which of the following statements regarding the benefits of using template functions over preprocessor #define macros are correct?
    A. A preprocessor macro expansion cannot work when user-defined types are passed to it as arguments.
    B. While expanding #define macros, the preprocessor does no type checking on the arguments to the macro.
    C. Since the preprocessor does the macro expansion and not the compiler, the build process takes a longer period of time.
    D. A preprocessor macro expansion incurs a performance overhead at runtime.
    E. It is simple to step into a template function code during the debugging process.

    8. In a hierarchy of exception classes in C++, which of the following represent possible orders of catch blocks when a C++ developer wishes to catch exceptions of more than one class from a hierarchy of exception classes?
    A. Classes belonging to the same hierarchy cannot be part of a common set of catch blocks.
    B. The most derived classes must appear first in the catch order, and the parent classes must follow the child classes.
    C. The most derived classes must appear last in the catch order, and the parent classes must precede the child classes.
    D. The order is unimportant as exception handling is built into the language.
    E. Multiple classes can be caught in a single catch clause as multiple arguments.

    9. Which of the following statements provide a valid reason NOT to use RTTI for distributed (i.e. networked between different platforms) applications in C++?
    A. RTTI is too slow.
    B. RTTI does not have standardized run-time behavior.
    C. RTTI uses too much memory.
    D. RTTI's performance is unpredictable/non-deterministic.
    E. RTTI frequently fails to function correctly at run-time.

    10. Which of the following options describe the expected overhead for a class that has 5 virtual functions?
    A. Every object of the class holds the address of the first virtual function, and each function in turn holds the address of the next virtual function.
    B. Every object of the class holds the address of a link list object that holds the addresses of the virtual functions.
    C. Every object of the class holds the addresses of the 5 virtual functions.
    D. Every object of the class holds the address of a structure holding the addresses of the 5 virtual functions.
    E. Every object of the class holds the address of the class declaration in memory, through which the virtual function calls are resolved.

    11. A C++ developer wants to handle a static_cast <char*>() operation for the class String shown below. Which of the following options are valid declarations that will accomplish this task?
    class String {
    public:
      //...
      //declaration goes here
    };
    A. char* operator char*();
    B. operator char*();
    C. char* operator();
    D. String operator char*();
    E. char* operator String();

    12. Which of the following options describe the functions of an overridden terminate() function?
    A. It performs the desired cleanup and shutdown processing, and then throws a termination_exception.
    B. It performs the desired cleanup and shutdown processing, and then returns an error status value to the calling function.
    C. It performs the desired cleanup and shutdown processing, and then calls abort() or exit().
    D. It performs the desired cleanup and shutdown processing, and if it has restored the system to a stable state, it returns a value of "-1" to indicate successful recovery.
    E. It performs the desired cleanup and shutdown processing, and then calls the unexpected() handler.

    13. Which of the following options are returned by the typeid operator in C++?
    A. A reference to a std::type_info object
    B. A const reference to a const std::type_info object
    C. A const std::type_info object
    D. A reference to a const std::type_info object
    E. A const reference to a std::type_info object
    100  修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-02 06:59:311楼 得分:0

    14. Which of the following statements accurately describe unary operator overloading in C++?
    A. A unary operator can be overloaded with no parameters when the operator function is a class member.
    B. A unary operator can be overloaded with one parameter when the operator function is a class member.
    C. A unary operator can be overloaded with one parameter when the operator function is free standing function (not a class member).
    D. A unary operator can only be overloaded if the operator function is a class member.
    E. A unary operator can be overloaded with no parameters when the operator function is a free standing function (not a class member).

    15.  What is the correct syntax for portable fstream file paths?
    (e.g. the string you would pass to std::fstream::open() to open a file.)

    A. "::directory:file.bin"
    B. "C:/Directory/File.bin"
    C. "/directory/file.bin"
    D. "C:\\Directory\\File.bin"
    E. std:fstream file paths are not portable.

    16. When a Copy Constructor is not written for a class, the C++ compiler generates one. Which of the following statements correctly describe the actions of this compiler-generated Copy Constructor when invoked?
    A. The compiler-generated Copy Constructor makes the object being constructed, a reference to the object passed to it as an argument.
    B. The compiler-generated Copy Constructor does not do anything by default.
    C. The compiler-generated Copy Constructor performs a member-wise copy of the object passed to it as an argument, into the object being constructed.
    D. The compiler-generated Copy Constructor tags the object as having been Copy-Constructed by the compiler.
    E. The compiler-generated Copy Constructor invokes the assignment operator of the class.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-02 07:21:212楼 得分:0
    我怎么不能修改我自己发的帖子……
    忘了说明了。
    全部是不定项选择,至少有一个答案正确。
    3分钟一道题,还是读秒的……超过3分钟就不能再答题了。做过的题目也不能再回头看。
    做得我头晕死了。对RTTI和preprocessor还有exception handling太不熟了……
    以下是我的答案,有诸多疑问,希望高手现身解释解释。
    1. A.
    2. D——不知道B对不对,E是什么东西哦……没见过
    3. DE——ABC的情况好像没见过……
    4. AD——但是不确定D对不对,auto_ptr变量做为vector的elements会有问题,只是最好不要这么用吧,但是编译和运行好像是可以的。
    5. 太不确定了,结果忘记答题时间就过了T_T
    6. A——怎么有这么诡异的代码……也不知道对不对
    7. AB——不确定……
    8. D——完全不懂啊……
    9. AD——猜的
    10. 不会——虚函数表忘记了
    11. 完全不懂……
    12. D吧
    13. C吧
    14. B吧
    15. CD
    16. AC——D是什么意思?

    也不知道回答不全的得不得分,也不知道最终结果。
    希望高手来解答,看看我到底错了多少?希望有详细的解释,谢谢。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-02 07:25:113楼 得分:0
    怎么不能修改我发的帖子和回复啊?!我还想到时候把大家总结的东西编辑在第一页的帖子里呢
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • tienchiu
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-02 18:46:534楼 得分:0
    引用 2 楼 George1227 的回复:

    3分钟一道题,还是读秒的……超过3分钟就不能再答题了。做过的题目也不能再回头看。



    不是吧?这么夸张~~
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Mougou
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-02 20:19:415楼 得分:0
    路透的笔试题吧?真是那样的话建议你别去了,他们正难过呢,金融危机。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-03 00:14:596楼 得分:0
    路透?路透社?不是……

    没人一起来看看吗?
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • lily604
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-03 00:25:137楼 得分:0
    太晚了 做个记号 明天在看
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • jia_xiaoxin
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-03 03:02:068楼 得分:5
    1. 选A
    2. 只有D是标准的写法,E中的第三个参数是环境变量字符串的指针数组,虽然许多编译器支持,但不是标准的写法
    3. D
    4. AD
    5. B
    6. A

    下面的先MARK
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • MagiSu
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-03 03:35:519楼 得分:10
    楼主去的公司出的题目很厉害哦!
    我没看是多选,全是单选的。请高手批评!

    A
    D
    C
    A
    B
    A
    B
    B
    B
    D
    B
    C
    B
    A
    B
    C
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-03 04:58:3710楼 得分:0
    等了1天,总算有人响应了T_T

    第一题楼上2位选A都确定吗?
    第二题为什么题目强调standard or standard conforming extensions?谁有标准和标准扩展翻翻。
    第三题有C的情况吗?真没见过哦
    第四题D是肯定可以编译和运行通过的。只是不推荐这么用。答案应该确定是AD没问题了。
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zizaifeiyu
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 18:00:3111楼 得分:0
    先标记了,回去再看
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • zmlovelx
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 19:19:3512楼 得分:0
    up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • cyj626
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 19:29:0713楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • macfan
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 19:33:2514楼 得分:0
    全是英文的,看不懂..帮顶..
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • ssdx
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 20:22:4815楼 得分:0
    不知道哪的?感觉还比较好答啊~
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • fhtingtian
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 20:43:5116楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • mabo321
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-04 22:03:3017楼 得分:0
    不错……回头看看,

    谢谢分享
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • George1227
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 00:00:4618楼 得分:0
    怎么都是mark的……都没有分享答案和讨论的……T_T
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • hqin6
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 00:22:3419楼 得分:0
    全是e文啊~~~~~~~~~

    死定了!
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wingfff
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 07:27:3620楼 得分:40
    引用 10 楼 George1227 的回复:
    等了1天,总算有人响应了T_T

    第一题楼上2位选A都确定吗?
    第二题为什么题目强调standard or standard conforming extensions?谁有标准和标准扩展翻翻。
    第三题有C的情况吗?真没见过哦
    第四题D是肯定可以编译和运行通过的。只是不推荐这么用。答案应该确定是AD没问题了。


    第二题should be bd

    refer to http://en.wikipedia.org/wiki/Main_function

    Are u sure about the option D of 第三题? Can u give me an example? thanks.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • fengxuxing
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 07:49:0321楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • Flyinsky1
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 07:52:2622楼 得分:0
    mark
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • wingfff
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 07:52:4923楼 得分:20
    第7题 A. A preprocessor macro expansion cannot work when user-defined types are passed to it as arguments.

    I think this is wrong. Macros don't check types. So u can pass any type to them.

    "user-defined types are passed to it as arguments" is confusing. Does it mean an object of the type or the type itself?

    Can template function accept a type as an argument? I am not sure. Can anyone give me an example? thanks.
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • e_sharp
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 08:28:1024楼 得分:0
    UP
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • xuxingok
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 08:29:0325楼 得分:0
    up
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天
    • xuxinjie
    • 等级:
    • 可用分等级:
    • 总技术分:
    • 总技术分排名:
    发表于:2008-11-05 08:41:2926楼 得分:0
    每题三分钟,英文不好就不行啦
    修改 删除 举报 引用 回复
    进入用户个人空间
    加为好友
    发送私信
    在线聊天