Test II, CSCI 230, Spring 2016


  1. Abstract Data Type
    1. [2 points] Define Abstract Data Type
    2. [3 points] Is char an abstract data type? Justify your answer.
  2. Arrays
    1. [2 points] What is an array?
    2. [2 points] Give the syntax to declare an array. State any restrictions.
    3. [1 point] Give the code to declare an array of 25 integers.
    4. [2 points] Give a code fragment which will initialize all elements of this array to be 99.
    5. [5 points] Give a code segment that finds the maximum and minimum values in an array of ARY_SIZE integers.
  3. Array Index
    1. [2 points] What is an out of bounds array index?
    2. [2 points] What is the result of an out of f bounds array index error?
    3. [2 points] What entity is responsible for assuring that out of bounds array index errors do not occur?
  4. Arrays as parameters
    1. [2 points] Describe how arrays are passed as parameters in C/C++.
    2. [2 points] Why are arrays passed in this manner?
  5. Classes
    1. [4 points] Describe two common programming problems addressed by classes. Name/describe the mechanism that classes in C++ use to overcome these problems.
    2. [2 points] What data is automatically available to a class member function?
    3. [2 points] How can client code change private data within a class?
  6. Class Design
    1. [2 points] When would a programmer use a class instead of a struct? When would a struct be appropriate?
    2. [3 points] How does a programmer decide which member functions to implement for a class?
  7. Class Implementation (Please read the entire problem before beginning)

    For this problem, you will implement a class which contains the geometric object square. A square is a polygon with four sides of equal length and all angles are 90 degrees. The length of a side must be at least 0. The program to use your class will need to compute the perimeter (P) and area (A) of the square. If l is the length of a side, P = 4l and A = l2

    1. [2 points] Define the Square ADT.
    2. [3 points] Give the code to define the SquareT class (as in a header file).
    3. [3 points] Give the code to implement the SquareT class (as in a source code file)
    4. [2 points] Give code to declare an instance of the class SquareT, assign a value to the side, and print out the area and parimiter. This code should not perform computations directly, that should be done by the SquareT class.