ENUMERATED DATATYPES. USER DEFINED DATA TYPES  Data Type Defined By Programmer  Allows Use Of More Complex Data  Typically Defined Globally So Variables.

Slides:



Advertisements
Similar presentations
1 C++ Syntax and Semantics The Development Process.
Advertisements

This Time Pointers (declaration and operations) Passing Pointers to Functions Const Pointers Bubble Sort Using Pass-by-Reference Pointer Arithmetic Arrays.
Pointers Typedef Pointer Arithmetic Pointers and Arrays.
Chapter 7: User-Defined Simple Data Types, Namespaces, and the string Type.
Objectives In this chapter, you will:
Informática II Prof. Dr. Gustavo Patiño MJ
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Computer Science 1620 Other Data Types. Quick Review: checklist for performing user input: 1) Be sure variable is declared 2) Prompt the user for input.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 9 Pointers and Dynamic Arrays.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
An Introduction to Programming with C++ Fifth Edition Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation –The new operator –The delete operator –Dynamic.
Data Types.
Basic Elements of C++ Chapter 2.
Variables, Constants, Methods, and Calculations Chapter 3 - Review.
VARIABLES, TYPES, INPUT/OUTPUT, ASSIGNMENT OPERATION Shieu-Hong Lin MATH/CS Department Chapel.
Java for Beginners University Greenwich Computing At School DASCO
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Announcements Final NEXT WEEK (August 13 th Thursday at 16:00) Recitations will be held on August 12 th Wednesday We will solve sample final questions.
C++ Programming: From Problem Analysis to Program Design, Second Edition1 Objectives In this chapter you will: Learn about the pointer data type and pointer.
Defining and Converting Data Copyright Kip Irvine, 2003 Last Update: 11/4/2003.
Copyright 2003 Scott/Jones Publishing Standard Version of Starting Out with C++, 4th Edition Chapter 11 Structured Data.
Structures in C++ UNIVERSITY OF THE PUNJAB (GUJRANWALA CAMPUS) 1 ADNAN BABAR MT14028 CR.
Introduction to C++ Version 1.1. Topics C++ Structure Primitive Data Types I/O Casting Strings Control Flow.
Copyright 2005, The Ohio State University 1 Pointers, Dynamic Data, and Reference Types Review on Pointers Reference Variables Dynamic Memory Allocation.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 11: Structured Data.
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 8: User-Defined Simple Data Types, Namespaces, and the string Type.
Copyright © 2012 Pearson Education, Inc. Chapter 11: Structured Data.
C++ Basics. Compilation What does compilation do? g++ hello.cpp g++ -o hello.cpp hello.
Computing and Statistical Data Analysis Lecture 2 Glen Cowan RHUL Physics Computing and Statistical Data Analysis Variables, types: int, float, double,
© Oxford University Press All rights reserved. CHAPTER 8 STRUCTURES.
CSC 143A 1 CSC 143 Introduction to C++ [Appendix A]
PROGRAM ESSENTIALS. TOKENS  SMALLEST UNITS OF A PROGRAM LANGUAGE  Special Symbols  Mathematical Operators  Punctuation  Word Symbols  Key Words.
C++ for Java Programmers Chapter 2. Fundamental Daty Types Timothy Budd.
Pointers in C++. Topics Covered  Introduction to Pointers  Pointers and arrays  Character Pointers, Arrays and Strings  Examples.
CMPSC 121- Spring 2015 Lecture 6 January 23, 2015.
Lecture 5: Expressions and Interactivity Professor: Dr. Miguel Alonso Jr. Fall 2008 CGS2423/COP1220.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 9 Pointers and Dynamic Arrays.
CS201 Introduction to Sabancı University 1 Chapter 2 Writing and Understanding C++ l Writing programs in any language requires understanding.
Copyright © 2014 Pearson Addison-Wesley. All rights reserved. Chapter 9 Pointers and Dynamic Arrays.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 11: Structured Data.
1 Recall that... char str [ 8 ]; str is the base address of the array. We say str is a pointer because its value is an address. It is a pointer constant.
1 Chapter 15-1 Pointers, Dynamic Data, and Reference Types Dale/Weems.
C++ Basics Programming. COMP104 Lecture 5 / Slide 2 Introduction to C++ l C is a programming language developed in the 1970s with the UNIX operating system.
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.
Array and Pointers An Introduction Unit Unit Introduction This unit covers the usage of pointers and arrays in C++
1 1  Lecture 11 – Structured Data FTMK, UTeM – Sem /2014.
1 A more complex example Write a program that sums a sequence of integers and displays the result. Assume that the first integer read specifies the number.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter Structured Data 11. Combining Data into Structures 11.2.
Basic Concepts:- Invalid use of Address Operator &75 &(‘a’) &(a+b)
Data Storage So far variables have been able to store only one value at a time. What do you do if you have many similar values that all need to be stored?
Bill Tucker Austin Community College COSC 1315
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Chapter 8: Namespaces, the class string, and User-Defined Simple Data Types.
Chapter Topics The Basics of a C++ Program Data Types
Objectives In this chapter, you will:
Enumeration Type Data type: a set of values with a set of operations on them Enumeration type: a simple data type created by the programmer To define an.
Type Checking Generalizes the concept of operands and operators to include subprograms and assignments Type checking is the activity of ensuring that the.
Computing and Statistical Data Analysis Lecture 2
Introduction to Computer Science / Procedural – 67130
Basic Elements of C++.
Basic Elements of C++ Chapter 2.
Chapter 2 Elementary Programming
Data Types Chapter 8.
Introduction to C++ Programming
CS150 Introduction to Computer Science 1
Objectives In this chapter, you will:
Python Creating a calculator.
Presentation transcript:

ENUMERATED DATATYPES

USER DEFINED DATA TYPES  Data Type Defined By Programmer  Allows Use Of More Complex Data  Typically Defined Globally So Variables Of The Type Can Be Declared Wherever Needed  Types Include:  enumerated  arrays  structures  array of structures  linked list

ENUMERATED DATA TYPE  User Defined Type  Used To Increase Readability Of Programs  Assigns Meaningful Name To Value  Programmer Defines Names Of Values  Internal Data Type That Cannot Be Read Or Written

ENUMERATED DATA TYPE  Requires List Of Values (Enumerated Constants)  List Is Identified With A New Data Type  Values Are Not char, string Or Number  No ‘ ‘ or “ “ Around Constants  Constants Must Be Valid Identifier Names  Constants Cannot Be Used In Another Enumerated Data Type In Same Program  Proper Syntax: enum colors {BLACK, RED, GREEN, BLUE, BROWN};

ENUMERATED DATA TYPE  Declaring Data Type Does Not Allocate Memory  Variables Of Type Needs To Be Declared colors shirtColor, pantColor  This Creates Two Variables That Can Store Enumerated Constant shirtColor = RED; pantColor = BLUE;

ENUMERATED DATA TYPE  The Enumerated Constants Are An Ordered List Of Values (ordinal type)  The First Constant Has The Ordinal Value Zero  Each Successive Constant Is One Greater  Internally The Data Type Stored When Using The Enumerated Constant Is Integer cout << pantColor << ‘ ‘ << shirtColor << endl; displays: 3 1

ENUMERATED DATA TYPE  Constants Are Ordinal So Relational Operators Can Be Used if (shirtColor > pantColor) cout << “You May Want To Change Your Shirt” << endl;  Arithmetic Operators Cannot Be Used Directly shirtColor = pantColor + 1; // THIS IS ILLEGAL  However Use Of Static Cast Allows Addition / Subtraction shirtColor = static_cast (pantColor + 1) // IS LEGAL

ENUMERATED DATA TYPE  WARNING, WARNING, WARNING…. There Is No Predecessor Before The First Constant And No Successor After The Last Constant  Trying To Subtract One From The First Or Add One To The Last Causes An Undefined Value

ENUMERATED DATA TYPE  Two Major Drawbacks:  Cannot Be Input Directly From Keyboard  Cannot Be Output Directly To The Screen (except for ordinal value)  Solving Problem Requires:  Creating An Input Function That Accepts Allowed Input And Converts To Enumerated Value  Creating An Output Function That Converts Enumerated Value To A Value That Can Be Displayed

ENUMERATED DATA TYPE  In The End:  Enumerated Data Types Provide For More Readable Code  But Often Require Extra Coding To Make Them Useable