Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jordan Jozwiak CS50. Announcements Pset3 will be returned by 7pm on Tuesday REMINDER: Access section materials from this year and last year at

Similar presentations


Presentation on theme: "Jordan Jozwiak CS50. Announcements Pset3 will be returned by 7pm on Tuesday REMINDER: Access section materials from this year and last year at"— Presentation transcript:

1 Jordan Jozwiak CS50

2 Announcements Pset3 will be returned by 7pm on Tuesday REMINDER: Access section materials from this year and last year at http://cloud.cs50.net/~jjozwiak/http://cloud.cs50.net/~jjozwiak/ Quiz 0 on Wednesday!

3 This Week Quiz 0 Review Quiz 0 Review My questions My questions Your questions Your questions

4 Question (2011.35) Why is it necessary to have: Why is it necessary to have: before a function that calls ? before a function that calls ? #include strlen

5 Question (2010.5) What is the ASCII value of ‘A’, in binary? What is the ASCII value of ‘A’, in binary? 01000001

6 Question (2011.3) How many bits does a single hexadecimal digit (e.g. F) ordinarily represent? How many bits does a single hexadecimal digit (e.g. F) ordinarily represent? 4

7 Question (2009.12) Recall that the formula for conversion from Celsius, C, to Fahrenheit, F, is: C = (5/9) x (F – 32) Recall that the formula for conversion from Celsius, C, to Fahrenheit, F, is: C = (5/9) x (F – 32) Consider the implementation of this formula in C: Consider the implementation of this formula in C: No matter the value of f, this code always assigns c a value of 0.0 No matter the value of f, this code always assigns c a value of 0.0 In no more than 2 sentences, explain why. In no more than 2 sentences, explain why. float c = (5/9) * (f – 32);

8 Answer (2009.12) Since 5 and 9 are both ints, their quotient gets rounded down to 0, thereby assigning c a value of 0 as well. A correct implementation would be: Since 5 and 9 are both ints, their quotient gets rounded down to 0, thereby assigning c a value of 0 as well. A correct implementation would be: float c = (5/9.0) * (f – 32);

9 Question (2010.13)

10 Answer (2010.13) This code always prints “zero” because the if-statement never executes due to an extra semicolon. This code always prints “zero” because the if-statement never executes due to an extra semicolon.

11 Question (2010.14)

12 Answer (2010.14) This program always prints “one” because the if- statement uses an assignment “=“ instead of the comparison “==“. This program always prints “one” because the if- statement uses an assignment “=“ instead of the comparison “==“.

13 Coding Time! No computers necessary today. No computers necessary today. Time to practice coding by hand. Time to practice coding by hand. Grab a piece of paper and a pencil and get ready! Grab a piece of paper and a pencil and get ready!

14 Question (2011.29) Complete the implementation of isupper below in such a way that the function returns false unless its argument is an uppercase letter, in which case the function should instead return true. You may not call isupper, isalpha, or islower. Complete the implementation of isupper below in such a way that the function returns false unless its argument is an uppercase letter, in which case the function should instead return true. You may not call isupper, isalpha, or islower. bool isupper (char c) {

15 Answer (2011.29) bool isupper (char c) { if (c >= ‘A’ && c <= ‘Z’) return true; else return false; }

16 Question (2011.30) Complete the implementation of tolower below in such a way that the function returns its argument, lowercased, unless the argument is not alphabetical, in which case the function should return its argument unchanged. You MAY call the isupper function you just wrote. Complete the implementation of tolower below in such a way that the function returns its argument, lowercased, unless the argument is not alphabetical, in which case the function should return its argument unchanged. You MAY call the isupper function you just wrote. char tolower (char c) {

17 Answer (2011.30) char tolower (char c) { if (isupper(c)) return c – ‘A’ + ‘a’; else return c; }

18 Question (2010.30) Recall that is a function that, according to its man page, “calculates the length of a string s, not including the terminating character. Complete the implementation of below. If s happens to be NULL, your implementation must return 0. Recall that is a function that, according to its man page, “calculates the length of a string s, not including the terminating character. Complete the implementation of below. If s happens to be NULL, your implementation must return 0. int strlen(char* s) { strlen \0 strlen

19 Answer (2010.30) int strlen(char* s) { int n = 0; if (s == NULL) return 0; for (int i = 0; s[i] != ‘\0’; i++) n++; return n; }

20 Question (2010.35) Recall that the “ceiling” of some real number, x, usually written [x], is the smallest integer greater than or equal to x. For instance, [49.001] = 50, [49.1] = 50, [49.5] = 50, [49.9] = 50, and [50.0] = 50. Complete the implementation of below. Recall that the “ceiling” of some real number, x, usually written [x], is the smallest integer greater than or equal to x. For instance, [49.001] = 50, [49.1] = 50, [49.5] = 50, [49.9] = 50, and [50.0] = 50. Complete the implementation of below. int ceil(float x) { ceil

21 Answer (2010.30) int ceil(float x) { if (x – (int) x > 0.0) return (int) (x + 1.0); else return (int) x; }

22 Other Concepts When to "free" memory (and how is that done)?

23 Your Questions What’s on your mind? What’s on your mind?

24 On your way out… Go to to download this PowerPoint and a practice quiz to help review even more. Go to http://cloud.cs50.net/~jjozwiak/ to download this PowerPoint and a practice quiz to help review even more.http://cloud.cs50.net/~jjozwiak/

25 Good luck!!


Download ppt "Jordan Jozwiak CS50. Announcements Pset3 will be returned by 7pm on Tuesday REMINDER: Access section materials from this year and last year at"

Similar presentations


Ads by Google