Welcome
Welcome
CSCI 3233.01
Object-Oriented Design and Programming
• Mon. and Wed., 6:00–8:29 p.m.
Instructor: Charles Moen
• Email – crmoen@juno.com
• Web page – http://sce.cl.uh.edu/moenc/
• Office – Delta Building 232
• Office hours – Mon. and Wed. 5:30–6 and 8:30–9 p.m.
– Phone me at (281) 283-3848 so that I can open the hall door.
• Home – (713) 880-2924
1
CSCI 3233
Today’s Objectives
Class roster
Course introduction
• Required text, web site, syllabus, schedule
• How to succeed
Brief facts about C++ and object-oriented programming
Using C++ Compilers at UHCL – Microsoft Visual Studio
Introduction to C++ programming (Ch. 1 and Ch. 2)
• A simple example
• Arithmetic operators, equality operators, relational operators
Introduction to classes and objects (Ch. 3)
• Data members and member functions
• Example: the GradeBook class
Next class – Intro to UML (Ch. 1) and Control Structures
3
Course Introduction
4
Course Introduction
Required Textbook
Course page
http://sce.cl.uh.edu/moenc/csci3233summer06/index.html
Schedule
http://sce.cl.uh.edu/moenc/csci3233summer06/schedule.html
Syllabus
http://sce.cl.uh.edu/moenc/csci3233summer06/syllabus.html
Resources
http://sce.cl.uh.edu/moenc/csci3233summer06/resources.html
6
Course Introduction
How to Succeed
Bonus Labs
Optional guided lab assignment
• At least 5 scheduled during the semester
• During regular class time, but at the end of the period
• Simple assignments that will give you some hands-on C++ experience
Procedure
• First, a demo by the instructor
• Then you will complete the assignment on your own
• Print it and hand it in before the end of class
Rules
• Do your own work, but you may help each other
• You may ask the instructor for help
• You may leave if you finish early or if you do not wish to do this
assignment
1 bonus point added to a quiz grade for each lab correctly
completed and handed in before the end of class
8
C++ and
Object-Oriented Programming
9
C++ and Object-Oriented Programming (Deitel; Randell; Wirth)
Historical Perspective
Structured Programming
Object-Oriented Programming
Object-Oriented Programming
Some advantages
• Easy to understand and develop because the objects directly
model real-world elements
• Faster development
• Easier to maintain
• Object-oriented software is easier to reuse
Object-based programming
• Class – program element that contains both data and the
functions that manipulate it
• Object –instance of a class (like a “variable”)
Object-oriented programming
• Inheritance
• Polymorphism
13
C++ and Object-Oriented Programming (Deitel; Josuttis)
Evolved from C
Designed and implemented by Bjarne Stroustrup
at the Bell Labs in the early 1980s
“C with classes”
Standardized by ISO in 1997
• Includes the C++ standard library
• Standard Template Library (STL)
– Part of the C++ standard library
– Readymade classes for data structures and algorithms
14
Using C++ Compilers at UHCL
15
Using C++ Compilers at UHCL
Compilers
http://sce.cl.uh.edu/moenc/usingMSVS.html
17
Introduction to
C++ Programming
18
Introduction to C++ Programming (Deitel)
A Simple Example
Another Example
Chapter 3
24
Introduction to Classes and Objects (Deitel, 76)
Class
25
Introduction to Classes and Objects (Deitel, 77–99)
Declaring a Class
Name
class GradeBook{
public:
GradeBook(string name="CSCI 3233");
void setCourseName(string name); Member functions
string getCourseName(); (also called
void displayMessage(); operations)
private:
string courseName; Data Member
};
Remember the ‘;’ !
27
Introduction to Classes and Objects (Deitel, 96)
Access Specifiers
Access specifier All members after
class GradeBook{ “public:” are accessible
public: by any user in your
GradeBook(string name="CSCI 3233"); program wherever there
void setCourseName(string name); is an object of this class.
string getCourseName();
void displayMessage();
All members after
private: Access specifier “private:” are only
string courseName;
accessible to the member
};
functions of this class.
Class members are private
by default.
28
Introduction to Classes and Objects (Deitel, 76)
Information Hiding
Encapsulation
class GradeBook{
public:
GradeBook(string name="CSCI 3233"){
setCourseName(name);
}
void setCourseName(string name){
courseName = name;
}
string getCourseName(){
return courseName;
}
void displayMessage(){
cout << "GradeBook for " << getCourseName() << endl;
}
private:
string courseName;
33
};
Introduction to Classes and Objects (Deitel, 95)
Separating
the Class from main()
In C++, this is the normal approach
• The class declaration and definition goes in a header
file (GradeBook.h)
• A preprocessor directive includes it in the cpp file
#include "GradeBook.h"
Advantage
• Reusability – if the GradeBook class is in its own file,
it can be used in any program where we need it, just
by “including it”
Not required – it is legal to put the class in the
same file as main()
34
Introduction to Classes and Objects (Deitel, 80)
Constructor
GradeBook(string name){
setCourseName(name);
}
36
Introduction to Classes and Objects (Deitel, 103)
#include <iostream>
#include "GradeBook.h"
using namespace std;
int main(){
GradeBook myFirstGradeBook;
cout << "GradeBook created for "
<< myFirstGradeBook.getCourseName() << endl;