




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、现有1000个苹果,10个盒子,问各个盒子内应该分别放入多少个苹果,才能使得用户要买任意1至1000之间的一个苹果数,都可以给他(卖的时候是整个盒子卖,不能拆盒子的包装)。2、请仔细阅读下面的资料:1)材料一:CArraytemplate class CArray : public CObjectParameters:TYPETemplate parameter specifying the type of objects stored in the array. TYPE is a parameter that is returned by CArray.ARG_TYPETemplate parameter specifying the argument type used to access objects stored in the array. Often a reference to TYPE. ARG_TYPE is a parameter that is passed to CArray.Remarks:The CArray class supports arrays that are are similar to C arrays, but can dynamically shrink and grow as necessary. Array indexes always start at position 0. You can decide whether to fix the upper bound or allow the array to expand when you add elements past the current bound. Memory is allocated contiguously to the upper bound, even if some elements are CArray:Add (ARG_TYPE newElement);Return Value:The index of the added element.Parameters:ARG_TYPETemplate parameter specifying the type of arguments referencing elements in this array.newElementThe element to be added to this array.TYPE& CArray:operator (int nIndex);Parameters:TYPETemplate parameter specifying the type of elements in this array.nIndexIndex of the element to be accessed.Remarks:Returns the array reference of element at the specified index.2)材料二:CListtemplateclass CList : public CObjectParameters:TYPEType of object stored in the list.ARG_TYPEType used to reference objects stored in the list. Can be a reference.Remarks:The CList class supports ordered lists of nonunique objects accessible sequentially or by value. CList lists behave like doubly-linked lists. void CList:AddTail(ARG_TYPE newElement);Parameters:ARG_TYPETemplate parameter specifying the type of the list element (can be a reference).newElementThe element to be added to this list.Remarks:Adds a new element or list of elements to the tail of this list. The list can be empty before the operation.3)材料三: reallocreallocReallocate memory blocks.void *realloc(void *memblock, size_t size);Return Value:The return value points to a storage space that is guaranteed to be suitably aligned for storage of any type of object. To get a pointer to a type other than void, use a type cast on the return value.Remarks:The size argument gives the new size of the block, in bytes. The contents of the block are unchanged up to the shorter of the new and old sizes, although the new block can be in a different location. Because the new block can be in a new memory location, the pointer returned by realloc is not guaranteed to be the pointer passed through the memblock argument.4)请指出下面这段代码可能会出现的问题CList g_ValueList;CArray g_ValuePool;void AddNewValue (const VARIANT& newValue)g_ValueList.AddTail(&g_ValuePoolg_ValuePool.Add(newValue);3、有一无符号整型数组,大小为10, 初始的数值随机,但在0, 99之间。请用C语言写一个过滤程序,令数组内的数据互不相等。说明:1.若数组内有相等的数据,可令某一数值加1或减1作出偏移,直至不等为止。2.数组内的数据只能在0, 99之间。3.保持数组内的数据位置不变,即对应下标不变。4、 按要求编写以下函数。功能:将给定缓冲区中的#字符移到字符串尾部函数名称:ChangeToTail入口参数:pSZ指向缓冲区的指针, nSize缓冲区长度出口:pSZ所指缓冲区中的#字符被移到缓冲区尾部返回值:在出口缓冲区中第一个#的位置,若缓冲区中无#字符则返回-1说明:如传入#W#W#W#WW#, 10 则传出时应转换为WWWWW#并且返回值为5int ChangeToTail(BYTE* pSZ, UINT nSize)/ Todo:请在此加入您的代码5、在金山,有一个非常经典有趣的游戏,称为杀人游戏。此游戏角色有:好人(m人)、坏人(n人)、村长(1人)、裁判(1人)。角色采用一定方式(如:抓阄)分配。村长、裁判两个角色是公开的,而好人、坏人两个角色则只要裁判和本人心知肚明。其玩法如下:游戏开始了,裁判说:“天黑了”,这是所有其他角色都低头闭上眼睛(不准作弊!)。然后裁判说:“坏人开始活动”,此时坏人抬起头,并相互商议,杀死一个好人。然后裁判说:“天亮了”,此时所有人抬头,被杀死的那个好人宣布出局。剩下的人在村长的主持下,开始判断杀人凶手。每个人可以根据各人的表情反应,判断并提议杀死自己心目中的坏人。不过最终的裁决权属于村长,综合大家的意见杀死一人。此时裁判宣布此人出局。游戏进入下一轮,由天黑到天亮,再有2人出局,如此反复,直到最后好人先被全部杀死,则游戏结束,“邪恶”的一方战胜了“正义”的一方;而另一个结局则是在大家以及村长的英明决断下,坏人被全部杀死,则“正义”的一方战胜了“邪恶”的一方。现在,我们的问题是,请写出你的思路,并编写一个C/C+语言程序,求出:在坏人有两个(n = 2)的情况下,需要多少个好人(m = ?),才能够使这个游戏比较公平,也就是说,从概率上说,“正义”的一方与“邪恶”的一方胜利的几率最接近于50%。(此题与下面一题选做一道)6、在以上的杀人游戏中,还有一个玩法,就是取消村长这个角色,“天亮”后剩余的人每个人投票列出自己心目中最怀疑的2个人,以此决定让谁出局。试问,在此玩法下,上面的问题又何解?7.C+程序设计1).写出以下程序的运行结果:#include class Basepublic:Base()cout Base() endl;Base(const Base &theBase)cout Base(const Base &theBase) endl;Base()cout Base() endl;void Open()OnOpen();private:virtual void OnOpen() = 0;class Derived : public Basepublic:Derived()cout Derived() endl;Derived(const Derived &theDeriv
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家电小门店管理制度
- 强化领导及管理制度
- 德育活动室管理制度
- 志愿者茶室管理制度
- 快速响应区管理制度
- 急救中感染管理制度
- 意大利剧院管理制度
- 成品库储存管理制度
- 战备综合室管理制度
- 房地产经理管理制度
- 江苏省南通市海安市2025年七年级下学期期末英语试题及答案
- 有限空间作业通风时间专题
- 广东省广州市天河外国语学校2025年七年级英语第二学期期末综合测试模拟试题含答案
- Java EE-形考任务一-国开(LN)-参考资料
- 西安无人机项目商业计划书
- 2025年公务员综合素质能力考试卷及答案
- 化工智能控制技术-形考任务4(预备知识:第十~十三章;分值100分;不需辅导老师评阅)测验-国开-参考资料
- 蚂蚁花呗对大学生消费行为的实证分析
- 储能专业知识考试试题及答案
- 中国上市银行2024年回顾及未来展望-安永-202505
- 抗肿瘤药卡铂的介绍与研究
评论
0/150
提交评论