University of Helsinki / Dep. of Computer Science / Introduction to Programming / Copyright © 2002 Arto Wikla.

581325-0 Introduction to Programming, course examination 13.11.2002/AW

Write the name of the course, the date of the exam, your name, personal number and signature on each paper. Write each answer on a separate paper! You are allowed to use the tools of the Lue-class (or Read-class) for reading the input.

  1. Answer the following questions briefly and exactly:
                                                                (12 points)
    

  2. MinMax is a gadget for registering maximum and minimum temperature values. Temperatures are input to the gadget and the user can at any time ask the highest and the lowest temperature that MinMax has received. At the beginning of its use, MinMax sets both the values to 0.0. Also later the gadget can be reset to have zero values. The user can ask, whether MinMax is at the initial state, or if he can rely on the temperature values.

    Implement the gadget as a class MinMax, which has a constructor and the following accessors:

    Take into account: When the first temperature is registered, it is both the highest and the lowest temperature thus far.

                                                                (12 points)
    

  3. "Object? What the heck is an object? And what in the world is encapsulation?", our friend asks after listening to your stories about the course Introduction to Programming. Your friend has done a little programming, enough to know primitive variables, expressions, statements, methods and parameters, but he does not know a thing about object programming. Help your friend understand what objects are, how they are programmed and used, and why they are useful. Write an explanation (a maximum of one sheet). Please keep in mind that pictures and examples are a great help in learning. When evaluating the answer, we will take into account the intended reader, so do not write for the evaluator, who already knows about objects, but for that friend of yours!
                                                                (12 points)
    

  4. Implement the following service as an interactive program. In the mornings, the program is given character strings (String values) as input in random order. The end of a character string is announced by the input "end" as the final character. There are never more than one thousand strings. During the day, the program is often asked whether a certain character string (String value) was among the morning input. In the evening, the program is closed by the input "night". For the sake of efficiency, the search for character strings has to be programmed with a binary search
                                                                (14 points)