Lecture 16 CIS 208 Friday March 18 th, 2005. Last bit on structs, I swear Structs in Debugger It’s your friend.

Slides:



Advertisements
Similar presentations
Incomplete Structs struct B; struct A { struct B * partner; // other declarations… }; struct B { struct A * partner; // other declarations… };
Advertisements

Question Bank. Explain the syntax of if else statement? Define Union Define global and local variables with example Concept of recursion with example.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
1 CSE 331 Enumerated types ( enum ) slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia
Unions The storage referenced by a union variable can hold data of different types subject to the restriction that at any one time, the storage holds data.
Counting Money & Making Change By Mrs. Wade One cent Five cents Ten cents Nickel Identify coins Penny Dime.
Made by: Second Grade On the head side One coin that equals On the tails side Give the value of…
Topic Map Topic 5 Lesson 1 = Dime, Nickel, Penny
David Notkin Autumn 2009 CSE303 Lecture 9 Dictionary.com, "c," in The American Heritage® Abbreviations Dictionary, Third Edition. Source location: Houghton.
CS 112 Intro to Computer Science II Sami Rollins Fall 2006.
1 CSE 303 Lecture 8 Intro to C programming read C Reference Manual pp. Ch. 1, , 2.6, 3.1, 5.1, , , , Ch. 8 ; Programming.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 10 - Structures, Unions, Bit Manipulations, and Enumerations Outline 10.1Introduction 10.2Structure.
Dynamic Allocation and Linked Lists. Dynamic memory allocation in C C uses the functions malloc() and free() to implement dynamic allocation. malloc is.
What is your strategy for counting money?
2nd grade Math Lesson 2.MD.8. Solve word problems involving dollar bills, quarters, dimes, nickels, and pennies, using $ and ¢ symbols appropriately.
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration.
Pennies, Nickels, and Dimes Objective: I will count pennies, nickels, and dimes. Standard: Identify and know the value of coins. Student’s Job to Learn.
I wonder who has more money…. 1 dollar, 3 nickels, 5 dimes 6 dimes, 3 pennies, 5 quarters 8 pennies, 6 nickels, 3 dimes 2 half dollars, 5 pennies, 8 nickels.
Penny Nickel Dime Music by: Dr. Jean Power Point by Mrs. Holton.
C Tokens Identifiers Keywords Constants Operators Special symbols.
17. ADVANCED USES OF POINTERS. Dynamic Storage Allocation Many programs require dynamic storage allocation: the ability to allocate storage as needed.
Money By: Rachel Morello Teacher Page Click here!
Engineering H192 - Computer Programming Gateway Engineering Education Coalition Lect 23P. 1Winter Quarter Structs and Enumeration Lecture 23.
Money I. Objectives To be able to recognize U.S. coins & the dollar To know the value of each coin & dollar To know how coins are related to each other.
Counting Money Pennies, Nickels, & Dimes Created by Mrs. Miller Math SOL K.7 & 1.10.
Penny Nickel Dime Penny Nickel Dime Quarter Half Dollar.
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$ $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Who uses it?. We all use money to buy what we need to function in our world. Money Vocabulary Bills Dollars Coins Sliver Dollar Half Dollar Fifty Cent.
Counting Coins. The Basics Quarter 25 cents Dime 10 cents.
Lesson 14: Identifying and Counting Coins
MONEY! Pick the correct coin! Click here to get started!!
Touch Money Jane Hancock.
 M2N1. Students will use multiple representations of numbers to connect symbols to quantities  c. Use money as a medium of exchange. Make change and.
Money By Shelly Hodges Let’s learn about money!
Canadian Money. Coins Penny 1 cent 1¢ Nickel 5 cents 5¢
Dennis Ritchie 1972 AT & T Bell laboratories (American Telephone and Telegraph) USA 1www.gowreeswar.com.
Let’s Learn About Money!
Name the United States Coins Count the Pennies 10 ¢
Coin Problems.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Adding and Subtracting Money! Click on the dollar sign to begin!
Coins A small piece of metal, usually flat and circular, authorized by a government for use as money.
The Importance of Counting Coins. Coins in everyday life  How important is being able to count coins?  What are coins used for?  When and how often.
Counting Quarters, Dimes, Nickels, and Pennies Click here to begin Click here to begin.
Money, Money, Money, Money!!!!!!! Counting money is as easy as 1, 2, 3.
ENEE150 – 0102 ANDREW GOFFIN Abstract Data Types.
2 nd Grade Math Counting Money by Annette Burchett.
Money – Change Combinations &MathLine. Start with each ring representing a penny Money – Change.
$ Money $ $ Money $ $ Money $.
MATHEMATICS JEOPARDY! Allie Marshall 2 nd Grade Mathematics.
HOW CAN I CONVERT MONEY? MCC.4.MD.1 Money. Conversions ____ pennies = 1 nickel ____ nickels = 1 dime ____ dimes = 1 dollar ____ quarters = 1 dollar.
Structures, Unions, Enumerations
Warm-Up Ch.3 #2B Gr 6.
k-2 Lesson d: kids as coins Coin Signs
Money Concept Assessment Bank
BY GAWARE S.R. COMPUTER SCI. DEPARTMENT
Instructor: Ioannis A. Vetsikas
CSC 253 Lecture 8.
CSC 253 Lecture 8.
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $
Name the United States Coins
Dynamic Memory A whole heap of fun….
C Programming Lecture-8 Pointers and Memory Management
The Stack.
Module 2 Variables, Data Types and Arithmetic
Money Math Review.
C# Language & .NET Platform 9th Lecture
Counting Money Pennies, Nickels, & Dimes
Exercise 6 – Compound Types und Kontrollfluss
Presentation transcript:

Lecture 16 CIS 208 Friday March 18 th, 2005

Last bit on structs, I swear Structs in Debugger It’s your friend

Enumerations new types with limited, specific values Example: Create a coin type that only allows the values: penny, nickel, dime, quarter, dollar called symbols

Money type enum coin {penny,nickel,dime,quarter,dollar}; //type definition enum coin money; // variable declaration value money now will only accept values called penny, nickel, etc.

enums money = dime; money = penny; if(money == dime) printf(“dime”); penny, dime,etc are now values, like 1, ‘a’, 2.3

enums actual values of penny, nickel, etc are ints. penny == 0; nickel == 1; dime == 2; etc given values in order of definition enum coin{penny, nickel, dime…}; 012

values of enums Since values are just ints, they act like ints printf(“%d %d”, penny, dime); 0 2 Using enumerations let’s users not care about actual values Especially if the enumeration is defined in a header file

Initial values Enums don’t have to use default values. enum coin{penny,nickel, dime, quarter = 100, half-dollar, dollar}; penny = 0 nickel = 1 dime = 2 quarter = 100 half-dollar = 101 dollar = 102

enums values Don’t have to be unique enum foo{fred =1, lucy = 1, ethel = 1};

using enums switch(money) { case penny: value += 1; break; case nickel: value +=5; break; case dime: value += 10; break; etc

one last example char name[][12] = { “penny”, “nickel”, “dime”, “half-dollar”, “dollar”}; printf(“%s”, name[money]); only works if no symbol has been initialized.

Unions Memory location shared by two or more different variables Usually of different types, at different times. Generally just one at a time

Unions declared like structs union u_type { int j; char ch; }; union u_type bar;

unions all variables exist in same memory int j & char ch share some memory. changing one might change the other.

access same as structs,. operator for actual union variables -> operator for pointers to unions

allocation default size is the size of the largest element. for dynamic allocation, use sizeof

‘practical’ example struct symbol{ enum type {INT, CHAR, STRING} kind; union foo { int I; char C; char S[10];} val; } mySym;

continued switch (mySym.kind) { case INT: printf(“%d”, kind.val.I); break; case CHAR: printf(“%c”, kind.val.C); break; case STRING: printf(“%s”,kind.val.S); }