lecture21-march11

# lecture21-march11 - Announcements Lecture 21 Read Chapter...

This preview shows pages 1–2. Sign up to view the full content.

1 Announcements Lecture 21 • Read Chapter 14 for after the break • Assignment 4 – Due Friday – Write down your stats (SLOC,hrs, logic errors) Friday lecture and recitations called off • Topics for today – enumerations – Random numbers (pg 570-571) – Performance evaluation enum Type An enumeration type stands for a set of named integer constants that specify all the legal values that a variable of that type can hold The advantage (over #define) is they follow the scope rules E.g. enum weekday { SUN, MON, TUE, WED, THURS, FRI, SAT }; /* C gives these the values of 0,1,2,. . . 6 by default */ weekday today; /* declare a variable of that enum type */ scanf (“%d”, &today); if ( today == MON | | today == WED || today == FRI ) { printf ( "Today is a ee312 lecture day;go to class \n"); } Enumerations (2) /* you can give the identifiers specific int values instead */ enum coin_value { PENNY=1, NICKEL=5, DIME=10, QUARTER=25, HALF_DOLLAR=50, DOLLAR=100}; coin_value money; /* declare a variable of that type*/ scanf (“%d”, &money); printf ( ”the value of money input is a ”); switch(money) { case PENNY: printf ( "penny”); break; case NICKEL: printf ( "nickel”); break; case DIME: printf ( "dime”); break; case QUARTER: printf ( "quarter”); break; case HALF_DOLLAR: printf ( "half_dollar”); break; case DOLLAR: printf ( "dollar”); break; default: printf ( ” non-legitimate coin value”); } Simulating Randomness in C • What is a random number? pseudorandom

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 01/24/2010 for the course EE 312 taught by Professor Shafer during the Spring '08 term at University of Texas.

### Page1 / 3

lecture21-march11 - Announcements Lecture 21 Read Chapter...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online