Final Format最终的格式_第1页
Final Format最终的格式_第2页
Final Format最终的格式_第3页
Final Format最终的格式_第4页
Final Format最终的格式_第5页
已阅读5页,还剩45页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、Instructor: Alexander Stoytchev/alexs/classes/2009_Fall_185/CprE 185: Intro to Problem Solving(using C)Review for the Final ExamCprE 185: Intro to Problem SolvingIowa State University, Ames, IACopyright Alexander StoytchevFinal Exam Final Exam: Thursday Dec 17: 2:15- 4:15 pm

2、 Location: This room. The final is worth 25% of your grade. The best way to fail this class is to not show up.Final Format True/False(10 x 1p each = 10p) Fun Stuff( 3 x 5p each = 15p) Short answers( 5 x 3p each = 15p) Code Snippets( 4 x 5p each = 20p) What is the output( 3 x 5p each = 15p) Program 1

3、(15p) Program 2(20p) Program 3(20p) TOTAL (130p)Final Format You dont need to get all 130 points to get an A 100 is a 100 You must get at least 65 points in order to pass this examGeneral Topics for the Final Everything since midterm2 Recursion Stuctures Strings Files PointersGeneral Topics for the

4、Final Everything since midterm2 Recursion Stuctures Strihngs Files Pointers And everything before midterm2. No topic is off limits!How to Study for the Final Form a study group. (this will help you overcome your fear) Go back and look at my slides for this class. Go back and look at the sample progr

5、ams that were demonstrated during the lectures. Programs you wrote during the labs. Homework problems (solve them again). Exercise. And get some sleep. 2004 Pearson Addison-Wesley. All rights reservedRecursive Programming/ This function returns the sum of 1 to numint sum (int num) int result; if (nu

6、m = 1) result = 1; else result = num + sum (n-1); return result;sum(1);sum(1)sum(2) Recursive Control Flow In Recursive calls methods can call themselves, but typically with different arguments each timereturn 1;Recursive Control Flow In Recursive calls methods can call themselves, but typically wit

7、h different arguments each timesum(2) sum(1)sum(1); sum(2);sum(3) main()return 1;sum(3); 2004 Pearson Addison-Wesley. All rights reservedRecursive Programmingmainsumsumsumsum(3)sum(1)sum(2)result = 1result = 3result = 6Recursion: Fibonacci NumbersThe sequence: 0,1,1,2,3,5,8,13,. Fibonacci Sequence#i

8、nclude#includeint fib(int n) int ret; if (n 2) ret = 1; else ret= fib(n-1) + fib(n-2); return ret;int main() int i; for(i=0;i10;i+) printf(%d , fib(i); system(pause);Mathematical notation v.s. C codeint fib(int n) if(n = 1) return n; /base case else return fib(n-1) + fib(n-2); Execution TraceMystery

9、 Recursionvoid mystery1(int a, int b) if (a print 2(a=0, b=5)(a=0, b=1)(a=3, b=5)(a=0, b=-1)(a=1, b=1)(a=3, b=3)(a=5, b=5)(a=1, b=0)(a=2, b=1)(a=3, b=2) (a=4, b=3)(a=6, b=5)(a=5, b=4)201354(a=0, b=5)(a=0, b=1)(a=3, b=5)(a=0, b=-1)(a=1, b=1)(a=3, b=3)(a=5, b=5)(a=1, b=0)(a=2, b=1)(a=3, b=2) (a=4, b=3

10、)(a=6, b=5)(a=5, b=4)201354Traversal OrderDeclaring Stringschar c10 = “EE/CprE”; /only 7 charsWhat about the uninitialized characters in the string?Array contents Contents of the c arraycEE/CprE0?NULL character automatically assignedArray ContentsProgram:/ character arraychar c10 = “EE/CprE”; printf

11、(“%s”, c); /output 1c8 = a;printf(“%s”, c); /output 2_Output 1: EE/CprEOutput 2: EE/CprEcEE/CprE0a?#include char c7;strcpy(c, “Wednesday”); Assign value to a String Watch out for overflow (bad)cWednesda0yoverfloway#include char c7;strncpy(c, “Wednesday”, 7); Assign value to a String Better to use st

12、rncpy copies up to n characters from the sourcecWednesdneed NULL#include char c7;strncpy(c, “Wednesday”, 6); c6 = 0;/ORc6 = NULL; /NULL and 0 are the sameAssign value to a String Better to use strncpy assign NULL to the end afterwordcWednes0Basic pointer operationsint i = 5; Int* ip = &i; printf

13、(%dn, *ip); http:/ pointer operations*ip = 7;http:/ pointer operationsint j = 3; ip = &j; http:/ pointer operationsint *ip2; ip2 = ip; http:/ pointer operationsip = &i; http:/ and arrays Array indexing: a0, a1, a2, int *ip = &a0; Pointer indexing: *ip, *(ip+1), *(ip+2), In general ai is

14、“equivalent” to *(ip+i) Pointer Arithmetic ip2 = ip1 + 3; ip2 - ip1 = 3 (true or false?)int *ip; int a10; ip = &a3; ip2 = ip + 1; http:/ is the meaning of this?typedef struct nodeint value;struct node *next; node_t;valuenext?Inserting a node into a Linked ListBeforeAfter/wi

15、ki/Linked_listDeleting a node from a linked listBefore:After:/wiki/Linked_listThe road ahead This class is only the beginning. It taught you only the very basics of programming. It taught you very little about many other things. Continue to write programs (even small ones to help you with your other classes or just for fun). Otherwise youll forget it all in 1-2 years!Recommended B

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论