[Skip Navigation] [CSUSB] / [CNS] / [CSE] / [R J Botting] / [CSci202] / lab04
[Text Version] [Syllabus] [Schedule] [Glossary] [Resources] [Grading] [Contact] [Question] [Search ]
Notes: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20]
Labs: [01] [02] [03] [04] [05] [06] [07] [08] [09] [10]
Tue Apr 19 08:33:39 PDT 2011

Contents


    CSci202 Laboratory 04 Classes


      (previous): See [ lab03.html ] + Problem [ lab02bad.cpp ] + Four of my solutions: [ lab02string.cpp ] (use C++ 'string' type) [ lab02get.cpp ] [ lab02get2.cpp ] (input one character at a time and discard the extra ones) [ lab02getline.cpp ] (use getline... and tidy up extra input if needed).

      Check out the Latest News

      [ http://cse.csusb.edu/dick/cs202/ ]

      Problem

      Arrays are efficient but dangerous to use. It is wise to wrap up a dangerous data structure inside a class. We hide the data by making it private. We have only a few safe operations that make public. Anything which might be abused is private. So we forbid the dangerous operations and only allow the safe ones.

      We use assert to protect our safe operations from abuse.

      We provide the user with a safe Application Programmer Interface -- -- --(API)

      We also provide common constructors and operators that application programmers expect.

      Goals

      By the end of the lab you should know more about coding classes that include common constructors and operators.

      Deliverables Due at end of Lab Period

      A working program that uses a safe 8 character Buffer class that does the useful things of the lab02 program but does not permit the abuse possible in lab02.

      Givens

      Here [ lab04main.cpp ] is a program that is designed to test a new safe Buffer class. Download a copy of this.

      The safe buffer was defined in a file called buffer04.h. It worked until I deleted some functions header lines from the function definitions and replaced them by

       		// DELETED
      Here is the result [ buffer04.h ] Download this "header" file.

      Your task is to use the book, the compiler, your brain, and my advice to replace the DELETED lines until it compiles and runs.

      Do not change the main program. Do not change anything but the DELETED lines in the .h file.

      Overloading operators

      The buffer04.h file defines special meanings for the operators <<, >>, ==, []. You can find out more about this elegant technique in section 14.1 of our text. All you need for today is to know that
    1. operator== is the name of a function that does the operation "=="!

      Disclaimer

      There are things that still need improving in these two files. Do not do these. We will tackle them in later labs.

      If you have time at the end of the lab, work on your next project.

      Next Lab -- Inheritance and Polymorphism

      In [ lab05.html ] you will add new features to a program, one step at a time, by deriving new classes from given classes.

    . . . . . . . . . ( end of section CSci202 Laboratory 04 Classes) <<Contents | End>>

    Glossary

  1. accessor::=`A Function that accesses information in an object with out changing the object in any visible way". In C++ this is called a "const function". In the UML it is called a query.
  2. Algorithm::=A precise description of a series of steps to attain a goal, [ Algorithm ] (Wikipedia).
  3. class::="A description of a set of similar objects that have similar data plus the functions needed to manipulate the data".
  4. constructor::="A Function in a class that creates new objects in the class".
  5. Data_Structure::=A small data base.
  6. destructor::=`A Function that is called when an object is destroyed".
  7. Function::programming=A selfcontained and named piece of program that knows how to do something.
  8. Gnu::="Gnu's Not Unix", a long running open source project that supplies a very popular and free C++ compiler.
  9. mutator::="A Function that changes an object".
  10. object::="A little bit of knowledge -- some data and some know how". An object is instance of a class.
  11. objects::=plural of object.
  12. OOP::="Object-Oriented Programming", Current paradigm for programming.
  13. Semantics::=Rules determining the meaning of correct statements in a language.
  14. SP::="Structured Programming", a previous paradigm for programming.
  15. STL::="The standard C++ library of classes and functions" -- also called the "Standard Template Library" because many of the classes and functions will work with any kind of data.
  16. Syntax::=The rules determining the correctness and structure of statements in a language, grammar.
  17. Q::software="A program I wrote to make software easier to develop",
  18. TBA::="To Be Announced", something I should do.
  19. TBD::="To Be Done", something you have to do.
  20. UML::="Unified Modeling Language".
  21. void::C++Keyword="Indicates a function that has no return".

End