Structure and User-Define Type struct tag {members;…;} variable; typedef old_type new_type;

Slides:



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

指標 Pointers.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
Introduction to Java Programming Lecture 13 Classes I OO Programming.
“Rule” By OX. By Check CREATE TABLE 員工薪資 ( 編號 int IDENTITY PRIMARY KEY, 薪資 smallmoney, CHECK ( 薪資 > 0 AND 薪資
邏輯設計 題目:3_8解碼器 姓名:李國豪 學號:B09322001.
建立靜態資料成員 關鍵字: static 靜態資料成員不屬於特定物件,而是該類物件 所共同擁有的,可做為類別範圍裡的靜態變數。
第一章 變數、常數及資料型態. 變數 C 程式語言的變數名稱 第一個字必須是英文字母或底線 (_) 之後可以是數字, 英文字母或底線 (_) 不可以是保留字 例: Num (Ο) _score (Ο) C&C (X) 8num (X)
1 連續系統與 離散系統之比較 指導教授 : 陳正宗 終身特聘教授 報告 : 吳建鋒 日期 :2015年6月12日星期五 2015年6月12日星期五 2015年6月12日星期五 2015年6月12日星期五 2015年6月12日星期五 2015年6月12日星期五.
Multidimensional Array Outline Two-Dimensional Arrays Lengths of Two-Dimensional Arrays Multidimension Arrays [Sample code]
第 4 章 迴歸的同步推論與其他主題.
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
Canonical Correlation 典型相關 目標 1 – 決定兩組變數 ( 對相同事務的衡量 ) 是否獨立, 或決定這兩組變數之間關係的強度 –Example: Y1+Y2+…+Ym=X1+X2+…Xn ( 一般式 ) Y1, Y2,…Ym 是否與 X1, X2,..,Xn 有相關 / 無相關.
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
1 CH 13- 規格、公差與可靠度  一定性、不一定性和可靠性  誤差、常態分配和品質規格  組合公差.
Department of Air-conditioning and Refrigeration Engineering/ National Taipei University of Technology 模糊控制設計使用 MATLAB 李達生.
1 The PVT Equation of States 體積狀態方程式. 2 相律 相律; The Gibbs Phase rule 相律; The Gibbs Phase rule 相律與狀態變數 相律與狀態變數 科學研究儀器的發展 科學研究儀器的發展.
VHDL 邏輯設計 題目:一對十六解多工器 題目:一對十六解多工器 姓名:李國豪 姓名:李國豪 學號:B09322001 學號:B09322001.
1 Chemical and Engineering Thermodynamics Chapter 8 Phase equilibrium in mixtures Parts B : Illustration Sandler.
民意調查的分析 II 蔡佳泓 政大選舉研究中心 副研究員. 課程大綱 假設的檢定 研究假設 H1: 研究假設 ( 例: X 與 Y 相關 ) H0: 虛無假設 ( 例: X 與 Y 無關 ) 檢定結果:接受虛無假設或拒斥虛無假 設,但不代表接受研究假設.
變異數分析 檢定 類型 One Way ANOVA Two way ANOVA Three way ANOVA ..five..
資料結構實習-四.
1 第十三章 Pascal 程式語言 陳維魁 博士 儒林圖書公司.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
Introduction to pointers in C/C++. Pointers 特殊變數 存放變數在記憶體中的位址 MinGW C++ 中佔用 4 bytes 間接定址取執法 位址 指標變數 變數內容 變數.
第九章 結構. 結構的宣告 結構 它是由許多不同 ( 或相同 ) 資料型態的變數所組成的 集合,通常利用結構標籤稱呼此集合 struct student { char *name; int score; }; struct 為保留字,表示結構的宣告開始 結構項目需定義於大括號「 { } 」內 結尾需加上分號.
VB2005 DataBase Manipulation Command for Access. 引用類別定義 Imports System.Data.OleDb Imports System.Data.SqlClient Imports System.Data.Odbc Imports System.
最新計算機概論 第 5 章 系統程式. 5-1 系統程式的類型 作業系統 (OS) : 介於電腦硬體與 應用軟體之間的 程式,除了提供 執行應用軟體的 環境,還負責分 配系統資源。
Introduction to Java Programming Lecture 10 Array I Declaring, Creating, and Initializing Arrays.
Hung-Hsiang WuWindows Processing Design1 Chapter 3 基本觀念 變數宣告與型態 特殊運算子符號 字串與數值的轉換 類別與物件的觀念 建立新的專案 WinMain 程式進入點 Include Header File.
Department of Air-conditioning and Refrigeration Engineering/ National Taipei University of Technology MATLAB 操作與 系統動態模擬 SIMULINK 李達生.
 Prentice Hall Chapter 81 組織設計.  Prentice Hall Chapter 82 學習目標 了解組織結構的六項特徵 比較機械式與有機式的組織設計 解釋造成結構差異的四項權變性變數 解釋環境的不確定性如何影響組織結構.
Introduction to C Language ─ C 語言資料型態. 大綱 常數與變數 整數資料型態與變數宣告 浮點數資料型態與變數宣告 字元資料型態與變數宣告 資料的大小 Homework.
Fugacity Coefficient and Fugacity
生物統計學 期中報告 組員 : 醫放一 A 王小明 醫放一 A 王小明 醫放一 A 王大明 醫放一 A 王大明 2009/04/14.
Analysis of Variance (ANOVA) CH 13 變異數分析. What is ANOVA? n 檢定 3 個或 3 個以上的母體平均數是否相等的統計檢定 n 檢定多個母體平均數是否相同 n 比較大二、大三、大四學生實習滿意度是否一樣 ? ( 來 自相同的 population)
教材名稱:網際網路安全之技術及其應用 (編號: 41 ) 計畫主持人:胡毓忠 副教授 聯絡電話: 教材網址: 執行單位: 政治大學資訊科學系.
資訊教育 東海大學物理系施奇廷 92 學年度第一學期. 物理研究的新方法 傳統:理論與實驗 傳統:理論與實驗 現在:理論、實驗、計算 現在:理論、實驗、計算 計算 vs. 實驗:計算物理可視為在所有的條 件皆能完美調控之下的「數值實驗室」 計算 vs. 實驗:計算物理可視為在所有的條 件皆能完美調控之下的「數值實驗室」
第六章 陣列.
資訊教育 吳桂光 東海大學物理系助理教授 Tel: 3467 Office: ST223 Office hour: Mon (10:30-12am) or by appointment.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
A[0] a[1] pa ???? *pa ppa *ppa Address:4 byte Double:8 byte.
Pointer and Array 指標 與 陣列 double *a, b[10]; char name[80], *np;
校園網頁整合平台介紹 電算中心綜合業務組. 大綱 設計理念 功能介紹 實做 FAQ 特殊案例 Q&A.
資訊教育 吳桂光 東海大學物理系助理教授 Tel: 3467 Office: ST223 Office hour: Tue, Fri. (10-11am)
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
結構力學總複習 Review of Structural Mechanics
5 重複迴圈 5.1 增減運算符號 增量運算符號 減量運算符號
SQL 進階查詢.
3 數學運算 3.1 鍵盤輸入 鍵盤輸入 輸入函數 cin 輸入函數 cin 多重輸入 cin 多重輸入 cin 輸出格式化 輸出格式化 設定輸出長度 setw.
Introduction to Java Programming Lecture 8 Flow Control : while do-while and for loops.
Ch 3 Central Tendency 中央集中趨勢測量.
Miscellanea Switch Bitwise operations ?,. break; continue; (example) (example) do { a = getc(stdin); if (a=='q') break; else if (a=='c') continue; n++;
Visual C++重點複習.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2008.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2010.
C 語言練習題 2010/12/2. C 程式的格式 一、 C 程式的格式 (1). /* …. */ 是 C 程式的 ______ main() 的內容是由敘述構成的 (2). 敘述要以 __ 為結束符號 (3). 變數、函數都要做 ____ 的宣告 (4). ‘=’ 是 ____ 用的算符 (5).
Mapping - 1 Mapping From ER Model to Relational DB.
第 1 章 PC 的基本構造. 本章提要 PC 系統簡介 80x86 系列 CPU 及其暫存器群 記憶體: Memory 80x86 的分節式記憶體管理 80x86 的 I/O 結構 學習組合語言的基本工具.
Chapter 12 Estimation 統計估計. Inferential statistics Parametric statistics 母數統計 ( 母體為常態或 大樣本 ) 假設檢定 hypothesis testing  對有關母體參數的假設,利用樣本資料,決定接受或 不接受該假設的方法.
VHDL語法(3).
McGraw-Hill/Irwin © 2003 The McGraw-Hill Companies, Inc.,All Rights Reserved. 肆 資料分析與表達.
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.
STRUCTURE 為一種複合式的資料型態,可用來把相關的資料組織 成為有意義的資料單元。 名片: name age tel namecard : char name[10]; int age; char tel[10] char [60]
Data Types Always data types will decide which type of information we are storing into variables In C programming language we are having 3 types of basic.
C++ 程式語言. 2 C++ 程式語言 – 大綱 1. 指標 2. 結構與類別 3. 標準函式庫 (STL)
Arrays Chap 8. 2 Without Array If you want to create Lottery winning numbers… –You need 7 variables (6 for winning numbers and 1 for the special number)
1 Chapter 11 – File Processing Outline 11.1Introduction 11.2The Data Hierarchy 11.3Files and Streams 11.4Creating a Sequential Access File 11.5Reading.
Structures In C Programming By Rajanikanth B.
Isolated Word Recognition
Presentation transcript:

Structure and User-Define Type struct tag {members;…;} variable; typedef old_type new_type;

Structures 結構變數 Syntax: struct type_id { type1 variable1; type2 variable2; …} varible1,..; struct type_id variable1, variable2;

Memory layout 計憶體的配置 int a; double b; struct {int n; double x;} ss; 4 bytes8 bytes &a &b 4 bytes8 bytes &ss.n &ss.x &ss

Structure members (example) 結構變數之成員example struct item_record { unsigned int number; float price; } pen, book; pen.number = 10; pen.price = 13.5; book.number = 5; book.price = 590.5; total = pen.price * pen.number + book.price * book.number; struct item_record notebook; notebook.price = 60,4; notebook.number = 20; total = total + notebook.price * notebook.number;

User-Type Define (example)example 自定新的變數型態 Syntax: ( 語法 ) typedef old_type_name new_type_name; typedef unsigned int Uint; typedef struct struct_type new_type_name;

ExampleExample 2. 將相關變數集合為一變數結構 typedef struct { char name[80]; unsigned long int id; float t1, t2, t3, avg;} Student; Student sss; // Student 為一新的變數型態 sss.name // name of student. 姓名 sss.id // id number. 學號 sss.t1 // score of first test. 成績 …. sss.avg // average over t1, t2, and t3 平均

While Loop 用 while 控制迴圈 (1) while (condition) { …; …..; …..; } (2) do { …; …; …; …; } while (condition); char a; printf(“Press q to quit”;) fflush(stdin); do { a = getc(stdin); } while (a != ‘q’); sum = 0; n = 0; while (n <= 10) { sum = sum + n; n++; }

File input: getc(file_pointer) 從檔案中讀取一個字元 Symbol represents the file pointer of Keyboard: stdin : standard input device, defined within stdio.h getc(stdin) : read a single character from keyboard.

直角座標 與 球座標 轉換 ex4ex4 typedef struct { double x, y, z;} Cartesian; typedef struct { double r, t, p;} Spherical; Cartesian v1; Spherical v2; v2.r = sqrt(v1.x*v1.x + v1.y*v1.y+v1.z*v1.z); v2.t = acos(v1.z / v2.r); v2.p = atan(v1.y / v1.x);

Practice 2. 增加 expval(x) 的可用範圍 A double variable can represent a value < ~ exp(709) exp(800) = #INF 超出 double 的範圍 Problem : How to increase the applicable range of our previous program?

Numerical Scheme 選擇 a = ln(10) = 選擇 n 使 y=(x – na), 0 <= y < ln(10)

Flow Chart of the Scheme Call myexp(x) myexp(x) nq = (int)floor(x / LN10) y = x – nq *LN10 Input x Output result expval(y) Set n = 30 Do Taylor series In reverse order return expval(y), nq return sum main mytype myexp() double expval()

Pratice 5. Another root searching Using Netwon’s method find the root of Write the function and its derivative within a same subroutine, And return these values in a two-double structure.

details struct two_double { double x; double y;}; typedef struct two_double twodim; twodim funct(double x) { twodim fdf; ……. fdf.x = ??; fdf.y = ??; return fdf; } int main() { twodim ff; …. do { … ff = funct(x); delta = ff.x / ff.y; } …… }

Related usages or functions #include double floor(double a) ; // return the largest integer that smaller than a. typedef struct {double x; int n} MyType; For example : floor(2.34) = 2.00, floor(-3.48) = MyType myexp(x) { MyType ttt; ……; …..; ttt.n = nq; ttt.x = expval(y); return ttt; }

Project 3. 計算二次方程的根 設計一程式 1. 寫一函數讀取系數 a, b, c. 回傳主程式. 2. 將系數傳到令一函數計算兩複數根. 3. 將兩複數根傳回主程式 4. 再傳到另一副程式列印結果.

自定新變數格式 1. Quardratic typedef struct {double a, b, c;} Quardratic; 2. Complex typedef struct {double x; double y;} Complex; 3. TwoComplex typedef struct { Complex r1; Complex r2; } TwoComplex;

functions 1. 讀取系數, 並回傳到主程式 Quadratic inputcoef(void); 2. 給與系數計算兩根 TwoComplex findroots(Quadratic coef); 3. 列印 void printroots(TwoComplex root);

Techniques -- input Quadratic inputcoef(void) { double a, b, c; Quadratic coef; …. 讀入 a, b, c… coef.a = a; coef.b = b; coef.c = c; return coef; }

Output viod printroots (TwoComplex twor) { printf(“root1 = (%.10lf, %.10lf)\n”, twor.r1.x, twor.r2.y); ……… return; }

#include typedef struct {double a, b, c;} Quadratic; typedef struct {double x, y;} Complex; typedef struct {Complex r1, r2;} TwoComplex; Quadratic inputcoef(void); TwoComplex findroots(Quadratic); void printroots(TwoComplex); int main() { Quadratic coefs; TwoComplex roots; coefs = inputcoef(); roots = findroots(coefs); printroots(roots); system("pause"); return 0; } Main and prepocessors 輸入系數 解根 列印

findroot(Quadratic cf) 判別式 crit = b*b – 4*a*c crit >= 0.0 ? crit = sqrt(crit) root1.x = (-b+crit) / (2a) root2.x = (-b-crit) / (2a) root1.y = root2.y = 0.0; crit = sqrt(-crit) root1.x = root2.x = (-b) / (2a) root1.y = crit / (2a) root2.y = (-crit) / (2a); root.r1 = root1; root.r2 = root2; return root; yes no Complex root1, root2; TwoComplex root; a  cf.a b  cf.b c  cf.c