[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] /[CS320 Course Materials] /07.html [07.txt(Text)] [Search ]
Fri Apr 20 10:17:43 PDT 2012
[Schedule] [Syllabi] [Text] [Labs] [Projects] [Resources] [Grading] [Contact]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]

Contents


    CS320/07 Data Types and Data Structures


      Table
      Prev06 NamesChapter 5lab06 C/C++ Scoping
      Today** Project Phase 1 UML of old+Proposed changes(10 pts)
      Today07 Data TypesChapter 6lab07 C/C++ Data
      Next08 Expressions etcChapter 7 not section 8lab08 C/C++ Expressions

      (Close Table)

      Project Phase 1 Due in at start of class

      [ projects.html#Project Phase 1 due class 07 ]

      Preparation

      1. Study chapter 6 together with the notes on UML below.

      2. Answer review questions at end of chapter 6 .

      3. Hand in 2 or more answers to review questions.

      Notes

      Standard C++ comes with a large library (the STL) of powerful data types.

      CSCI 330 (Data Structures) is an in depth study of this material.

      Decimal Data Types

      Decimal data is a very important data type becuase it is used to represent money. Accountants require precise decimal arithmetic -- to avoid fraud. So, floating point is not an option. Integers don't capture the typical currencies division into
      1. dollars and cents
      2. pounds and pence
      3. francs and centime

      Only COBOL let's describe money as a decimal fraction and also as two decimal integers: the dollars and the cents.

      Integer arithmetic using binary can also break the rules of accountancy. For example taking an annual salary of $10,000 and representing it as an integer 10000, and dividing it by 12 to get the monthly salary means you get 833 per months.... or $9996 total -- and your employee could pocket $4. Most countries specify rules that pay more in some months and less in others so that the total is correct and each month is close to the mathematical division.

      UML and Data Types

      The UML has four primitive data types: Real, Integer, Boolean, String. These are actually defined in the Object Constraint Language or OCL [ ../samples/ocl.html ] for details.

      Enumerations in the UML (6.4.1) are shown as a class with stereotype

       		<<enumeration>>
      and with the values listed as attributes. In the OCL they are written:
         enum{ value1, value2, ...}
      Their values are written
                 #Value1, #Value2, ...
      in the OCL.

      In place of array types (6.5) we have multiplicities(0..*, 4..5, ...). Put them on attributes in square brackets and links.

       		grade[30]:Grade
      There are also special OCL types: Collection, Set, Bag, and Sequence.

      Record types (6.7) are UML classes with no operations and all attributes public. Composition is a good way to show fields in a record.

      Fields in a Record

      Unions (6.8) are best treated by generalizations and multiple inheritance.

      Pointers (6.9) have no special UML type. Do not use "*" to indicate pointers in the UML! The aggregation link is the old way for saying that one type of data has a pointer that refers to an object of another type. Make sure that (1) the name of the pointer is the role, (2) there is an arrow head, and (3) the multiplicity is 0..1. However, aggregation is not really intended to model pointers. Modern UML users just use an association with an arrow to show a pointer.

      Using Aggregation to model pointers Using Association to model pointers

      Chapter 6 in the UML

      Concepts in Chapter 6

      Class Work

      [ 07q.html ]

    Lab Work

    [ lab/07.html ]

    Next: Expressions

    [ 08.html ]

End