CGS 3460 Thus Far n Whenever we declare a variable, we specified its data type. n The data type helped us identify the type of information that a variable.

Slides:



Advertisements
Similar presentations
Data Types in C. Data Transformation Programs transform data from one form to another –Input data  Output data –Stimulus  Response Programming languages.
Advertisements

1 Chapter 11 Introducing the Class Pages ( )
1 Programming Structures COMP102 Prog. Fundamentals, Structures / Slide 2 2 Structures l A Structure is a collection of related data items, possibly.
C Structures Basics of structures Typedef. Data Hierarchy Byte –8 bits (ASCII character ‘A’ = ) Field –Group of characters (character string “Fred”)
Structure.
Structures Spring 2013Programming and Data Structure1.
Structures in C.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
CSC141- Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture – 25 Thanks for Lecture Slides: Dr. Sadaf Tanveer Dr. Sadaf Tanveer,
What have we learned so far… Preprocessor directives Introduction to C++ Variable Declaration Display Messages on Screen Get Information from User Performed.
Structures. An array allows us to store a collection of variables However, the variables must be of the same type to be stored in an array E.g. if we.
Dale/Weems/Headington
ECE 353: Lab C Pointers and Structs. Basics A pointer holds an address to some variable Notation: – Dereferencing operator: * int *x is a declaration.
Lecture 3 1. Structures 2. Abstract Data Types. STRUCTURES WHY ARE STRUCTURES NEEDED? If the predefined types are not adequate to model the object, create.
Introduction to C Programming CE Lecture 10 Data Structures typedef and struct.
1 Lecture 25 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
Data Type. A data type defines a set of values that a variable can store along with a set of operations that can be performed on that variable. Common.
Structures EE2372 Software Design I Dr. Gerardo Rosiles.
Lecture 8. Lecture 8: Outline Structures [Kochan, chap 9] –Defining and using Structures –Functions and Structures –Initializing Structures. Compound.
Structs. Structures We already know that arrays are many variables of the same type grouped together under the same name. Structures are like arrays except.
Chapter 6 Structures and Classes. Copyright © 2006 Pearson Addison-Wesley. All rights reserved. 6-2 Structures  2 nd aggregate data type: struct  Recall:
 For Loops › for (variable set; condition; incremental or decrement){ // loop beginning › } // loop end  While loops › while (condition) { // beginning.
C Programming Tutorial – Part I CS Introduction to Operating Systems.
C Tokens Identifiers Keywords Constants Operators Special symbols.
Database Management System Lecture 4 The Relational Database Model- Introduction, Relational Database Concepts.
Structured Data Types array array union union struct struct class class.
Functions, Pointers, Structures Keerthi Nelaturu.
Attribute Grammar Examples and Symbol Tables Compiler Design Lecture (02/23/98) Computer Science Rensselaer Polytechnic.
Understanding Structures tMyn1 Understanding Structures In order to describe virtually anything in the real world, you need to define several values that.
Cosc237/structures1 Structures aggregate data types record - single variable name for the whole collection composed of several variables - fields,BUT,
Module 4: Structures ITEI222 Advanced Programming.
Review of ICS 102. Lecture Objectives To review the major topics covered in ICS 102 course Refresh the memory and get ready for the new adventure of ICS.
CISC105 – General Computer Science Class 9 – 07/03/2006.
GUIDED BY- A.S.MODI MADE BY- 1. SHWETA ALWANI 2. PRIYANKA.
CGS 3460 More On File IO. CGS 3460 What is a File n A file is a package of information with a name attached to it. n Files are used for various purposes:
1 Chapter 11 Structured Types, Data Abstraction and Classes Dale/Weems/Headington.
COP Structures Instructor: Diego Rivera-Gutierrez I’m back baby!
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 6: Object-Oriented Programming.
Senem Kumova Metin STRUCTURES continues CHAPTER 9 in A Book in C.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Structured Data Types struct class Structured Data Types array – homogeneous container collections of only one type struct – heterogeneous data type.
Passing Structure to function.  structure to function structure to function  Passing structure to function in C Passing structure to function in C 
1 CSC241: Object Oriented Programming Lecture No 02.
1 C Language Structures. 2 Topics Concept of a structure Concept of a structure Structures in c Structures in c Structure declaration Structure declaration.
Structures and Unions in C Alan L. Cox
+ Structures and Unions. + Introduction We have seen that arrays can be used to represent a group of data items that belong to the same type, such as.
CCSA 221 Programming in C CHAPTER 9 WORKING WITH STRUCTURES 1.
ENEE150 – 0102 ANDREW GOFFIN Project 4 & Function Pointers.
1 CSC103: Introduction to Computer and Programming Lecture No 24.
Slide 1 Chapter 6 Structures and Classes. Slide 2 Learning Objectives  Structures  Structure types  Structures as function arguments  Initializing.
1 CS161 Introduction to Computer Science Topic #15.
Introduction to Computers and Programming Class 24 Structures (structs) Professor Avi Rosenfeld.
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.
CCSA 221 Programming in C CHAPTER 11 POINTERS ALHANOUF ALAMR 1.
1 11/30/05CS150 Introduction to Computer Science 1 Structs.
13/10/2016CS150 Introduction to Computer Science 1 Multidimensional Arrays  Arrays can have more than one column  Two dimensional arrays have two columns.
Advanced Programming Constants, Declarations, and Definitions Derived Data Types.
Click to edit Master title style Click to edit Master text styles –Second level Third level –Fourth level »Fifth level 1 Fundamentals of Programming Most.
‘C’ Programming Structures and Commands
CO1401 Program Design and Implementation
Chapter 10-1: Structure.
Time Manager Class Activity Material Manager Writer leader Communicator Programmer Start a journey from the capital AbuDhabi to Alasmaa School using your.
Structures December 6, 2017.
Structures putting data together.
Variables and Their scope
Structured Data Types array union struct class.
Structures Structured Data types Data abstraction structs ---
C++ Parse Analysis Introduction
Structures, Unions, and Enumerations
Presentation transcript:

CGS 3460 Thus Far n Whenever we declare a variable, we specified its data type. n The data type helped us identify the type of information that a variable holds. n So far we have seen simple data types lint - represent whole numbers lfloat - represent numbers with decimal (fractional part), lchar - represent characters n We have also seen arrays, that allow us to represent a collection of data elements of a specific type with a single variable name. n We accessed individual elements in the collection using the array subscript operator [].

CGS 3460 Structures n Structures in C allows us to represent a collection of variables (possibly of different types) under a single name. n It allows us to create record style data with various fields. n More generally, it allows us to model real-world entities. n An entity is something that has a distinct, seperate existence. n An entity has a set of attributes that describes it. n Any object in the real-world can be modeled as an entity. n A book is an entity that can be distinguished from say a car.

CGS 3460 Examples Book Title Author Price Car Make Model Year Student Name ID Age Major Hometown Country Name Capital Population Longitude Latitude

CGS 3460 Examples – Programming Specific Book string Title string Author float Price Car int Make int Model int Year Student string Name string ID unsigned Age int Major string Hometown Country string Name string Capital unsigned Population float Longitude float Latitude

CGS 3460 Structure – Declaring n A collection of values (members) – type declaration struct struct_name { type1 data_member1; type2 data_member2; …; typeN data_memberN; }; n Declare a structure variable – instance declaration lstruct struct_name instance_name;

CGS 3460 Examples – Programming Specific Student string Name string ID unsigned Age int Major stringHometown struct Student { char Name[50]; char ID[9]; unsigned Age; int Major; char Hometown }; struct Student you;

CGS 3460 Examples – Programming Specific Book string Title string Author float Price struct Book { char Title[100]; char Author[100]; float price; }; struct Book bestSeller;

CGS 3460 Examples – Programming Specific Car int Make int Model int Year struct Car { int Make; int Model; int Year; }; struct Car carForSale;

CGS 3460 Examples – Programming Specific Country string Name string Capital unsigned Population float Longitude float Latitude struct Country { char Name[100]; char Capital[100]; unsigned Population; float Longitude; float Latitude; }; struct Country home;

CGS 3460 Examples – Programming Specific Date int Day string Month int Year struct Date { int Day; char Month[10]; int Year; }; struct Date today;

CGS 3460 Declarations n Three ways struct date{ int day; char month[10]; int year; }; struct date today; typedef struct { int day; char month[10]; int year; } date; date today; struct { int day; char month[10]; int year; } today;

CGS 3460 Initialization struct { int day; char month[10]; int year; } today = {15, “ June ”, 2007}; typedef struct { int day; char month[10]; int year; } date; date today = {15, “June”, 2007}; struct date{ int day; char month[10]; int year; }; struct date today = {15, “June”, 2007};

CGS 3460 How to use n To access the members in the structure lspecify the variable name, followed by a period and the member name today.day = 15; today.year = 2007; today.month[0]=‘J’; today.month[1]=‘u’; today.month[2]=‘n’; today.month[3]=‘e’; today.month[4]=‘\0’; lOR today.day = 15; today.year = 2007; today.month=“June”; 15 ‘J’ ‘u’ ‘n’ ‘e’ ‘\0’ 2007.month.day.year today

CGS 3460 How to use structure – cont. n Structure variable can be passed as a parameter to a function. n Structure variable can be returned from a function n Can have arrays of structures, and structures containing arrays or other structures. lstruct date list_of_days[10]; lstruct journalEntry { int location; struct date when; char entry[1000]; };

CGS 3460 Scope n A structure type declaration can be local or global lif declared locally, it is only valid locally. struct ONE { int a; float b; }; void main () { struct ONE x; } int f() { struct ONE x; } void main () { struct ONE { int a; float b; }; struct ONE x; } int f() { struct ONE x; }