编程范式期末考试练习题目

上传人:ji****72 文档编号:46448703 上传时间:2018-06-26 格式:PDF 页数:8 大小:122.65KB
返回 下载 相关 举报
编程范式期末考试练习题目_第1页
第1页 / 共8页
编程范式期末考试练习题目_第2页
第2页 / 共8页
编程范式期末考试练习题目_第3页
第3页 / 共8页
编程范式期末考试练习题目_第4页
第4页 / 共8页
编程范式期末考试练习题目_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《编程范式期末考试练习题目》由会员分享,可在线阅读,更多相关《编程范式期末考试练习题目(8页珍藏版)》请在金锄头文库上搜索。

1、CS107 Handout 38 Spring 2008 June 2, 2008 CS107 Final Exam Practice Problems Exam Facts First Offering: Monday, June 9th at 8:30 a.m. in Dinkelspiel Auditorium. Second Offering: : Monday, June 9th at 3:30 p.m. in Hewlett 200. Three hours, open notes, open book, closed computer. You may take the exam

2、 at whichever is the more convenient of these two times. Ill provide documentation for any relevant C, C+, and Scheme built-ins. The final exam Im presenting here contains many more problems than youll see on your final exam. I thought it would be better to give you plenty of practice problemsall dr

3、awn from previous midterms and finalsthatll help you identify the material I consider important. SCPD students will take the exam much like they took the midterm. The exam will be posted as a handout at 3:30 p.m. I need the exam to be faxed in by Tuesday at 5:00 p.m. My cell phone and fax number wil

4、l be posted on the first page of the exam, so you know where to call if you have questions and where to fax when youre all done. Material The final is comprehensive but will emphasize topics covered after the midterm. Want to see where youve been? Heres the pretty impressive list of things youve lea

5、rned in 107: 1. Implementationstack-heap diagrams, memory layout, structures, arrays and pointers, function calls, parameter passing, local variables, C and C+ code generation. 2. C arrays, pointers, malloc, * VectorNew( * VectorNew( * * generateAllCouples creates a new C vector of couples * and ins

6、erts one such record on behalf of every possible * mapping of boy to girl. The couples own their own strings, * so that none of the three vectors share any memory whatsoever. * Assume that CoupleFree is the VectorFreeFunction that disposes * of couple records embedded in a vector, and assume it just

7、 works. */ typedef struct char *girl; char *boy; couple; vector generateAllCouples(vector *boys, vector *girls) vector couples; VectorNew( Problem 2: Extending the vector A properly implemented C vector should have completed the struct as follows: typedef struct void *elems; / pointer to elemsize *

8、alloclength bytes of memory int elemsize; / number of bytes dedicated to each client element int loglength; / number of elements the client is storing int alloclength; / number of elements we have space for VectorFreeFunction free; / applied to elements as they are removed vector; Pretend that weve

9、decided to extend the vector abstraction to include one more function: VectorSplit. VectorSplit initializes and populates two additional vectors, copying those elements that pass a supplied predicate function to the first vector, and copying those that fail to the second. The original vector is comp

10、letely depleted of its elements without actually destroying them. 3 Your implementation has access to the vector fields, and can make use of the other vector functions if you so choose. In essence, youre emptying out the original vector and partitioning its elements so that some end up in the first,

11、 and the rest end up in the second. Be careful to not free anything youre not supposed to. This is pure C, so no C+ is allowed. typedef bool (*VectorSplitFunction)(const void *elemAddr); void VectorSplit(vector *original, vector *thoseThatPass, vector *thoseThatFail, VectorSplitFunction test) Proble

12、m 3: C+ Spice Rack Given the following C+ class definition, generate code for the spice:sage method. Assume that the parameters have already been set up for you. Be clear about what code pertains to which line. Recall that C+ references are automatically dereferenced pointers, and k-argument methods

13、 are really (k + 1)-argument functions, where the address of the receiving object is quietly passed in as the bottommost parameter. The address of the first instruction of the saffron method is synonymous with . You have this and the next page for your code. class spice spice * short sage(int cumin,

14、 spice rosemary) cumin *= thymecumin - *(char *)thyme; return (spice *) short thyme4; spice *parsley; ; Problem 4: Cars Given the following C+ class definition, generate code for the car:dochudson method. Assume that the parameters have already been set up for you, and dont worry about returning fro

15、m the method. Be clear about which code pertains to which line. Recall that C+ references are automatically dereferenced pointers, and k-argument methods are really (k + 1)-argument functions, because the address of the receiving object is quietly passed in as the bottommost parameter. The address o

16、f the first instruction of the operator method is synonymous with . Assume that the P of “Pixar“ is at address constant 1000. class car char *operator(const char *); car return (*(car *)mcqueen)-mcqueen3; short mater4; car *mcqueen; ; line 1 line 2 line 1 line 2 4 Problem 5: Marriage And Mapping a) Write a Scheme function called marry, which takes a list o

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号