Fundamentals of OOP
Rizoan Toufiq1
1 Assistant Professor
Department of Computer Science & Engineering
Rajshahi University of Engineering & Technology
rizoantoufiq@yahoo.com
Course Title: Object Oriented Programming
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 1 / 26
Overview
1 Object Oriented Programming
2 Introduction to C++
Origins of the C++ Language
A Sample C++ Program
Layout of a Simple C++ Program
Compiling and Running a C++ Program
3 Testing and Debugging
Kind of Program Errors
4 Resources
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 2 / 26
Object Oriented Programming
Abbreviated OOP
Used for many modern programs
Program is viewed as interacting objects
Each object contains algorithms to describe its behavior
Program design phase involves designing objects and their algorithms
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 3 / 26
Characteristics of OOP
Encapsulation
Information hiding
Objects contain their own data and algorithms
Inheritance
Writing reusable code
Objects can inherit characteristics from other objects
Polymorphism
A single name can have multiple meanings depending on its context
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 4 / 26
Overview
1 Object Oriented Programming
2 Introduction to C++
Origins of the C++ Language
A Sample C++ Program
Layout of a Simple C++ Program
Compiling and Running a C++ Program
3 Testing and Debugging
Kind of Program Errors
4 Resources
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 5 / 26
Origins of the C++ Language
Where did C++ come from?
Derived from the C language
C was derived from the B language
B was derived from the BCPL(Basic Combined Programming
Language)
Why the ‘++’ ?
++ is an operator in C++
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 6 / 26
Origins of the C++ Language
C developed by Dennis Ritchie at AT&T Bell Labs in the 1970s.
Used to maintain UNIX systems
Many commercial applications written in c
C++ developed by Bjarne Stroustrup at AT&T Bell Labs in the
1980s.
Overcame several shortcomings of C
Incorporated object oriented programming
C remains a subset of C++
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 7 / 26
Overview
1 Object Oriented Programming
2 Introduction to C++
Origins of the C++ Language
A Sample C++ Program
Layout of a Simple C++ Program
Compiling and Running a C++ Program
3 Testing and Debugging
Kind of Program Errors
4 Resources
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 8 / 26
A Sample C++ Program
#include <iostream>
using namespace std;
int main( )
{
int number;
cout << "Press return after entering a number.\n";
cout << "Enter the number:\n";
cin >> number;
number = number + number;
cout << number;
return 0;
}
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 9 / 26
A Sample C++ Program
Example (Sample Output:)
Press return after entering a number.
Enter the number:
10
20
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 10 / 26
A Sample C++ Program
A simple C++ program begins this way
And ends this way
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 11 / 26
A Sample C++ Program
Program statement
using namespace std;
Tells the compiler to use names in iostream in a ”standard” way.
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 12 / 26
A Sample C++ Program
Variable declaration line
int number;
Identifies names of three variables to name numbers
int means that the variables represent integers
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 13 / 26
A Sample C++ Program
Program statement
cout<< "Press return after entering a number.\n";
cout (see-out) used for output to the monitor
’\n’ causes a new line to be started on the monitor
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 14 / 26
A Sample C++ Program
Program statement
cin >> number;
cin (see-in) used for input from the keyboard
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 15 / 26
A Sample C++ Program
Program statement
number = number+ number;
Performs a computation
’+’ is used for multiplication
’=’ causes number to get a new value based on the calculation shown
on the right of the equal sign
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 16 / 26
A Sample C++ Program
Program statement
cout << number;
Sends the value of variable number to the monitor
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 17 / 26
Overview
1 Object Oriented Programming
2 Introduction to C++
Origins of the C++ Language
A Sample C++ Program
Layout of a Simple C++ Program
Compiling and Running a C++ Program
3 Testing and Debugging
Kind of Program Errors
4 Resources
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 18 / 26
Layout of a Simple C++ Program
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 19 / 26
Overview
1 Object Oriented Programming
2 Introduction to C++
Origins of the C++ Language
A Sample C++ Program
Layout of a Simple C++ Program
Compiling and Running a C++ Program
3 Testing and Debugging
Kind of Program Errors
4 Resources
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 20 / 26
Compiling and Running a C++ Program
#include <iostream>
using namespace std;
int main( )
{
cout << "Testing 1, 2, 3\n";
return 0;
}
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 21 / 26
Testing and Debugging
Bug
A mistake in a program
Debugging
Eliminating mistakes in programs
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 22 / 26
Overview
1 Object Oriented Programming
2 Introduction to C++
Origins of the C++ Language
A Sample C++ Program
Layout of a Simple C++ Program
Compiling and Running a C++ Program
3 Testing and Debugging
Kind of Program Errors
4 Resources
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 23 / 26
Kind of Program Errors
Syntax errors
Violation of the grammar rules of the language
Discovered by the compiler
Error messages may not always show correct location of errors
Run-time errors
Error conditions detected by the computer at run-time
Logic errors
Errors in the program’s algorithm
Most difficult to diagnose
Computer does not recognize an error
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 24 / 26
Resources
Walter Savitch
Problem Solving with C++
Herbert Schildt
Teach Yourself C++
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 25 / 26
The End
Rizoan Toufiq (Assistant Prof.,CSE,RUET) Fundamentals of OOP 26 / 26