Page 171 - DCAP404 _Object Oriented Programming
P. 171

Object-oriented Programming




                    Notes          You should get the following output.
                                   Stock Details-stock1-type
                                   code 101
                                   Items 10

                                   Price per item `125
                                   Stock value
                                   1250
                                   Stock Details-stock2-type

                                   code 10 1
                                   Total Value `1250

                                   Self Assessment

                                   Fill in the blanks:
                                   14.  Typecasting is making a variable of one type,  such as an int,  act like another type,  a
                                       ………………….. , for one single operation.
                                   15.  One special case of  implicit  type  conversion is  type  promotion,  where the  compiler
                                       automatically  expands the  …………………….. representation  of  objects  of  integer  or
                                       floating-point types.

                                     


                                     Caselet     Learn to Think Like the Computer Thinks

                                           o learn to program a computer you need to learn to think like the computer thinks,
                                           advises Jim Messinger in Starting Out With  Programming Logic & Design,  and
                                     Tintroduces readers first to friendly definitions of terms such as variable, constant,
                                     pseudocode, counter and so on.
                                     Thus, you’d learn that ‘flag’ is related to flagging of data. It is similar to flagging in car
                                     races where the flag tells you to take a specific action, explains Messinger.

                                     “In a computer, the flag is on when it is 1 and off when it is zero. In car races, there are a
                                     variety of flags: yellow, white, checkered, and so on. Each of these could be represented in
                                     a computer by an appropriately named variable and could be set to 0 or 1 to indicate to the
                                     computer program the state of the car race.”
                                     Again, when  explaining modules as collections of related  tasks, the author uses  the
                                     automotive example:  “Think of  a car  as a  program. Its modules could be the engine,
                                     transmission, and body.” Remember that modules can become complex, which is when
                                     you need sub-modules, such as “fuel system, ignition system, and exhaust system” for the
                                     engine.
                                     With Lord Falkland’s quote - “When it not necessary to make a decision, it is necessary not
                                     to make a decision” - begins a chapter on `selection logic’. If you’re familiar with flowchart
                                     symbols, you may know selection as what you do when a `diamond’ is encountered.
                                                                                                         Contd...




          164                               LOVELY PROFESSIONAL UNIVERSITY
   166   167   168   169   170   171   172   173   174   175   176