Derived Class. Derived class and Base class class base_class1 { …..}; class base_calss2 { …..}; class derived_class : public base_class1, public base_class2.

Slides:



Advertisements
Similar presentations
Installment 7 Tables With No Column Presented by rexmen 2001 資管所.林彥廷.
Advertisements

Introduction to Computers - 3 rd exam- 授課教授:李錫智. 1.Consider the following program: Magic 8-ball function GetResponse()
Fundamentals of Management ESSENTIAL CONCEPTS AND APPLICATIONS -- Stephen P. Robbins & David A. Decenzo 主講人:張德儀 銘傳大學管理學院
Introduction to Java Programming Lecture 13 Classes I OO Programming.
建立使用案例敘述 --Use Case Narrative
: A-Sequence 星級 : ★★☆☆☆ 題組: Online-judge.uva.es PROBLEM SET Volume CIX 題號: Problem D : A-Sequence 解題者:薛祖淵 解題日期: 2006 年 2 月 21 日 題意:一開始先輸入一個.
:Word Morphing ★★☆☆☆ 題組: Problem Set Archive with Online Judge 題號: 10508:word morphing 解題者:楊家豪 解題日期: 2006 年 5 月 21 日 題意: 第一行給你兩個正整數, 第一個代表下面會出現幾個字串,
: Determine it 星等:★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 10520: Determine it 解題者:林祺光 解題日期: 2006 年 5 月 22 日 題意:給兩個值 a 1,n 和 n a i,j.
1 Secure Context-sensitive Authorization 2005 Author : Kazuhiro Minami, David Kotz Presented by Shih Yu Chen.
: OPENING DOORS ? 題組: Problem Set Archive with Online Judge 題號: 10606: OPENING DOORS 解題者:侯沛彣 解題日期: 2006 年 6 月 11 日 題意: - 某間學校有 N 個學生,每個學生都有自己的衣物櫃.
Chapter 2 聯立線性方程式與矩陣 緒言 線性方程式組 (systems of linear equations) 出現 在多數線性模式 (linear model) 中。根據以往解 題的經驗,讀者們也許已發現方程式的解僅與 該方程式的係數有關,求解的過程也僅與係數 的運算有關,只要係數間的相關位置不改變,
第 13 章 常數、靜態成員與朋友關 係 13-1 常數物件與成員 13-1 常數物件與成員 13-2 物件成員與巢狀類別 13-2 物件成員與巢狀類別 13-3 靜態成員資料與函數 13-3 靜態成員資料與函數 13-4 朋友關係 13-4 朋友關係.
1. 假設以下的敘述為一未提供 “ 捷徑計算 ” 能力的程式段,試用程 式設計的技巧,使此敘述經此改 寫的動作後,具有與 “ 捷徑計算 ” 之 處理方法相同之處理模式。 if and then E1 else E2 endif.
例外處理. 內 容 大 綱 例外的產生 捕捉例外 丟出例外 例外的產生 (1/4) 一般常見的執行時期錯誤包括整數除法分母為 0(divide by zero) ,陣列索引值越限 (array index out of range) ,輸入輸出錯誤 (I/O error) 、檔案 不存在或無法存取.
1 Introduction to Java Programming Lecture 7 Flow Control : Boolean expressions and the if statement.
JAVA 程式設計與資料結構 第十四章 Linked List. Introduction Linked List 的結構就是將物件排成一列, 有點像是 Array ,但是我們卻無法直接經 由 index 得到其中的物件 在 Linked List 中,每一個點我們稱之為 node ,第一個 node.
MATLAB 程式設計 第 11 章 多維陣列 多維陣列的定義 在 MATLAB 的資料型態中,向量可視為 一維陣列,矩陣可視二維陣列,對於維 度 (Dimensions) 超過 1 的陣列則均可視 為「多維陣列」 (Multidimesional Arrays , 簡稱 N-D Arrays)
8.1 何謂高度平衡二元搜尋樹 8.2 高度平衡二元搜尋樹的加入 8.3 高度平衡二元搜尋樹的刪除
Introduction to Java Programming Lecture 5: Using Java Classes : String & Math Spring 2009.
Introduction to pointers in C/C++. Pointers 特殊變數 存放變數在記憶體中的位址 MinGW C++ 中佔用 4 bytes 間接定址取執法 位址 指標變數 變數內容 變數.
Introduction to Java Programming Lecture 17 Abstract Classes & Interfaces.
1 第十四章 職業道德 職業道德是一個人在行業工作內表現的道德 情操. 2 職業道德貴在實踐 3 學習目標  了解職業道德的意義  了解職業道得的重要性  遵守職業道德規範.
: The largest Clique ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11324: The largest Clique 解題者:李重儀 解題日期: 2008 年 11 月 24 日 題意: 簡單來說,給你一個 directed.
Introduction to Java Programming Lecture 10 Array I Declaring, Creating, and Initializing Arrays.
Chapter 20 塑模動態觀點:狀態圖 Statechart Diagram. 學習目標  說明狀態圖的目的  定義狀態圖的基本記號  展示狀態圖的建構  定義活動、內部事件及遞延事件的狀態 圖記號.
1 Contents Introduction A Simple Compiler Scanning – Theory and Practice Grammars and Parsing LL(1) Parsing Lex and yacc LR Parsing Semantic Processing.
: Happy Number ★ ? 題組: Problem Set Archive with Online Judge 題號: 10591: Happy Number 解題者:陳瀅文 解題日期: 2006 年 6 月 6 日 題意:判斷一個正整數 N 是否為 Happy Number.
選舉制度、政府結構與政 黨體系 Cox (1997) Electoral institutions, cleavage strucuters, and the number of parties.
Monte Carlo Simulation Part.1 Dept. Phys., Tunghai Univ. Numerical Methods, C. T. Shih.
: Playing War ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11061: Playing War 解題者:陳盈村 解題日期: 2008 年 3 月 14 日 題意:在此遊戲中,有一類玩家一旦開始攻擊, 就會不停攻擊同一對手,直到全滅對方或無法再.
: Count DePrimes ★★★★☆ 題組: Contest Archive with Online Judge 題號: 11408: Count DePrimes 解題者:李育賢 解題日期: 2008 年 9 月 2 日 題意: 題目會給你二個數字 a,b( 2 ≦ a ≦ 5,000,000,a.
Fugacity Coefficient and Fugacity
: Multisets and Sequences ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11023: Multisets and Sequences 解題者:葉貫中 解題日期: 2007 年 4 月 24 日 題意:在這個題目中,我們要定義.
1-6 動畫的文件屬性 舞台是動畫實際播放的畫面, 所以舞台的大 小與長寬比例對將來動畫的呈現有很大的 影響。 Flash 預設的舞台尺寸是 550 Pixels × 400 Pixels, 背景為白色, 如果要更改舞台大小與 背景色, 請執行『修改 / 文件』命令, 開啟文 件屬性 (Document.
:Nuts for nuts..Nuts for nuts.. ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 10944:Nuts for nuts.. 解題者:楊家豪 解題日期: 2006 年 2 月 題意: 給定兩個正整數 x,y.
第五章 基本的組織設計 現代管理學 林建煌編譯.
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2008.
: Beautiful Numbers ★★★★☆ 題組: Problem Set Archive with Online Judge 題號: 11472: Beautiful Numbers 解題者:邱經達 解題日期: 2011 年 5 月 5 日 題意: 若一個 N 進位的數用到該.
: 05-2 Rendezvous ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11015: 05-2 Rendezvous 解題者:池明洋 解題日期: 2006 年 4 月 16 日 題意: 給 node N 個 , edge.
Section 4.2 Probability Models 機率模式. 由實驗看機率 實驗前先列出所有可能的實驗結果。 – 擲銅板:正面或反面。 – 擲骰子: 1~6 點。 – 擲骰子兩顆: (1,1),(1,2),(1,3),… 等 36 種。 決定每一個可能的實驗結果發生機率。 – 實驗後所有的實驗結果整理得到。
JAVA 程式設計與資料結構 第二十章 Searching. Sequential Searching Sequential Searching 是最簡單的一種搜尋法,此演 算法可應用在 Array 或是 Linked List 此等資料結構。 Sequential Searching 的 worst-case.
資料結構實習-二.
: Automatic correction of misspellings ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11048: Automatic correction of misspellings 解題者:陳宜佐 解題日期:
Chapter 10 m-way 搜尋樹與B-Tree
人工智慧 第八章 模糊關係及推論 王榮華教授.
: Function Overloading ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11032:Function Overloading 解題者:許智祺 解題日期: 2007 年 5 月 8 日 題意:判對輸入之數字是否為.
1 523: Minimum Transport Cost ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 523: Minimum Transport Cost 解題者:林祺光 解題日期: 2006 年 6 月 12 日 題意:計算兩個城市之間最小的運輸成本,運輸.
Inheritance and Polymorphism
1 Introduction to Java Programming Lecture 2: Basics of Java Programming Spring 2009.
: Sum-up the Primes ★★★★☆ 題組: Problem A 題號: 10419: Sum-up the Primes 解題者:林一帆 解題日期: 2006 年 5 月 15 日 題意: 評斷一個給予的數字是否是由給予個數 的質數所組成的.
1 中期產能規劃. 2 3 ä 產能規劃 3 滿足優序計畫(即決定產品生產順序和生產時 機)之產能需求量的程序和獲取足夠可用產能 的方法。 3 如果產能不足以完成優序計畫,則該優序計畫 必須變更。 產能規劃.
ArcINFO &Geodatabase 由 ESRI 產生 1970 ArcINFO 一開始被設計在迷你電 腦上, 後來逐漸發展, 在 UNIX 系統上也能 執行, 直到今天, 已經可以在不同的平台上 運作.
INTRODUCTION TO MATLAB SHAWNNTOU. What Is MATLAB? MATLAB® is a high-performance language for technical computing. MATLAB® is a high-performance language.
C++ Overview 1999 amendment to c99 C with class. Important concepts of C++  Function overload: different function using same function name.  Enhance.
:Commandos ★★★☆☆ 題組: Contest Archive with Online Judge 題號: 11463: Commandos 解題者:李重儀 解題日期: 2008 年 8 月 11 日 題意: 題目會給你一個敵營區內總共的建築物數,以及建築物 之間可以互通的路有哪些,並給你起點的建築物和終點.
論文閱讀報告 論文題目:應用模糊理論於颱風降雨量之推估 作者:陳正彬. 模糊化類神經網路 ‧模糊系統的建立 1. 由人類專家建立規則 ex:if 風速大 then 降雨量高 效果受到規則庫完整的影響 2. 經由訓練法則從數值資料得到模糊規則.
函式 Function 東海大學物理系‧資訊教育 施奇廷. 函式簡介 當程式越來越大、越複雜時,程式的維護、 除錯會變得更困難,此時必須引入函式來 簡化程式或將程式分段,將程式重複的部 分改寫為函式,將程式「模組化」 這種作法有下列優點:節省程式發展的時 間、邏輯容易瞭解、程式容易除錯、可分 工合作完成程式.
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.
: Construct the wall maze ★★★★★ 題組: Problem Set Archive with Online Judge 題號: 11050: Construct the wall maze 解題者:宋柏儀 解題日期: 2007 年 6 月 12 日.
Microsoft Excel.
幼兒行為觀察與記錄 第八章 事件取樣法.
1 Introduction to Java Programming Lecture 3 Mathematical Operators Spring 2009.
VHDL語法(3).
: How many 0's? ★★★☆☆ 題組: Problem Set Archive with Online Judge 題號: 11038: How many 0’s? 解題者:楊鵬宇 解題日期: 2007 年 5 月 15 日 題意:寫下題目給的 m 與 n(m
主讲人 主讲人:彭泽洲 一. 预备知识 1. 已知 OP 为角  的终边,求单位圆上点 P 的坐标。 P 2 ( x 2,y 2 ) P 1 ( x 1,y 1 ) 2. 坐标系中两点的距离公式 Y X P O X Y  P ( COS  , SIN  ) |P 1 P 2 |=√(x 1.
RPL: IPv6 Routing Protocol for Low power and Lossy Networks
Chapter 14 Templates (樣板) Chapter 14 Templates (樣板)
「社會學動動腦」 授課人:苗延威 本週主題 「社會」在哪裡?.
Presentation transcript:

Derived Class

Derived class and Base class class base_class1 { …..}; class base_calss2 { …..}; class derived_class : public base_class1, public base_class2 { double x, y, z; // constructors derived_class (double r1, double r1, double r3) : base_class1(r1, r2), base_class2(r3); } ;

Properties of a derived class 1.Derived class 擁有 base class 的所有 members 和 member functions. 2. 在建構 derived class 的 constructor 時, 也必須賦予 base class 的建 構規則. 3.Derived class 可以經由 base class 的運算符作 + - * = 等運算. 例如 : dsqMatrix aMtx(n, xarray); dcoVector cVct(n, yarray); droVector rVct(n, yaary); cout << (aMtx*cVct) ; // print (1 x n) matrix; cout << (rVct*Amtx); // print (n x 1) matrix // 運算 aMtx * cVct 是藉由 Matrix(n, n) * Matrix(n, 1) 的規則進行. // 運算 rVct * aMtx 是藉由 Matrix(1, n) * Matrix(n, n) 的規則進行. // cout 也是經由 Matrix 的 overload 進行.

Class Matrix General (n x m) matrix Column Vectors Row vectors Square (nxn) Matrix Hermitian Matrix Define maritrx +,-,* Operations & transport

Class gnrMatrix Class gnrMatrix template class gnrMatrix { protected: int n_row, n_col; XTP *a_mtx; public: // constructors ….. }

Better structure dgrMatrix : (n x m) real matrix And operators cgrMatrix: (n x m) complex matrix And operators Operators between cgrMatrix and dgrMatrix cspmatrix.h csqMatrix : (n x n) complex matrix croVector : (1 x n) complex vector ccoVector : (n x 1) complex vector dspmatrix.h dsqMatrix : (n x n) real matrix droVector : (1 x n) real vector dcoVector : (n x 1) real vector base class derived class

Class dgrMatrix Class dgrMatrix class dgrMatrix { protected: int n_row; int n_col; double* a_mtx; public: ….; } Test program

constructors dgrMatrix() {}; dgrMatrix(const int, const int); dgrMatrix(const int, const int, double*); dgrMatrix(const int, const int, const double); dgrMatrix(const dgrMatrix &); // copy constructor ~dgrMatrix() {delete [] a_mtx;};

Member functions void put (const int i, const int j, const double x) ; void put (const int i, const double x); double get (const int i, const int j) const; double get (const int i) const; double &pos (const int i, const int j) {return this->a_mtx[i*n_col+j];} int ncol () const; int nrow () const; int ndim () const; dgrMatrix transport () const; void print (int) const; double norm () const; double abs () const; dgrMatrix unit () const; dgrMatrix getrow (const int) const; dgrMatrix getcol (const int) const; void putrow (const int, double*); void putcol (const int, double*); double* getarray () const;

i/o stream overload ostream &operator<<(ostream &ous, dgrMatrix mtx) { int i, j, w=8; cout << " row = " << mtx.nrow() << " col = " << mtx.ncol() << "\n"; for (i=0; i<mtx.nrow(); i++) { for (j=0; j<mtx.ncol(); j++) cout << setw(w) << mtx.get(i,j); cout << "\n"; } return ous; } ifstream &operator>>(ifstream &ins, dgrMatrix &mtx) { int i, j; for (i=0; i<mtx.nrow(); i++) { for (j=0; j > mtx.pos(i,j) ; } return ins; }

operators friend class cgrMatrix; dgrMatrix operator- (const dgrMatrix &); dgrMatrix operator+ (const dgrMatrix &, const dgrMatrix &); dgrMatrix operator- (const dgrMatrix &, const dgrMatrix &); dgrMatrix operator* (const double, const dgrMatrix &); dgrMatrix operator* (const dgrMatrix &s, const double x); dgrMatrix operator* (const dgrMatrix &, const dgrMatrix &);

Complex Matrix Complex Matrix class cgrMatrix { protected: int n_row; int n_col; complex *a_mtx; public: ……; } Test code

constructors cgrMatrix() {}; cgrMatrix(const int, const int); cgrMatrix(const int, const int, complex *); cgrMatrix(const int, const int, double *); cgrMatrix(const int, const int, const complex ); cgrMatrix(const int, const int, const double ); cgrMatrix(const cgrMatrix &mx); cgrMatrix(const dgrMatrix &mx);

operators cgrMatrix & operator=(const cgrMatrix &); cgrMatrix & operator=(const dgrMatrix & mx); cgrMatrix operator- (const cgrMatrix &); cgrMatrix operator+ (const cgrMatrix &, const cgrMatrix &); cgrMatrix operator- (const cgrMatrix &, const cgrMatrix &); cgrMatrix operator* (const complex &, const cgrMatrix &); cgrMatrix operator* (const cgrMatrix &, const cgrMatrix &); cgrMatrix operator+ (const dgrMatrix &x1, const cgrMatrix &x2); cgrMatrix operator+ (const cgrMatrix &x1, const dgrMatrix &x2); cgrMatrix operator- (const dgrMatrix &x1, const cgrMatrix &x2); cgrMatrix operator- (const cgrMatrix &x1, const dgrMatrix &x2); cgrMatrix operator* (const double &r, const cgrMatrix &mx); cgrMatrix operator* (const cgrMatrix &mx, const double &r); cgrMatrix operator* (const cgrMatrix &mx, const complex &r); cgrMatrix operator* (const dgrMatrix &m1, const cgrMatrix &m2); cgrMatrix operator* (const cgrMatrix &m1, const dgrMatrix &m2);

dspmatrix.h: real special matrices dspmatrix.h: real special matrices 1.Class dsqMatrix: real square matrix (n x n) 2.Class droVector: real row vector (1 x n) 3.Class dcoVector: real column vector (n x 1).

Class dsqMatrix class dsqMatrix : public dgrMatrix { public: dsqMatrix() : dgrMatrix() {}; dsqMatrix(const int n) : dgrMatrix(n, n){}; dsqMatrix(const int n, const double x) : dgrMatrix(n, n, x){}; dsqMatrix(const int n, double *xpt) : dgrMatrix(n, n, xpt) {}; dsqMatrix(const dsqMatrix &sqx) : dgrMatrix(sqx.nrow(), sqx.ncol(), sqx.getarray()){}; dsqMatrix(const dgrMatrix &grx); // memeber functions double trace() const; // 對角線元素的和 dsqmatrix diagonal() const; // 抽取對角線元素.. };

Class dcoVector class droVector : public dgrMatrix { public: droVector():dgrMatrix(){}; droVector(int n):dgrMatrix(1, n){}; droVector(int n, double x) : dgrMatrix(1, n, x){}; droVector(int n, double *xpt) : dgrMatrix(1, n, xpt){}; droVector(const dgrMatrix &mtx); };

Class dcoVector class dcoVector : public dgrMatrix { public: dcoVector():dgrMatrix(){}; dcoVector(int n):dgrMatrix(n, 1){}; dcoVector(int n, double x) : dgrMatrix(n, 1, x){}; dcoVector(int n, double *xpt) : dgrMatrix(n, 1, xpt){}; dcoVector(const dgrMatrix &mtx); };

cspmatrix: complex special matrix cspmatrix: complex special matrix 1.Class csqMatrix: complex square matrix (n x n) 2.Class croVector: complex row vector (1 x n) 3.Class ccoVector: complex column vector (n x 1).

Class csqMatrix class csqMatrix : public cgrMatrix { public: csqMatrix() : cgrMatrix() {}; csqMatrix(const int n) : cgrMatrix(n, n){}; csqMatrix(const int n, const double x) : cgrMatrix(n, n, x){}; csqMatrix(const int n, const complex x) : cgrMatrix(n, n, x){}; csqMatrix(const int n, double *xpt) : cgrMatrix(n, n, xpt) {}; csqMatrix(const int n, complex *xpt) : cgrMatrix(n, n, xpt) {}; csqMatrix(const dsqMatrix &sqx) : cgrMatrix(sqx.nrow(), sqx.ncol(), sqx.getarray()){}; csqMatrix(const csqMatrix &sqx) : cgrMatrix(sqx.nrow(), sqx.ncol(), sqx.getarray()){}; csqMatrix(const cgrMatrix &); csqMatrix(const dgrMatrix &); // memeber functions complex trace() const; };

Class croVector class croVector : public cgrMatrix { public: croVector():cgrMatrix(){}; croVector(int n):cgrMatrix(1, n){}; croVector(int n, double x) : cgrMatrix(1, n, x){}; croVector(int n, complex x) : cgrMatrix(1, n, x){}; croVector(int n, double *xpt) : cgrMatrix(1, n, xpt){}; croVector(int n, complex *xpt) : cgrMatrix(1, n, xpt){}; croVector(const cgrMatrix &); croVector(const dgrMatrix &); };

Class ccoVector class ccoVector : public cgrMatrix { public: ccoVector():cgrMatrix(){}; ccoVector(int n):cgrMatrix(n, 1){}; ccoVector(int n, double x) : cgrMatrix(n, 1, x){}; ccoVector(int n, complex x) : cgrMatrix(n, 1, x){}; ccoVector(int n, double *xpt) : cgrMatrix(n, 1, xpt){}; ccoVector(int n, complex *xpt) : cgrMatrix(n, 1, xpt){}; ccoVector(const cgrMatrix &); ccoVector(const dgrMatrix &); };

Write your classes for the test code to run … test codetest code // testing headfile cspmatrix.h & dspmatrix.h #include "cspmatrix.h" #include "dspmatrix.h" main() { int i, j; double aary[16]; complex cary[16]; for (i=0; i<16; i++) aary[i] = i ; for (i=0; i (i-8.123, i); dsqMatrix dmtx(4, aary); csqMatrix cmtx(4, cary); ………

Final works -- using matrix classes using iterative method solving 10 linear equations in ttdsp2.txtttdsp2.txt A * X = B (A0 + A1) * X = B separate A into large (diagonal part) A0 and smaller A1. A0 * X = B - A1 * X X = (1/A0 * B) - (1/A0 * A1) *X where 1/A0 is the inverse of A0. Let vector V = (1/A0) * B, and matrix M = (1/A0) * A1 Using iterative method, starting with an arbitray X1 X2 = V - M * X1, then replace X1 = X2. Do these processes iteratively until | X2 - X1 | < tolerance. (Practically you may mix X1 and X2 for better convergence.)

Data file ttdsp2.txt for Eq. A x = b ttdsp2.txt Line 1 : matrix dimension, number of rows and columns. Line 2 -10: matrix elements of A (10 x 10) Line 11 : vector B (1 x 10)

1. read dimension n, m from file ttdsp2.txt 2. build a square matrix amtx, and column vector bvct objects with dimension n (m=n). 3. provide member function in base class dgrMatrix to read a matrix from the file. 4. provide member function in dsqMatrix to extract the diaginal element as an (n x n) square Matrix -- A0 5. substract A0 from amtx to get A1: A1 = amtx - A0 6. inverse the diagonal elements of A0 ==> 1 / A0 7. Multiply A1 with 1/A0: A2 = 1/A0 * A1. 8. Multiply bvct with 1/AO : dvct = 1/A0 * bvct. 9. Start with XX2 = column vector of all element = 1, and a empty XX1 (provide memeber function of this effect.) 10. XX1 = XX XX2 = dvct - A2 * XX repeat step until | XX2 - XX1 | < tolerance (1.0E-6) 13. Check the answer, compare bvct with amtx*XX2. Mission: Make your classes definition work with my main programmain program

This concludes our course. Thank you for your attention.