notes-classes - Creating a Class in C+ LAST MODIFIED 1/7/03...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Creating a Class in C++ LAST MODIFIED 1/7/03 Opening Note This presentation is a "how-to" that presents the technical aspects of creating the classes, i.e. how to express them in C++ code. It doesn't extensively cover theory (although I'm constructing some notes on OO theory for those who are curious), nor does it define what a class is. Before you read this presentation, you should be familiar with the concept of what a class is and the dot notation. The PowerPoints that I will be using to teach the segue way into classes are linked here: Intro to Classes via the C++ String Class (11/18/02) Using Classes and Working with Class Interfaces (11/20/02) Creating Classes - Part 1 (11/22/02) Creating Classes - Part 2 (11/25/02) Exercises are written generically -- you could choose to implement any of the classes noted at the bottom. In class, we'll work with the library book problem for the exercises. Introduction Class Interface Member Functions OO,Pre/Post, Comments Implementation File Function Implementation UIs UNIX Practice Introduction Every time you create a C++ program in which you use classes, you'll need to create three files. Assuming we're defining a generic class called class , here are those three files: class.h - This file is the class interface. It's where you'll define your class, its data members, and its member functions. It must have the same name as the class itself. class.cpp - This file is the class implementation. It provides implementations for each of the member functions. It must have the same name as the class itself (the same filename as the .h file, just with a .cpp extension). testDriver.cpp - This file can have any name. It is the test driver or the user interface, and it must contain the main() function. It's the program you run, the user interface. It's not really part of the class; it just creates members of the class, operates on them, and communicates with the user. Exercise 1. Create a class interface , e.g. a .h file, for your class. The filename should be what you will name your class, or an abbreviation of it. 2. Create a implementation file for your class. It should have the same name as the .h file, but with a .cpp extension.
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. Create a C++ File for the user interface/test driver. Call it whatever you want. 4. At the top of each file, start the usual block of descriptive comments. [For future reference, notes on how to set up classes in Visual C++ ] Introduction • Class Interface Member Functions OO,Pre/Post, Comments Implementation File Function Implementation UIs UNIX Practice The Class Interface -- class.h The class interface defines the class, that is, What data members make up the class? What member functions are necessary to manipulate those data members?
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 02/10/2011.

Page1 / 24

notes-classes - Creating a Class in C+ LAST MODIFIED 1/7/03...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online