The evolution of Pokemon society Structures. COMP102 Prog. Fundamentals, Structures / Slide 2 “Good Old Days” At first it was Pokemon and his variables.

Slides:



Advertisements
Similar presentations
Chapter 7 Completing a Program
Advertisements

1 Records C++ Structs Chapter 14 2 What to do with records?  Declaring records  Accessing records  Accessing the field of a record  What is a union?
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
1 Lab 4 Westfield High School APCS LAB 4 Parameters, apvectors, structs.
Starting Out with C++, 3 rd Edition 1 Chapter 11 – Structured Data Abstract data types (ADTs) are data types created by the programmer. ADTs have their.
1 Programming Structures COMP102 Prog. Fundamentals, Structures / Slide 2 2 Structures l A Structure is a collection of related data items, possibly.
A pointer is the memory address of a variable. A memory address is a physical location within a system’s memory space. A pointer variable is variable used.
Structure.
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.
Programming Character I/O. COMP102 Prog. Fundamentals I: Character I/O/ Slide 2 More on char Type l Constant Declaration: const char star = '*'; l Variable.
If Statements & Relational Operators Programming.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
True or false A variable of type char can hold the value 301. ( F )
Programming Scope of Identifiers. COMP102 Prog. Fundamentals I: Scope of Identifiers/ Slide 2 Scope l A sequence of statements within { … } is considered.
Programming Switch command. COMP102 Prog. Fundamentals: Switch command / Slide 2 Multiple Selection: The switch Statement value1 action 1 value2 action.
Functions:Passing Parameters by Value Programming.
Programming Strings. COMP102 Prog. Fundamentals: Strings / Slide 2 Character Strings l A sequence of characters is often referred to as a character “string”.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
Structures COMP104 Structs / Slide 2 Motivation: a new type * Structures hold data that belong together. * Examples: n Student record  student id, name,
Summary of Loops Programming. COMP102 Prog Fundamentals I: Summary of Loops /Slide 2 Which Loop to Use? l for loop n for calculations that are repeated.
Copyright © 2005 Pearson Addison-Wesley. All rights reserved. Slide 1 Overview – Chapter Section 4 Arrays and Classes (10.4)
C++ Numerical Data Input/Output Programming. COMP 102 Prog Fundamentals I:C++ Numerical Data, Input/Output /Slide 2 Rules for Division l C++ treats integers.
Programming Pointers. COMP104 Lecture 32 / Slide 2 Pointers l Pointers are objects whose values are the locations of other objects l Pointers are memory.
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
Programming Introduction to C++.
Programming Initializing Data of Struct Type. COMP102 Prog. Fundamentals: initialize struct type/ Slide 2 Ex. 10: Initialize Data of struct Type l By.
COMP103 - C++ Review1 Variables and Special Chars (Ch. 2, 3)
 Review structures  Program to demonstrate a structure containing a pointer.
1 Structures. Structure (struct) Definition A Structure is a container, it can hold a bunch of things. –These things can be of any type. Structures are.
Comp 245 Data Structures Linked Lists. An Array Based List Usually is statically allocated; may not use memory efficiently Direct access to data; faster.
Introduction to C++ Programming COMP102 Prog. Fundamentals I:Introduction to C++ / Slide 2 Introduction to C++ l C is a programming language developed.
Introduction to Computer Science 2 Slide 1 Enumerated types We already know some data types int, float, char good for problems that involve int,
 Introduction to Computer Science COMP 51 – Fall 2012 – Section 2 Structures.
1 Lecture 04 Structural Programming in C++ You will learn: i) Operators: relational and logical ii) Conditional statements iii) Repetitive statements.
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
Structured Programming Instructor: Prof. K. T. Tsang Lecture 11: Structure and Union 1.
1 Chapter 11 Structured Data. 2 Topics 10.1 Abstract Data Types 10.2 Combining Data into Structures 10.3 Accessing Structure Members 10.4 Initializing.
 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 Structured Data (Lecture 11) By: Dr. Norazah Yusof FSKSM, UTM.
CPT: Types/ Computer Programming Techniques Semester 1, 1998 Objective of these slides: –to look at how new types can be created 6. User-defined.
Struct Data Type in C++ What Are Structures?
1 CS161 Introduction to Computer Science Topic #15.
Struct COMP104 Struct / Slide 2 Motivation * Structures hold data that belong together. * Examples: n Student record  student id, name, major, gender,
 Memory setup  Pointer declaration  Address operator  Indirection  Printing addresses or pointers.
COMP102 Lab 111 COMP 102 Programming Fundamentals I Presented by : Timture Choi.
C Structs Programming in C++ Fall 2008 Dr. David A. Gaitros
Programming 2. Arrays & structure Arrays : allow you to define variables that combine several data items of the same kind. Structure : is another user.
Lesson xx Why use functions Program that needs a function Function header Function body Program rewritten using a function.
Topic 4 Data Structures Program Development and Design Using C++, Third Edition.
Variables Mr. Crone.
Structured Data (Lecture 07)
Chapter 11: Structured Data.
Programming Structures.
Programming Fundamentals
ساختار ها در زبان C Structures in C.
Structures in C++.
Structures A Structure is a collection of related data items, possibly of different types. A structure type in C++ is called struct. A struct is heterogeneous.
Structures December 6, 2017.
Structures.
Arrays An array is a collection of variables that all have the same name and the same data type. Each member of the array is known as an element of the.
CS148 Introduction to Programming II
Objectives In this chapter, you will: - Learn about records (structs) - Examine operations on a struct - Manipulate data using a struct - Learn about the.
Starting to think about objects...
Fundamental Programming
A “User – Defined Data Type”
Programming Structures.
C Programming Lecture-14 Unions
Structure (i.e. struct) An structure creates a user defined data type
Programming Structures.
C++ Parse Analysis Introduction
Presentation transcript:

The evolution of Pokemon society Structures

COMP102 Prog. Fundamentals, Structures / Slide 2 “Good Old Days” At first it was Pokemon and his variables NameIdGenderDept

COMP102 Prog. Fundamentals, Structures / Slide 3 “Old Days” Then there were more Pokemons and their variables Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2

COMP102 Prog. Fundamentals, Structures / Slide 4 “Old Days” And more… Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2 Name_3Id_3Gender_3Dept_3

COMP102 Prog. Fundamentals, Structures / Slide 5 “Old Days” And more… Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2 Name_3Id_3Gender_3Dept_3 Name_4Id_4Gender_4Dept_4

COMP102 Prog. Fundamentals, Structures / Slide 6 “Old Days” And more and more Name_1Id_1Gender_1Dept_1 Name_2Id_2Gender_2Dept_2 Name_3Id_3Gender_3Dept_3 Name_4Id_4Gender_4Dept_4 Name_nId_nGender_nDept_n Name_mId_mGender_mDept_m

COMP102 Prog. Fundamentals, Structures / Slide 7 “What a mess! How can any Pokemon find his variables? We got to get organized!” Every Pokemon’s variable should stay together!

COMP102 Prog. Fundamentals, Structures / Slide 8 New World Order: An almost perfect world! Name IdGender Dept Pokemon_1 Name IdGender Dept Pokemon_2 Name IdGender Dept Pokemon_3 Name IdGender Dept Pokemon_n

COMP102 Prog. Fundamentals, Structures / Slide 9 struct examples l Example: struct Pokemon{ char Name[15]; int Id; char Dept[5]; char Gender; }; The “Pokemon” structure has 4 members.

COMP102 Prog. Fundamentals, Structures / Slide 10 struct basics l Declaration of a variable of struct type: ; l Example: Pokemon Pokemon_1, Pokemon_2; Pokemon_1 and Pokemon_2 are variables of Pokemon type. Pokemon_1Pokemon_2 Name IdGender Dept Name IdGender Dept

COMP102 Prog. Fundamentals, Structures / Slide 11 Chan Tai Man M COMP Ex. 1: struct basics l The members of a struct type variable are accessed with the dot (.) operator:. ; l Example: strcpy(Pokemon_1.Name, "Chan Tai Man"); Pokemon_1.Id = 12345; strcpy(Pokemon_1.Dept, "COMP"); Pokemon_1.gender = 'M'; cout << "The student is "; switch (Pokemon_1.gender){ case 'F': cout << "Ms. "; break; case 'M': cout << "Mr. "; break; } cout << Pokemon_1.Name << endl; Pokemon_1 Name IdGender Dept

COMP102 Prog. Fundamentals, Structures / Slide 12 Chan Tai Man M COMP Ex. 2: struct-to-struct assignment The value of one struct type variable can be assigned to another variable of the same struct type. l Example: strcpy(Pokemon_1.Name, "Chan Tai Man"); Pokemon_1.Id = 12345; strcpy(Pokemon_1.Dept, "COMP"); Pokemon_1.gender = 'M'; Pokemon_2 = Pokemon_1; Pokemon_1 Chan Tai Man M COMP Pokemon_2

COMP102 Prog. Fundamentals, Structures / Slide 13 New World Order: An almost perfect world! Name IdGender Dept Pokemon[0] Name IdGender Dept Pokemon[1] Name IdGender Dept Pokemon[2] Name IdGender Dept Pokemon[n]

COMP102 Prog. Fundamentals, Structures / Slide 14 Chan Tai Man M COMP Ex. 2: struct-to-struct assignment The value of one struct type variable can be assigned to another variable of the same struct type. l Example: strcpy(Pokemon[1].Name, "Chan Tai Man"); Pokemon[1].Id = 12345; strcpy(Pokemon[1].Dept, "COMP"); Pokemon[1].gender = 'M'; Pokemon[2] = Pokemon[1]; Pokemon[1] Chan Tai Man M COMP Pokemon[2]