Introduction to Data Structures and Software Engineering

CS1704 : Summer Session II 2000 : Midterm 1

Question One [20]

  1. List two reasons why we study data structures. [5]
  2. Eliminate size boundaries of fixed-size variables
    More efficient data access techniques

  3. List one advantage and one disadvantage of programming with modules. [5]
  4. Advantage: smaller compilation units => less time for recompilation during debugging
    Disadvantage: hard to keep track of large number of files

  5. List two advantages of object-oriented programming. [5]
  6. Objects are a closer model of the real world so it is easier to convert real-world solutions to computer programs
    Encapsulation and data hiding reduces complexity

  7. Dynamic variables still require a small amount of static storage space. What is this used for? [5]
  8. This space is required to store the address of the memory associated with the dynamic variable

Question Two [20]

Match the following terms with the most appropriate descriptions:

5000 modules, software engineering, design specification, function prototype, #ifdef, global variable definition, constructor, overloading, pointer variable, dereferencing


_ #ifdef ________________ avoid multiple inclusions of one header file
_ pointer variable ______ memory allocated at compile-time for address only
_ global variable defn __ .CPP file
_ software engineering __ problem, design, program, maintain
_ overloading ___________ set of similar functions
_ constructor ___________ automatic function
_ dereferencing _________ getting from an address to the actual data
_ 5000 modules __________ high cost of integration
_ design specification __ structure chart
_ function prototype ____ header file

Question Three [40]

  1. What is a class ? [4]
  2. A class is a data type definition/declaration for an object.

  3. When is a constructor called? What is it usually used for? [6]
  4. It is called when an object is created. It is usually used to initialize the object.

  5. Does a constructor return a value? Why or why not? [6]
  6. No. The constructor is called automatically by the compiler, which would not know what to do with a returned value.

  7. Write out non-inline definitions for all the functions contained within the following class declaration for an OOP model of a planet. SetRadius sets the radius of the planet and GetRadius returns that value. There is a constructor to set initial values and a member function (GetVolume) to compute the object’s volume. The formula to calculate volume from radius is Volume = 4/3 Pi Radius3. [20]
  8. const float Pi = 3.14159265359;
    
    class Planet
    {
    private:
       double Radius;
    public:
       void SetRadius ( double aValue );
       double GetRadius ();
       double GetVolume ();
       Planet ( double aValue );
    };
    

    void Planet::SetRadius ( double aValue )
    {
       Radius = aValue;
    }
    
    double Planet::GetRadius ()
    {
       return Radius;
    }
    
    double Planet::GetVolume ()
    {
       return Pi * Radius * Radius * Radius * 4 / 3;
    }
    
    Planet::Planet ( double aValue )
    {
       SetRadius (aValue);
    }
    

  9. In the previous question, we could have used an inline function for SetRadius. How does the compiler handle inline functions differently? [4]
  10. The compiler replaces every call to the function with the (compiled equivalent of the) actual body of the function.

Question Four [20]

Consider the following structure chart for a small program:

  1. Does A ever call E directly? [2]
  2. No

  3. Does A ever call B directly? [2]
  4. Yes

  5. Is it possible for C and F to be in the same module? [2]
  6. Yes

  7. Is it possible for D and F to be in the same module? [2]
  8. Yes

  9. Is K an input or output variable? [2]
  10. Output

  11. Is K a data or control variable? [2]
  12. Data

  13. What type of function is R? [2]
  14. System call

  15. List 3 errors (or inconsistencies) in the structure chart. [6]