Structure and Union Types 程式設計 潘仁義 CCU COMM. Structure Type Definition struct structured data objects, can be defined by users #define STRSIZ 10 typedef.

Slides:



Advertisements
Similar presentations
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Advertisements

 Overloading Methods  The Scope of Variables  The Math Class  Floating point Format [Sample code] TestMethodOverloading.java 、 AmbiguousOverloading.java.
Introduction to Java Programming Lecture 10 Method Benefits, Declaring, and Calling Methods.
Structures Spring 2013Programming and Data Structure1.
齊來學中文 Let’s Learn Chinese 英國中文學校聯會出版 Published by the UK Federation of Chinese Schools.
Student Data Score First Name Last Name ID GPA DOB Phone... How to store student data in our programs? 1.
10 Macros.  Lisp code is expressed as lists, which are Lisp objects  This makes it possible to write programs that would write programs  This lecture.
Divide-and-Conquer. 什麼是 divide-and-conquer ? Divide 就是把問題分割 Conquer 則是把答案結合起來.
Perception and Understanding1 Lesson Objectives 1.Why perceptions differ among people? 2.Why do social roles affect perception? 3.What is the self-serving.
Teacher : Ing-Jer Huang TA : Chien-Hung Chen 2015/6/2 Course Embedded Systems : Principles and Implementations Weekly Preview Question CH 1.4~CH /10/03.
© 2010 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Chapter 11: Structure and Union Types Problem Solving & Program Design.
Reference, primitive, call by XXX 必也正名乎 誌謝 : 部份文字取於前輩 TAHO 的文章.
What is static?. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1; this.instanceX =
NCCU System 學校信箱. Let’s start from here: 從首頁的信箱入口進入.
OAQ 的期中考 寶石奇兵 容許的排序演算法: Θ(n lg n) , ex: merge sort, quick sort, heap sort…. 排序的標準: (1) 分數愈大愈前面 (2) 時間愈短愈前面 (3) 字典排序愈小愈前面 最後再循序找名次就可以了。
Dynamic memory allocation in C and C++ 程式設計 潘仁義 CCU COMM.
Chapter 6 Modular Programming Dr. J.-Y. Pan Dept. Comm. Eng. Nat. Chung Cheng Univ.
STAT0_sampling Random Sampling  母體: Finite population & Infinity population  由一大小為 N 的有限母體中抽出一樣本數為 n 的樣 本,若每一樣本被抽出的機率是一樣的,這樣本稱 為隨機樣本 (random sample)
備份部落格資料 Zoundry 為什麼要備份部落格資料?
Lecture Note of 9/29 jinnjy. Outline Remark of “Central Concepts of Automata Theory” (Page 1 of handout) The properties of DFA, NFA,  -NFA.
程式註解說明. 2 程式註解格式 塊狀註解 對檔案、 class 、 method 、資料結構、一段程式 …. 等程式區塊 做說明。 第一行的開頭必需為 “/*” 且沒有其他文字,最後一行的開頭 必需以 “*/” 做為結束,在中間每一行的開頭都必需是一個 “*” 。 單行註解 佔據一整行的說明。 以.
Chapter 11 Structure and Union Types Instructor: Alkar / Demirer.
Introduction to Java Programming Lecture 10 Array I Declaring, Creating, and Initializing Arrays.
: Point of View in Flatland ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 11037: Point of View in Flatland 解題者:黃士庭 解題日期: 2007 年 5 月 15 日 題意:在座標平面上給三個圓,找一個點使從這.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
Outline Overloading Methods The Scope of Variables The Math Class Floating point Format [Sample code] TestMethodOverloading.java.
: Ahoy, Pirates! ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11402: Ahoy, Pirates! 解題者:李重儀 解題日期: 2008 年 8 月 26 日 題意:有一個海盜島有 N 個海盜,他們的編號 (id)
第二十一章 研究流程、論文結構        與研究範例 21-1  研究流程 21-2  論文結構 21-3  研究範例.
CS 201 Structure & Union Debzani Deb.
Java Homework 1 Requirements Define a “ Student Class ” Attributes: firstName, lastName, school, studentID, age, year, etc. Methods: getNameInfo(), getAgeInfo(),
研究資料的分析. 資料分析的基本策略  General data analysis strategies 1.Sketching ideas 2.Taking notes 3.Summarize field nores 4.Getting feedback on ideas 5.Working with.
Chapter 11 Structure and Union Types Dr. Jiung-yao Huang Dept. Comm. Eng. Nat. Chung Cheng Univ. TA: 鄭筱親 陳昱豪.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
: Problem G e-Coins ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10306: Problem G e-Coins 解題者:陳瀅文 解題日期: 2006 年 5 月 2 日 題意:給定一個正整數 S (0
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
物件導向程式 授課教師 : 王耀德 研究室 : 靜宜大學 二研 105 電話 : (04) # Web site:
845: Gas Station Numbers ★★★ 題組: Problem Set Archive with Online Judge 題號: 845: Gas Station Numbers. 解題者:張維珊 解題日期: 2006 年 2 月 題意: 將輸入的數字,經過重新排列組合或旋轉數字,得到比原先的數字大,
Introduction to Java Programming Lecture 9 Flow Control : while do-while and for loops II.
User-defined Structure Types Structures: collection of data of different types. We can define a structure type student_t : typedef struct { string name;
2 期末程式第一份報告 報告內容 撰寫此程式的動機和目的以及預期達到的功能和結果 流程圖 繼承關係 資料結構 檔案上傳格式 第 n 組程式流程圖.doc 組別於近日內公告 5/31, 17:00 前交.
組合語言與系統程式 軟體使用教學. 軟體下載及安裝 下載 到課程網頁下載 tw/~jiun/ 安裝 解壓縮後將 System Software 資料夾放在 D 槽 (C 槽版本放在 C 之下 )
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
TDBA66, Lecture Ch. 11, vt-03 1 Abstraction Prucedural abstraction moduralize by hiding the details in a function() Ex.functions in get_params(…) display_match(…)
INTRODUCTION TO MATLAB SHAWNNTOU. What Is MATLAB? MATLAB® is a high-performance language for technical computing. MATLAB® is a high-performance language.
Introduction to Java Programming Lecture 12 Method Benefits, Declaring, and Calling Methods.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
What is static? CS340100, NTHU Yoshi. Static? 靜態 ? class Test { static int staticX; int instanceX; public Test(int var1, int var2) { this.staticX = var1;
Communication Engineering National Central University Video-Audio Processing Laboratory VAP HW3 Suggestion 指導教授:張寶基 研究生:鄭玉欣 音視訊處理實驗室 2006 / 10 / 24.
C++ Control Structures 程式的控制、運算、判斷跟你之前學過的程式語言是類 似的,所以這裡我們只用程式碼來說明。 你應該而且必須能看得懂這些程式 !!
A. Abhari CPS1251 Input/Output Files, Review Text file: a named collection of characters newline, input stream, output stream This is first line. This.
 Structures are like arrays except that they allow many variables of different types grouped together under the same name. For example you can create.
Chapter 11 Structure and Union Types J. H. Wang ( 王正豪 ), Ph. D. Assistant Professor Dept. Computer Science and Information Engineering National Taipei.
Text and Binary File Processing 程式設計 潘仁義 CCU COMM.
1 Lecture10: Structures, Unions and Enumerations 11/26/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
chap11 Chapter 11 Structure and Union Types.
Problem Solving and Program Design in C Chap. 11 Structure and Union Types Chow-Sing Lin.
© 2012 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Programming application CC213 Week 08 – Struct & Unions– Chapter 10.
Introduction We will study how to broaden the modeling facilities of C by defining our own data types that represent structured collections of data pertaining.
CS1001 Programing Fundamental Lecture 12 Strings and Structured Type
Text and Binary File Processing
Structure and Union Types
Structure and Union Types
Speaker: Liu Yu-Jiun Date: 2009/4/15
Speaker: Liu Yu-Jiun Date: 2009/04/08
READING AND PRINTING MATRICES (with functions)
Dynamic memory allocation in C and C++
Chapter 10 C Structures and Unions
Chapter 11 Structure and Union Types.
Computer Science II CS132/601* Lecture #C-3.
Presentation transcript:

Structure and Union Types 程式設計 潘仁義 CCU COMM

Structure Type Definition struct structured data objects, can be defined by users #define STRSIZ 10 typedef struct { char name[STRSIZ]; double diameter; /* diameter in km */ intmoons;/* number of moons */ double orbit_time,/* years to orbit sun once */ rotation_time;/* hours to rotate once */ } planet_t; int main () { planet_tcurrent_planet, blank_planet = {“”, 0,0,0,0}; intstatus = scan_planet(&current_planet); /* 等會看 */ current_planet = get_planet(); print_planet(current_planet); …

Assigning Values to Components of Variable current_planet

Function with a Structured Input Parameter

Function Comparing Two Structured Values for Equality

Function with a Structured Output Argument 也可寫成 & plnp->diameter, &plnp->moons, & plnp->orbit_time, &plnp->rotation_time);

Data Areas of main and scan_planet during Execution of status = scan_planet (&current_planet);

Function get_planet Returning a Structured Result Type

Data Type planet_t and Basic Operations 例如 : 課本的 complex Figure 11.10

Parallel Arrays and an Array of Structures int id[50]; double gpa[50]; struct { int id; double gpa; } stulist[50];

Union types Union To deal with situations in which one needs a data object that can be interpreted in a variety of ways. typedef union { intwears_wig; /* 載假髮嗎 ?*/ charcolor[20]; } hair_t; typedef struct { intbald;/* 禿頭嗎 ?*/ hair_th; } hair_info_t;

Function That Displays a Structure with a Union Type Component

Q & A union 可以用 -> 嗎 ? struct planet_t a, b; a = b; /* 可這麼寫嗎 ? */ if(a == b) {} /* 可這麼寫嗎 ? */ (*plnp).name *plnp.name plnp->name &plnp->name 小心: union 的內容該如何解釋 ?