CP1300 C++ Classes

(Sections 7.3, 8.1, 8.2, 8.3)
Last modified Wednesday, 20-Sep-2000 02:37:41 UTC.

Content


Self assessments


Tutorial Questions


Exam style questions

  1. Programs may be monolithic, may be organized with libraries, or may use classes.
  2. Given the following class implementation file integer_store.cpp, provide the class header file integer_store.h.
    #include "boolean.h"
    #include "integer_store.h"
    //-------------------------------------------------------------
    integer_store::integer_store(void) {
    
    Clear();
    }
    //-------------------------------------------------------------
    integer_store::integer_store(int Value) {
    
    Store(Value);
    }
    //-------------------------------------------------------------
    void integer_store::Store(int Value) {
    
    ValuedStored = TRUE;
    TheValue = Value;
    }
    //-------------------------------------------------------------
    void integer_store::Clear(void) {
    
    ValuedStored = FALSE;
    }
    //-------------------------------------------------------------
    boolean integer_store::Retrieve(int &Value) {
    
    if (ValueStored) {
        Value = TheValue;
        return(TRUE);
        }
    else return(FALSE);
    }
    //-------------------------------------------------------------
    
  3. In the context of Object Oriented Programming, explain how the following are implemented in C++:
  4. Write the header and implementation file for a class that stores a person's name as their first name initial and complete family name. Include a default constructor that initializes the name to J. Citizen, an initial value constructor, and a member function that writes out the name.