资源描述
*,*,*,按一下以編輯母片標題樣式,按一下以編輯母片,第二層,第三層,第四層,第五層,Programming Language(,程式語言,),Chapter 6,Data Types(,資料型態,),Topics,Introduction,Primitive data types(,基本資料型態,),Character string types(,符號字串型態,),User-defined ordinal types(,使用者定義順序型態,),Array types(,陣列型態,),Associative arrays(,關聯陣列,),Record types(,紀錄型態,),Union types(,聯合型態,),Pointer and reference types(,指標與參考型態,),2,Introduction,Data type defines,A collection of data objects and a set of predefined operations on those objects,一群資料物件與再這物件上被預先定義運算集合,3,Primitive Data Types,Almost all programming languages provide a set of,primitive data types,Primitive data types,Those not defined in terms of other data types,沒有被定義再其他的資料型態中,Some primitive data types are merely(,只是,)reflections(,反映,)of the hardware,Integer type,Others require(,需要,)only a little non-hardware,4,Integer,The most common privative numeric(,數字的,)data type is integer,Javas signed integer sizes,byte,short,int,long,C+and C#include unsigned integer types,Unsigned types are often used for binary data,5,Floating Point,Model real numbers,but only as approximations(,近似值,),Languages for scientific(,科學,)use support at least two floating-point types,Float,and,double,IEEE Floating-Point,Standard 754,6,IEEE Standard 754 Floating-Point,(,單精確度,),(,倍精確度、雙精確度,),7,Decimal(10,進位,),For business applications(money),Essential(,基本,)to COBOL,C#offers a decimal data type,Store a fixed number of decimal digits,Advantage,Accuracy(,準確,),Disadvantages,Limited range(,有限的範圍,),Wastes memory(,消耗記憶體,),8,Boolean,Simplest(,最簡單,)of all,Range of values:two elements,True,False,Could be implemented as bits,but often as bytes,Advantage,Readability,9,Character(,字元,),Stored as numeric(,數值,),codings,Most commonly used coding:ASCII,An alternative,16-bit coding:Unicode,Includes characters from most natural languages,Originally used in Java,C#and JavaScript also support Unicode,10,Character String Types,Values are sequences of characters,Design issues,Should strings be simply a special kind of character array or a primitive type?,Should strings have static or dynamic length?,11,Character String Types Operations,Typical operations,Assignment,and copying,Comparison(=,etc.),Catenation(,串接,),Substring reference(,子字串參考,),Pattern matching(,樣式匹配,),12,Character String Type in Certain Languages,C and C+,Not primitive(,基本,),Use,char,arrays and a library of functions that provide operations,Java,Primitive via the,String,class,13,Character String Length Options,Static,Javas,String,class,Limited dynamic length,C and C+,In C-based language,a special character is used to indicate the end of a strings characters,rather than maintaining(,維持,)the length,Dynamic(no maximum),Perl,JavaScript,Ada supports all three string length options,14,Character String Implementation,Static length,Compile-time descriptor,Limited dynamic length,May need a run-time descriptor for length(but not in C and C+),Dynamic length,Need run-time descriptor;allocation/de-allocation is the biggest implementation problem,15,Compile-and Run-Time Descriptors,Compile-time descriptor for static strings,Run-time descriptor for limited dynamic strings,16,Ordinal Types,An ordinal type is one in which the range of possible values can be easily associated(,組合,)with the set of positive integers(,正整數,),Examples of primitive ordinal types in Java,integer,char,boolean,17,User-Defined Ordinal Types,In some language,users can define two kinds of ordinal type,Enumeration(,列舉,),Subrange,(,子範圍,),18,Enumeration Types,All possible values,which are named(,被命名,)constants(,常數,),are provided in the definition,C#example,enum,days,mon,tue,wed,thu,fri,sat,sun;,Design issues,Are enumeration values coerced(,強制,)to integer?,Any other type coerced to an enumeration type?,19,Subrange Types,An ordered contiguous(,連續,)subsequence of an ordinal type,Example:12.18 is a subrange of integer type,Pascal,Ada,Adas design,type Days is(mon,tue,wed,thu,fri,sat,sun);,subtype Weekdays is Days range mon.fri;,subtype Index is Integer range 1.100;,Day1:Days;,Day2:Weekday;,Day2:=Day1;,20,Implementation of User-Defined Ordinal Types,Enumeration types are implemented as integers,Subrange,types are implemented like the parent types with code inserted(by the compiler)to restrict(,限制,)assignments to,subrange,variables,21,Array Types,An array is a homogeneous(,同質,)aggregate(,集合體,)of data elements(,元素,)in which an individual(,單獨的,)element is identified by its position in the aggregate,relative(,相對,)to the first element,一個陣列是一個同質的資料元素集合體,那個獨立的元素,(,指陣列,),表示集合體的位置,相對於第一個元素,22,Array Indexing,Indexing(or subscripting)is a mapping from indices(,索引,)to elements,array_name(index_value_list),an element,Index Syntax,FORTRAN,PL/I,Ada use parentheses(,圓括號,),(),Most other languages use brackets(,方括號,),23,Arrays Index(Subscript)Types,FORTRAN,C,Java,Integer only,Pascal,Any ordinal type(integer,Boolean,char,enumeration),Ada,Integer or enumeration(includes Boolean and char),C,C+,Perl,and Fortran do not specify,range checking,Java,ML,C#specify range checking,24,Subscript Binding and
展开阅读全文