【Morgan Stanley IKM在线测试】C++
来源:互联网 发布:hadoop用什么数据库 编辑:程序博客网 时间:2024/05/22 06:46
掌握好基础啊!<<Effective C++>>,<<C++ Primer>>
考核内容包括不限于:
重构,重载,析构函数里(重构,重载,)new,malloc异常 堆和栈
OOP,OSI七层模型(应用层:http,ftp 传输层:tcp)
设计模式,UML图
Xml(DocTYPe)
数据库 sybase
1. XML DOCTYPE
2.10.2 The DOCTYPE declaration
An XML file which is valid (as opposed to simply well-formed) must specify a DTD against which its content is to be validated. This is the function of the DOCTYPE declaration.
The DOCTYPE declaration contains, following the DOCTYPE keyword, at least two parts: the name of the root element for the associated document, and a set of declarations for all the elements, attributes, notations, entities, etc. which together define the document type declaration (DTD) of that document. Note, incidentally, that the root element name (and hence the DOCTYPE name) may be that of any element whose declaration is supplied in this set. The declarations may be supplied explicitly, or by reference to an external entity such as a file, or by a combination of the two.
Taking each of these possibilities in turn, we first present a DOCTYPE declaration in which the declarations for all the elements, attributes, etc. required are given explicitly:
<!DOCTYPE myDoc [ <!ELEMENT myDoc (p+) > <!ATTLIST myDoc n CDATA #IMPLIED> <!ELEMENT p (#PCDATA)>]><myDoc n="1"> <p>This is an instance of a "my.doc" document</p></myDoc>Note that the required declarations are enclosed within square brackets inside the DOCTYPE declaration: this part of the declaration is technically known as the DTD subset.
More usually, however, the required declarations will be held in a separate entity and invoked by reference, as follows:
<!DOCTYPE myDoc SYSTEM "myDoc.dtd" []><myDoc> <p>This is another instance of a "myDoc" document.</p> <p>It has two paragraphs.</p></myDoc>Note the similarity between the syntax used to reference the external entity containing the required declarations and that used to define any other system entity (see 2.7.1 Entity declarations). The square brackets may be supplied even though they enclose nothing, as in this example, or they may be omitted.
Next, we present a case where declarations are given both within the DTD subset and by reference to an external entity:
<!DOCTYPE myDoc SYSTEM "myDoc.dtd" [ <!ENTITY tla "three letter acronym">]><myDoc> <p>This is yet another instance of a "myDoc" document.</p> <p>It is surprisingly free of &tla;s.</p></myDoc>
Any kind of declaration may be added to a DTD subset; as we have already seen (2.8.2 Conditional marked section), this is the mechanism by which the TEI DTD is customized.
<!DOCTYPE TEI.2 PUBLIC "-//TEI P3//DTD Main Document Type//EN" "tei2.dtd" [ <!ENTITY % TEI.prose 'INCLUDE'> <!ENTITY % TEI.XML 'INCLUDE'> <!ENTITY tla "Three Letter Acronym"> <!ENTITY % x.phrase 'myTag|'> <!ELEMENT myTag (#PCDATA) > <!-- any other special-purpose declarations or re-declarations go here --> ]><TEI.2> <!-- This is an instance of a modified TEI.2 type document, which may contain <myTag>my special tags</myTag> and references to my usual entities such as &tla;. --></TEI.2>When, as here, the document type declaration in force includes both the contents of the DTD subset, and the contents of some external entity (in the case above, whatever file is specified by the PUBLIC identifier given, tei2.dtd by default), declarations in the DTD subset are always carried out first. As noted above, (2.7.5 Parameter entities), the order is important, because in XML only the first declaration of an entity counts. In the above example, therefore, the declaration of the entity tla in the DTD subset takes precedence over any declaration of the same entity in the file tei2.dtd. Similarly, the declaration for x.phrasetakes precedence over the existing declaration for that entity in the TEI dtd. It is perfectly legal for entities to be declared more than once; elements, by contrast, may not be declared more than once; if a declaration for <myTag> were already contained in file tei.dtd, the XML parser would signal an error.
2. C++new失败的处理
int* p = new int[SIZE];
if ( p == 0 ) // 检查 p 是否空指针
return -1;
// 其它代码
其实,这里的 if ( p == 0 ) 完全是没啥意义的。C++ 里,如果 new 分配内存失败,默认是抛出异常的。所以,如果分配成功,p == 0 就绝对不会成立;而如果分配失败了,也不会执行 if ( p == 0 ),因为分配失败时,new 就会抛出异常跳过后面的代码。如果你想检查 new 是否成功,应该捕捉异常:
try {
int* p = new int[SIZE];
// 其它代码
} catch ( const bad_alloc& e ) {
return -1;
}
据说一些老的编译器里,new 如果分配内存失败,是不抛出异常的(大概是因为那时 C++ 还没加入异常机制),而是和 malloc 一样,返回空指针。不过我从来都没遇到过 new 返回空指针的情况。
当然,标准 C++ 亦提供了一个方法来抑制 new 抛出异常,而返回空指针:
int* p = new (std::nothrow) int; // 这样如果 new 失败了,就不会抛出异常,而是返回空指针
if ( p == 0 ) // 如此这般,这个判断就有意义了
return -1;
// 其它代码
===============================详解===================================
首先按c++标准的话,new失败会抛出bad_alloc异常,但是有些编译器对c++标准支持不是很好,比如vc++6.0中new失败不会抛出异常,而返回0
3.stlcontainer Adapter
1、容器(Containers):各种数据结构,如Vector,List,Deque,Set,Map,用来存放数据,STL容器是一种Class Template,就体积而言,这一部分很像冰山载海面的比率。
2、算法(Algorithms):各种常用算法如Sort,Search,Copy,Erase,从实现的角度来看,STL算法是一种Function Templates。
3、迭代器(Iterators):扮演容器与算法之间的胶合剂,是所谓的“泛型指针”,共有五种类型,以及其它衍生变化,从实现的角度来看,迭代器是一种将:Operators*,Operator->,Operator++,Operator--等相关操作予以重载的Class Template。所有STL容器都附带有自己专属的迭代器——是的,只有容器设计者才知道如何遍历自己的元素,原生指针(Native pointer)也是一种迭代器。
4、仿函数(Functors): 行为类似函数,可作为算法的某种策略(Policy),从实现的角度来看,仿函数是一种重载了Operator()的Class 或 Class Template。一般函数指针可视为狭义的仿函数。
5、配接器(Adapters):一种用来修饰容器(Containers)或仿函数(Functors)或迭代器(Iterators)接口的东西,例如:STL提供的Queue和Stack,虽然看似容器,其实只能算是一种容器配接器,因为 它们的底部完全借助Deque,所有操作有底层的Deque供应。改变Functor接口者,称为Function Adapter;改变Container接口者,称为Container Adapter;改变Iterator接口者,称为Iterator Adapter。配接器的实现技术很难一言蔽之,必须逐一分析。
6、配接器(Allocators):负责空间配置与管理,从实现的角度来看,配置器是一个实现了动态空间配置、空间管理、空间释放的Class Template。
——《STL源码剖析》
4. 关键字 volatile
与锁相比,Volatile 变量是一种非常简单但同时又非常脆弱的同步机制,它在某些情况下将提供优于锁的性能和伸缩性。如果严格遵循 volatile 的使用条件 —— 即变量真正独立于其他变量和自己以前的值 —— 在某些情况下可以使用 volatile
代替 synchronized
来简化代码。然而,使用 volatile
的代码往往比使用锁的代码更加容易出错。本文介绍的模式涵盖了可以使用 volatile
代替synchronized
的最常见的一些用例。遵循这些模式(注意使用时不要超过各自的限制)可以帮助您安全地实现大多数用例,使用 volatile 变量获得更佳性能。
http://www.ibm.com/developerworks/cn/java/j-jtp06197.html
5. 析构函数 异常问题
析构函数中抛异常
构造函数中抛异常
1: 构造函数中是否可以抛异常?
可以。
2: 有什么限制吗?
有限制。构造抛异常之前必须把已经申请的资源释放掉。这样,就算你的对象是new出来的,也不会造成内存泄漏。
因为析构函数不会被调用,所以抛出异常后,你没机会释放资源。
建议,在构造函数中不要做过多的事情,只是能对成员变量的做初始化工作就好了。真的需要做其他复杂的初始化操作,完全可以提供一个Init或Start函数. 这样在Init或Start抛出异常后,如果对象是在栈上,析构函数仍会被调用。如果是在堆上,需要在捕获Init或Start抛出的异常后,delete对象。
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
网络讨论集锦:http://bbs.yingjiesheng.com/thread-1242412-1-1.html
网申结束后2天收到邮件,通知进行IKM online test,有C++, C#, Java可供选择,选择其一即可。收到邮件后,开始在网上收IKM的相关资料,但很遗憾,没有找到原题。从查到的信息来看,大概是说这个测试很难,题目是adaptive的。另外可以找到考试的说明,大概来说,题目都是选择题,答题的正确率比速度更重要等等。
也不知道怎么准备。。于是开着google,旁边放本C++ premier就开始做题。选的是C#的题目,一共35分钟。题目范围很广,涉及到多线程(lock等知识点)、内存管理、调试、界面类(与C#对应)、多态继承以及一些设计模式的问题。另外,还有给个程序,让你指出哪里有错误的题目。题目确实很难,而且大部分题一时半会是查不到。我做题速度很慢,一共只做了20多道题,估计要挂。
另外,之前在网上查到一篇博客说,考试的时候可以复制题目,我试着复制了一下,立刻弹出一个警告,说考试题目不允许复制,要是再复制的话,考试将自动终止。所以,题目是不能直接复制的。
题目太难,好多都是我不熟悉的,所以也没记住太多信息。Anyway,希望对大家有帮助!
“楼上很厉害啊,我考的JAVA,做了大概20道的样子,坑爹的5选项不定选择,全是考什么异常静态类之类的东西,还有大量的uml题,能把英文看懂就不错了,算了反正没啥希望了,还是等好好复习下再继续参加其他的笔试
刚做完了,只做了17道。貌似题目都是看上去不难(我的意思是以概念题为主,看来我悲剧了,做的太差,系统默认给我越来越简单了),当然我还是不会做就是了。悲剧啊。。 选的C++,貌似主要考C++、面向对象和unix线程的一些概念。
我做了java的,做了感觉答的很不好,后来闲着没事又把C++的做了,题目很多都一样啊。不知道什么情况。2周了快,没消息。估计挂了。期待楼主的好消息。
没有,全是选择题。主要考 C,面向对象和unix操作系统一些东西。
我做的Java,知识覆盖挺广的,数据库(Sybase)、OS、UML,被活虐了,做完好久了,一直没有信儿,估计挂掉了
__________________________________________________________
大摩IT笔试
(2012-03-29 16:48:57)杂谈
分类: 我的求职- 【Morgan Stanley IKM在线测试】C++
- C#/WPF 面试题(Microsoft, Morgan stanley)
- morgan stanley IT interview
- 应聘Morgan Stanley(转)
- Morgan Stanley OA题库
- 【Morgan Stanley】AC面试
- morgan stanley 电话面试
- morgan stanley 面试资料(一)
- morgan stanley 面试资料(二)
- 我对morgan stanley it的了解
- 【2014校招】Morgan Stanley - phone interview
- Morgan Stanley Program Contest 2014-Train
- Morgan Stanley Programming Constest 2014题目Train
- 【面试】Morgan Stanley IT面经
- Morgan Stanley IT笔试面试经验
- 【Morgan Stanley IT暑期实习生电面】
- Morgan Stanley(摩根士丹利)电面过程
- Morgan Stanley(摩根士丹利)电面过程
- shell中read命令
- 数据库范式
- Objective-C中的NSObject对象经常使用到的方法
- 关于 rcp 中Texteidtor 控件的使用注意事项
- 软件架构、领域驱动设计漫谈
- 【Morgan Stanley IKM在线测试】C++
- oracle中的游标 包 集合 的学习总结
- 从网络获取xml格式的视频资讯
- window语言id
- oracle 中的集合(联合数组 内嵌表 可变数组)
- 八皇后问题的解决(c语言)
- tutorial 2
- poj 1935 journey 树DP
- 正则表达式匹配