[Skip Navigation] [CSUSB] / [CNS] / [Comp Sci & Eng] / [R J Botting] /[CS320 Course Materials] /05a.html [05a.txt(Text)] [Search ]
Tue Apr 20 20:22:26 PDT 2010
[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


    Answers to Questions in Lecture/Discussion 5

      Question 1

      Draw a UML diagram of the following classes and associations. Class names: Student, PieceOfWork, Date, SequenceNumber, TypeOfWork. Relationships: Each student does several pieces of work. Each piece of work is done by one student on a particular date. Each piece of work is of a particular type. Each piece of work has a sequence number.

      Add multiplicities and some role names to your diagram. Suggested role names: does, doneBy, ...?

      Answer to question 1

      Question 2

    1. Draw a UML diagram of the following classes and relationships::Integer and Float are sub-types of Object. All Applets are Panels, all Panels are Containers, all Containers are Components, and all Components are Objects. Some other Components are Buttons, Lists, and TextFields. Note. This example is part of the Java "AWT".

      Answer to question 2

      What do you add to it to show that a Container can have any number of Components inside it?

      Question 3

      Draw a UML diagram that uses composition to model the following C++ class:
    2. class Wodget { public: float size; int knobs; string id; };

      Answer to question 3a

      Draw a UML diagram that uses attributes to model the following C++ class:

    3. class Wodget { public: float size; int knobs; string id; };

      Answer to question 3b

      Question 4

      Draw a UML diagram of the part of your web site that is concerned with this class. Include the following ideas: Your_Home_Page, Your_CS320_Page, Lab_Page, Source_Code_Page, WWW Pages in general.

      Answer to question 4

      (The above is non-standard!)

      Question 5

      Draw a UML diagram of a Node where: A Node is either Empty, an Atom, or a Pair. Each Pair has two pointers to nodes called the car and cdr. (This is the structure of LISP!)

      Answer to question 5

      This is a simple example of the Composite pattern. The composite pattern is in the handout. Use it in your project!

      Question 6 Minicalc

        MiniCalc has simple integer Expressions:
      1. Expression::= Constant | Operation. All expressions can be evaluated returning a number.

      2. Constant::= digit #digit. The evaluation of a constant returns its value.

      3. Operation::= Constant Operator Expression.

      4. Operations are evaluated by applying the operator to the Constant and the result of evaluating the Expression.

      5. Operator::= "+" | "-" | "*" | "/".

      6. Each operator has an apply function that takes two values and returns an int value.

        Hint: Hint for Question 6

        Answer: [ 06/ole7.gif ]

        Specifications using the Object Constraint Language

         Constant::evaluate()
              result self.value
        
        
         Operation::evaluate()
              result operator.apply( constant.evaluate(), expression.evaluate())
        
        
         Addition::apply( i:Int, j:Int)
              result i+j
        
        
         Subtraction::apply( i:Int, j:Int)
              result i-j
        
        Write, in the same format as the above, the missing
        specifications for methods.
        

        C++ Code for MiniCalc

        Have look at [ minicalc.cpp ] that is the C++ code for 6 of the above classes plus a simple set of tests. Down load and test it.

        Add and test classes for Multiplication and Division.

        If you have a lot of spare time, add a lexer and a parser.

      . . . . . . . . . ( end of section Question 6 Minicalc) <<Contents | End>>

End