Week 9 - Friday.  What did we talk about last time?  typedef  Linked lists.

Slides:



Advertisements
Similar presentations
Introduction to C Programming
Advertisements

C Programming Lecture 23 Enumeration Types Structures.
Ain't It A Shame 1-4 Aint it a shame to work on Sunday, Aint it a shame, (a working shame,) Aint it a shame to work on Sunday, Aint it a shame, (a working.
COLORING WITH NUMBERS. NumbersNumbers NumbersNumbers
A Leprechaun Paints A Rainbow! By: Michelle Provence.
Lee was a witch, a very funny witch. On Sunday, she went shopping. She bought a black dog.
© red ©
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 5 Types Types are the leaven of computer programming;
Sizes of simple data types sizeof(char) = 1 size(short) = 2 sizeof(int) = 4 size(long) = 8 sizeof(char) = 1 size(short) = 2 sizeof(int) = 2 size(long)
Saturday May 02 PST 4 PM. Saturday May 02 PST 10:00 PM.
Types A type consists of –a set of values –a set of operations on those values Types can be –primitive (atomic, non-decomposable) –composite (includes.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration.
Ingredients on a Pizza What do you like on your pizza? Extended Activity PPT41.
Section 2 - More Basics. The char Data Type Data type of a single character Example char letter; letter = 'C';
Types(2). 2 Recursive Problems  One or more simple cases of the problem have a straightforward, nonrecusive solution  The other cases can be redefined.
CS 241 – Computer Programming II Lab Kalpa Gunaratna –
The Color Wheel Claire Heider The Primary Colors.
Week 1 - Friday.  What did we talk about last time?  C basics  Data types  Output with printf()
CCSA 221 Programming in C CHAPTER 14 MORE ON DATA TYPES 1 ALHANOUF ALAMR.
3. The Nuts and Bolts of C++ Computer Programming 3. The Nuts and Bolts of C++ 1 Learning the C++ language 3. The Nuts and Bolts of C++ (4)
ping-pong ball basketball volleyball baseball football tennis ---What’s your favorite sport? ---- My favorite sport is…
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
One day seven blind fish found something strange in their ocean.
ECE 103 Engineering Programming Chapter 48 Typedef and Enum Type Herbert G. Mayer, PSU CS Status 6/4/2014 Initial content copied verbatim from ECE 103.
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration Lecture 23.
Homework Assignment You are going to research any artist of your choosing from any time period or genre. You are going to complete a one page double- spaced.
Liang, Introduction to Programming with C++, Second Edition, (c) 2010 Pearson Education, Inc. All rights reserved Chapter 3 Selections.
Compound Statements If you want to do more than one statement if an if- else case, you can form a block of statements, or compound statement, by enclosing.
More Selection Executing Statements Selectively Chap. 7 (Read § & Part of Picture: Boolean Logic and Digital Design) 1.
16. STRUCTURES, UNIONS, AND ENUMERATIONS. Declaring Structures A structure is a collection of one or more components (members), which may be of different.
ISBN Chapter 6 Data Types Introduction Primitive Data Types User-Defined Ordinal Types.
Types(1). Lecture 52 Type(1)  A type is a collection of values and operations on those values. Integer type  values..., -2, -1, 0, 1, 2,...  operations.
Boolean Expressions and if-else Statements Java Methods A & AB Object-Oriented Programming and Data Structures Maria Litvin ● Gary Litvin Copyright © 2006.
Monday December 3rd 1. Check for an titled “assignments” make corrections 2. Open Fall of the Roman Empire letter project your reason.
Data Structure and c K.S.Prabhu Lecturer All Deaf Educational Technology.
Java Implementation: Part 4 Software Construction Lecture 9.
Week 10 - Wednesday.  What did we talk about last time?  Linked list implementations  Started doubly linked lists.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
ENGLISH CLASS TODAY IS MONDAY APRIL 7TH OF 2014 DAYS OF THE WEEK MONDAY TUESDAY WEDNESDAY THURSDAY FRIDAY SATURDAY SUNDAY YESTERDAY WAS.
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
Weekly C-minar Week 0. Today: Steps of the compile Basic inclusion/syntax rules Low-cost containment Debugging.
Monkey, Monkey In the Tree. Monkey, monkey in the tree Throw the yellow coconut down to me!
CSci 162 Lecture 2 Martin van Bommel. Enumeration –process of listing all of the elements in the domain of a type Enumerated type –type defined via enumeration.
Introduction to C# By: Abir Ghattas Michel Barakat.
CSED101 INTRODUCTION TO COMPUTING SUM TYPE 유환조 Hwanjo Yu.
Structure A collection of values (members) struct date{ int day; char month[10]; int year; }; Declare a structure variable struct date today; struct struct_name.
BUILDING JAVA PROGRAMS CHAPTER 7 Arrays days until the AP Computer Science test.
Lecture 7 Computer Programming -1-. Conditional Statements 1- if Statement. 2- if ….. else Statement. 3- switch.
Enum,Structure and Nullable Types Ashima Wadhwa. Enumerations, Enumerations, or enums, are used to group named constants similar to how they are used.
Simple Data Types Chapter Constants Revisited t Three reasons to use constants –Constant is recognizable –Compiler prevents changes in value.
Week 6 - Friday.  What did we talk about last time?  Loop examples.
The birthday calendar 2B : Unit 6 Days of the week Days of the week.
Array contiguous memory locations that have the same name and type. Note: an array may contain primitive data BUT an array is a data structure a collection.
Computer Programming Lab 6. Exercise 1 Sample Runs.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Data Structures & Algorithms CHAPTER 2 Arrays Ms. Manal Al-Asmari.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
PART OF SPEECH DEFINITION SYNONYM SENTENCE NAME TEACHER AND DATE1 WORDS OF THE WEEK.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Week 9 - Friday.  What did we talk about last time?  typedef  Linked lists.
Snowman Glyph Mrs. Bigler.
Watch Pete the Cat here:
Colors/Color Words.
Can I color yellow?. Can I color yellow?
Expression and Asignment Statements
What Color is it?.
Enum.
Variables and Constants
Let’s Learn the Basic Colors
Presentation transcript:

Week 9 - Friday

 What did we talk about last time?  typedef  Linked lists

One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. Robert Firth One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs. Robert Firth

 There are situations where you'd like to have a set of named constants  In many cases, you'd like those constants to be different from each other  What if there were a way to create such a list of constants easily?  Enter enum !

 To create these constants, type enum and then the names of your constants in braces  Then in your code, you can use these values (which are stored as integers) enum { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY }; int day = FRIDAY; if( day == SUNDAY ) printf("My 'I don't have to run' day"); int day = FRIDAY; if( day == SUNDAY ) printf("My 'I don't have to run' day");

 You can also create named enum types  Then you can declare variables of these types  Naturally, because they are constants, it is traditional to name enum values in ALL CAPS enum Color { BLACK, BLUE, GREEN, ORANGE, PURPLE, RED, WHITE, YELLOW }; enum Color color; color = YELLOW; enum Color color; color = YELLOW;

 If you want to declare enum types (and there isn't much reason to, since C treats them exactly like int values), you can use typedef to avoid typing enum all the time typedef enum { C, C_PLUS_PLUS, C_SHARP, JAVA, JAVASCSRIPT, LISP, ML, OBJECTIVE_C, PERL, PHP, PYTHON, RUBY, VISUAL_BASIC } Language; Language language1 = C; Language language2 = JAVA; typedef enum { C, C_PLUS_PLUS, C_SHARP, JAVA, JAVASCSRIPT, LISP, ML, OBJECTIVE_C, PERL, PHP, PYTHON, RUBY, VISUAL_BASIC } Language; Language language1 = C; Language language2 = JAVA;

 enum values by default start at 0 and increase by one with each new constant  In this case, the constants have the following numbering  SUNDAY : 0  MONDAY : 1  TUESDAY : 2  WEDNESDAY : 3  THURSDAY : 4  FRIDAY : 5  SATURDAY : 6 enum { SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY };

 You can even specify the values in the enum  If you assign values, it is possible to make two or more of the constants have the same value (usually bad)  A common reason that values are assigned is so that you can do bitwise combinations of values enum { ANIMAL = 7, MINERAL = 9, VEGETABLE = 11 }; enum { PEPPERONI = 1, SAUSAGE = 2, BACON = 4, MUSHROOMS = 8, PEPPER = 16, ONIONS = 32, OLIVES = 64, EXTRA_CHEESE = 128 }; int toppings = PEPPERONI | ONIONS | MUSHROOMS; enum { PEPPERONI = 1, SAUSAGE = 2, BACON = 4, MUSHROOMS = 8, PEPPER = 16, ONIONS = 32, OLIVES = 64, EXTRA_CHEESE = 128 }; int toppings = PEPPERONI | ONIONS | MUSHROOMS;

 One of the most common uses of enum is to specify a Boolean type  It's not a perfect system, since you can assign values other than 0 and 1 to a BOOLEAN  Likewise, other values are also true in C typedef enum { FALSE, TRUE } BOOLEAN; BOOLEAN value = TRUE; BOOLEAN flag = FALSE; typedef enum { FALSE, TRUE } BOOLEAN; BOOLEAN value = TRUE; BOOLEAN flag = FALSE;

 More on linked lists and data structures using structs and pointers

 Keep working on Project 4  Keep reading K&R chapter 6