Data Types Copyright © 2006 Patrick McDermott College of Alameda
Fact CRC Cards : (Attribute) ERD : Attribute Relational : Attribute Database : Column Programmer : Variable UML : Property Etc., etc., etc. …: Field, Item, Element
The Rules C++ Allowed/Forbidden characters –Letters, Numerals, _ –NO Spaces Break_character: Underscore _ –No initial numeral Length, Very Long Case SeNsItiVe Cannot be a Keyword (Keywords are Reserved Words) Nouns for Variables/Classes Verbs for Functions/Methods
The Rules Java Allowed/Forbidden characters –Letters, Numerals, $, _ –NO Spaces Break_character: Underscore _ –No initial numeral Length, Very Long Case SeNsItiVe Cannot be a Keyword (Keywords are Reserved Words) Nouns for Variables/Classes Verbs for Functions/Methods
Numbers, Text & Truth Numbers –int or double Text –char or string –C#: char is 2 bytes in C++ wchar_t Booleans –Logical: true or false. We might not have beauty, but it does have truth. Decimal (.NET) –± $792,281,625,142,643,375,935,439,503.35m –± 79,228,162,514,264,337,593,543,950,335M
2 Kinds of Numbers Integers int A counting number A whole number Discrete No fraction No decimal Floating Point float, but use double A measuring number A fractional number Continuous Fraction Decimal 2½, , too!
Numbers Integers: 4 billion –2,147,483,648 to +2,147,483, billion if unsigned Not enough bils for Bill’s fortune Double-Precision Floating-Point: double –Range: Big enough You can enumerate all the atoms in the Universe. –Precision: at least 15 decimal digits Just enough for $Trillion to the cent. $1,234,567,890, Not quite enough for a credit card number
I Declare! String s; String s = "Hi"; int x = 0; double x, y; int x = 0, y = 1; final int MYNUMBER = 0; The Unchanging const ant ALLUPPERCASE or ALL_UPPER_CASE
I Declare! string s; string s = "Hi"; int x = 0; double x, y; int x = 0, y = 1; const int MYNUMBER = 0; The Unchanging const ant ALLUPPERCASE or ALL_UPPER_CASE extern int SOMEWHERE_NOT_HERE; In compliment extern, ’tis not long after But I will wear my heart upon my sleeve—Iago, Otello I.1.
Number versus Character Sort As numbers, one & two & three are binary 1 and 10 and 11. As text, 1 & 2 & 3 are ASCII characters 49 & 50 & 51. Numbers sort by value. Text sorts character by character. You can be richer than Bill Gates! As text, $9 is greater than $80,000,000,000! So, just keep $9, and sort net worth as text!
Precision Values of type float have seven digits of precision. Values of type double have digits of precision. Values of type decimal are represented as integer values that are scaled by a power of 10. Values between -1.0 and 1.0 are represented exactly to 28 digits.
Size not Standard Each computer system is different. Types are based on the system Word. We are on a 32-bit (4-byte) system, So int is a word (4 bytes), double is 2 words (8 bytes)… TypeSize char, unsigned char, signed char 1 byte short, unsigned short 2 bytes int, unsigned int 4 bytes long, unsigned long 4 bytes float 4 bytes double 8 bytes long double 8 bytes
The incredible Growing int Windows 3.11 (and earlier) The 16-bit Windows A 2-byte system word Windows 95 (and later) The 32-bit Windows A 4-byte system DWord C Standard for int : The short must not be longer than the int The long must not be shorter than the int short int long short int long Windows 7 & Java (and later) The 64-bit Windows A 8-byte system QWord short int long
Alphanumeric Text String s Single character or a string of characters? 'a' is the single character known as a "a" is a character string consisting of the letter a A C string is actually a null-terminated array It needs a space for the null (binary zeroes) "a" is 2 characters long: a + null lpsz “long pointer to a null-terminated string” [yuck!] String Theory Strings have been a sore point, with me & others Unnecessarily overcomplicated What were they thinking???