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

Slides:



Advertisements
Similar presentations
Computer Programming w/ Eng. Applications
Advertisements

C Characters & Strings Character Review Character Handling Library Initialization String Conversion Functions String Handling Library Standard Input/Output.
Strings Testing for equality with strings.
Chapter 3 DATA: TYPES, CLASSES, AND OBJECTS. Chapter 3 Data Abstraction Abstract data types allow you to work with data without concern for how the data.
Nirmalya Roy School of Electrical Engineering and Computer Science Washington State University Cpt S 122 – Data Structures Characters and Strings.
Chapter 8 Characters and Strings Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Introduction to Computers and Programming Lecture 7:
1 9/24/07CS150 Introduction to Computer Science 1 Relational Operators and the If Statement.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 8 - Characters and Strings Outline 8.1Introduction.
Please pick up an attendance question and submit in 5 minutes CS 1003 Lecture #3 Sept 12, 2006 Knarig Arabshian.
PHYS 2020 Making Choices; Arrays. Arrays  An array is very much like a matrix.  In the C language, an array is a collection of variables, all of the.
1 CS150 Introduction to Computer Science 1 Relational Operators and the If Statement 9/22/08.
CS Nov 2006 C-strings.
Bit Operations C is well suited to system programming because it contains operators that can manipulate data at the bit level –Example: The Internet requires.
A bit can have one of two values: 0 or 1. The C language provides four operators that can be used to perform bitwise operations on the individual bits.
Administrative MUST GO TO CORRECT LAB SECTION! Homework due 11:59pm on Tuesday. 25 points off if late (up to 24 hours) Cannot submit after 11:59pm on Wednesday.
Data Structure and C Part-6. Naming a Function Any valid variable-name can be given to the user-defined function. The main program itself is considered.
 2007 Pearson Education, Inc. All rights reserved C Characters and Strings.
Agenda Review Compiling Review Data Types Integer Division Composition C++ Mathematical Functions User Input Reading: , 8.11 Homework #3.
CPS 2231 Computer Organization and Programming Instructor: Tian (Tina) Tian.
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
C programming: Variables, Expressions part II. Data Types of Arithmetic Expressions Relational Expressions Logical Expressions Multiple Assignments Compound.
1 Chapter 9 Scope, Lifetime, and More on Functions.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 8 - Characters and Strings Outline 8.1Introduction 8.2Fundamentals of Strings and Characters 8.3Character.
February 14, 2005 Characters, Strings and the String Class.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter 3 Section 1 Number Representation Modern cryptographic methods, unlike the classical methods we just learned, are computer based. Representation.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
CH2 – Using Data. Constant Something which cannot be changed Data Type Format and size of a data item Intrinsic Data Types Pg. 47 – Table 2-1 Basic ones.
1 Conditions Logical Expressions Selection Control Structures Chapter 5.
Functions Why we use functions C library functions Creating our own functions.
C++ Programming: Basic Elements of C++.
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Data Types & I/O Streams Objectives Data Types Understand that integers form the underlying foundation for many data types. Introduce a few frequently.
CS177 Week2: Recitation Primitive data types and Strings with code examples.
The character data type char. Character type char is used to represent alpha-numerical information (characters) inside the computer uses 2 bytes of memory.
Arrays II (Strings). Data types in C Integer : int i; Double: double x; Float: float y; Character: char ch; char cha[10], chb[]={‘h’,’e’,’l’,’l’,’o’};
Getting Started Java Fundamentals CSC207 – Software Design Summer 2011 – University of Toronto – Department of Computer Science.
Unit 3 Lesson 11 Passing Data and Using Library Functions Textbook Authors: Knowlton, Barksdale, Turner, & Collings PowerPoint Lecture by Dave Clausen.
CSC141- Introduction to Computer programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 21 Thanks for Lecture Slides:
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Chapter 2 Input, Variables and Data Types. JAVA Input JAVA input is not straightforward and is different depending on the JAVA environment that you are.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CSC Programming for Science Lecture 8: Character Functions.
COMPE 111 Introduction to Computer Engineering Programming in Python Atılım University
Characters and Strings
CSC 107 – Programming For Science. Announcements  Lectures may not cover all material from book  Material that is most difficult or challenging is focus.
Strings, and the string Class. C-Strings C-string: sequence of characters stored in adjacent memory locations and terminated by NULL character The C-string.
Principles of Programming - NI Chapter 10: Character & String : In this chapter, you’ll learn about; Fundamentals of Strings and Characters The difference.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
 Type Called bool  Bool has only two possible values: True and False.
Chapter 2: Introduction to C++
C Characters and Strings
EPSII 59:006 Spring 2004.
Binary, Decimal and Hexadecimal Numbers
Chapter 8 - Characters and Strings
Chapter 2: Introduction to C++
Decision Making.
10.1 Character Testing.
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Fundamentals of Functional Programming
SE1H421 Procedural Programming LECTURE 4 Operators & Conditionals (1)
In your notebook… Purpose: What types of data can we store in C
C Characters and Strings
Programming Fundamental-1
COMPUTING.
Section 6 Primitive Data Types
Presentation transcript:

Jordan Jozwiak CS50

Announcements Pset3 will be returned by 7pm on Tuesday REMINDER: Access section materials from this year and last year at Quiz 0 on Wednesday!

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

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

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

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

Question ( ) 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);

Answer ( ) 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);

Question ( )

Answer ( ) 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.

Question ( )

Answer ( ) 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 “==“.

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!

Question ( ) 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) {

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

Question ( ) 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) {

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

Question ( ) 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

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

Question ( ) 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

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

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

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

On your way out… Go to to download this PowerPoint and a practice quiz to help review even more. Go to to download this PowerPoint and a practice quiz to help review even more.

Good luck!!