Data Structure Lecture 2
Data Structure Lecture 2
ALGORITHMS
Lecture 2
Object Oriented Programming
Abbreviated OOP
Inheritance
– Writing reusable code
– Objects can inherit characteristics from other objects
Polymorphism
– A single name can have multiple meanings depending on
its context
Introduction to C++
Where did C++ come from?
– Derived from the C language
– C was derived from the B language
– B was derived from the BCPL language
C++ History
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++ History
C++ developed by Bjarne Stroustrup at AT&T Bell
Labs in the 1980s.
Killed several weaknesses of C
Combined object oriented programming
C remains a subset of C++
High-level Languages
Common programming languages include …
C C++ Java Pascal Visual Basic
FORTRAN
COBOL Lisp Scheme Ada
ADD X Y Z
main() { statements }
Testing and Debugging
Bug
A mistake in a program
Debugging
Removing mistakes in programs
Program Errors
Syntax errors
Damage 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
C ++ Keywords
25
#include <iostream.h>
using namespace std;
int main()
{
cout<<"Wel come To C++!" <<endl;
system("pause");
return (0);
}
What Is a Variable
A variable/ identifier is a specific piece of memory in
your computer that consists of one or more connecting
bytes.
An identifier is the name to denote labels, types,
variables, constants or functions, in a C++ program.
C++ is a case-sensitive language.
Work is not work
Identifiers should be descriptive
Using meaningful identifiers is a good programming practice
int,char,float and double
Logical Operators
The Equality Operator ==
The Logical Not Operator !
The Comparison for a Lower Value <
Combining Equality and Lower Value <=
Boolean Variables
Using Blocks of Code in if Statements
30
switch(Expression)
{
case Choice1:
Statement1;
case Choice2:
Statement2;
case Choice-n:
Statement-n;
}
Loops
34