SlideShare a Scribd company logo
1
CSE 459.22
Programming in C++
2
Overview
• Sign roster list
• Syllabus and Course Policies
• Introduction to C++
• About Lab 1
• Fill Questionnaire
3
Introduction to C++
• Programming Concept
• Basic C++
• C++ Extension from C
4
Focus
• Focus on
– Programming Concepts
– Programming Design Techniques
• Don’t get lost in
– Language Technical Details
5
What is programming?
Programming is taking
A problem
Find the area of a rectangle
A set of data
length
width
A set of functions
area = length * width
Then,
Applying functions to data to solve the problem
6
Programming Concept Evolution
• Unstructured
• Procedural
• Object-Oriented
7
Procedural Concept
• The main program coordinates calls to
procedures and hands over appropriate data
as parameters.
8
Procedural Concept (II)
• Procedural Languages
– C, Pascal, Basic, Fortran
– Facilities to
• Pass arguments to functions
• Return values from functions
• For the rectangle problem, we develop a
function
int compute_area (int l, int w){
return ( l * w );
}
9
Object-Oriented Concept
• Objects of the program interact by sending messages to
each other
10
Objects
An object is an encapsulation of both functions and data
• Objects are an Abstraction
– represent real world entities
– Classes are data types that define shared common properties or attributes
– Objects are instances of a class
• Objects have State
– have a value at a particular time
• Objects have Operations
– associated set of operations called methods that describe how to carry out
operations
• Objects have Messages
– request an object to carry out one of its operations by sending it a message
– messages are the means by which we exchange data between objects
11
OO Perspective
Let's look at the Rectangle through object oriented eyes:
• Define a new type Rectangle (a class)
– Data
• width, length
– Function
• area()
• Create an instance of the class (an object)
• Request the object for its area
In C++, rather than writing a procedure, we define a
class that encapsulates the knowledge necessary to
answer the question - here, what is the area of the
rectangle.
12
class Rectangle
{
private:
int width, length;
public:
Rectangle(int w, int l)
{
width = w;
length = l;
}
main()
{
Rectangle rect(3, 5);
cout << rect.area()<<endl;
}
int area()
{
return width*length;
}
};
Example Object Oriented Code
13
Object-Oriented Programming
Languages
• Characteristics of OOPL:
– Encapsulation
– Inheritance
– Polymorphism
• OOPLs support :
– Modular Programming
– Ease of Development
– Maintainability
14
Characteristics of OOPL
• Encapsulation: Combining data structure with actions
– Data structure: represents the properties, the state, or characteristics of objects
– Actions: permissible behaviors that are controlled through the member functions
Data hiding: Process of making certain data inaccessible
• Inheritance: Ability to derive new objects from old ones
– permits objects of a more specific class to inherit the properties (data) and
behaviors (functions) of a more general/base class
– ability to define a hierarchical relationship between objects
• Polymorphism: Ability for different objects to interpret
functions differently
15
Basic C++
• Inherit all ANSI C directives
• Inherit all C functions
• You don’t have to write OOP programming
in C++
16
Basic C++ Extension from C
• comments
/* You can still use the old comment style, */
/* but you must be // very careful about mixing them */
// It's best to use this style for 1 line or partial lines
/* And use this style when your comment
consists of multiple lines */
• cin and cout (and #include <iostream.h>)
cout << "hey";
char name[10];
cin >> name;
cout << "Hey " << name << ", nice name." << endl;
cout << endl; // print a blank line
• declaring variables almost anywhere
// declare a variable when you need it
for (int k = 1; k < 5; k++){
cout << k;
}
17
Basic C++ Extension from C (II)
• const
– In C, #define statement
• Preprocessor - No type checking.
• #define n 5
– In C++, the const specifier
• Compiler - Type checking is applied
• const int n = 5; // declare and initialize
• New data type
– Reference data type “&”.
int ix; /* ix is "real" variable */
int & rx = ix; /* rx is “alias” for ix. Must initialize*/
ix = 1; /* also rx == 1 */
rx = 2; /* also ix == 2 */
18
C++ - Advance Extension
• C++ allows function overloading
– In C++, functions can use the same names, within
the same scope, if each can be distinguished by its
name and signature
– The signature specifies the number, type, and order
of the parameters expressed as a comma separated
list of argument types
19
C++
• Is a better C
• Expressive
• Supports Data Abstraction
• Supports OOP
• Supports Generic Programming
– Containers
• Stack of char, int, double etc
– Generic Algorithms
• sort(), copy(), search() any container Stack/Vector/List
20
Take Home Message
• There are many different kinds of programming
paradigms, OOP is one among them.
• In OOP, programmers see the execution of the
program as a collection of dialoging objects.
• The main characteristics of OOPL include
encapsulation, inheritance, and polymorphism.

More Related Content

KEY
Objective c
PDF
Lo18
PPTX
The dag representation of basic blocks
PPTX
Directed Acyclic Graph Representation of basic blocks
PPTX
Lecture 08 uninformed search techniques
PDF
Standardizing on a single N-dimensional array API for Python
PPTX
Dag representation of basic blocks
PDF
17432 object oriented programming
Objective c
Lo18
The dag representation of basic blocks
Directed Acyclic Graph Representation of basic blocks
Lecture 08 uninformed search techniques
Standardizing on a single N-dimensional array API for Python
Dag representation of basic blocks
17432 object oriented programming

What's hot (20)

PPTX
Discrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
PPTX
COMPILER DESIGN AND CONSTRUCTION
PPTX
Inductive Triple Graphs: A purely functional approach to represent RDF
PDF
PyData NYC whatsnew NumPy-SciPy 2019
PPT
Primitive Wrappers
PPT
linked list in c++
PPTX
Lecture 1 Introduction C++
DOCX
Cs6660 compiler design may june 2017 answer key
PPTX
Object Detection with Tensorflow
PPTX
Mercury: A Functional Review
PDF
Cs2303 theory of computation november december 2015
PPT
Proposal for adding Named Dimensions to HDF5 Arrays
PDF
Python array API standardization - current state and benefits
PPTX
Example of iterative deepening search &amp; bidirectional search
PPTX
Stack Data structure
PPT
Dynamic Memory Allocation
PPTX
basics of c++
PPTX
Understanding the components of standard template library
PPT
An adaptive algorithm for detection of duplicate records
PPTX
Primitives in Generics
Discrete Logarithmic Problem- Basis of Elliptic Curve Cryptosystems
COMPILER DESIGN AND CONSTRUCTION
Inductive Triple Graphs: A purely functional approach to represent RDF
PyData NYC whatsnew NumPy-SciPy 2019
Primitive Wrappers
linked list in c++
Lecture 1 Introduction C++
Cs6660 compiler design may june 2017 answer key
Object Detection with Tensorflow
Mercury: A Functional Review
Cs2303 theory of computation november december 2015
Proposal for adding Named Dimensions to HDF5 Arrays
Python array API standardization - current state and benefits
Example of iterative deepening search &amp; bidirectional search
Stack Data structure
Dynamic Memory Allocation
basics of c++
Understanding the components of standard template library
An adaptive algorithm for detection of duplicate records
Primitives in Generics
Ad

Similar to Lecture1 (20)

PPTX
Object oriented programming 2 elements of programming
PPTX
Unit - I Fundamentals of Object Oriented Programming .pptx
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PPT
lecture02-cpp.ppt
PDF
C++ Interview Questions and Answers PDF By ScholarHat
PPTX
Cs1123 11 pointers
PPT
C++ - A powerful and system level language
PPTX
Return of c++
PPTX
Object oriented programming. (1).pptx
PPT
Oops lecture 1
PPTX
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
PDF
Software Engineering
PPT
Objective-C for iOS Application Development
PDF
L6
PPTX
Cs1123 3 c++ overview
PPT
c++ ppt.ppt
PPTX
C++ & Data Structure - Unit - first.pptx
Object oriented programming 2 elements of programming
Unit - I Fundamentals of Object Oriented Programming .pptx
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
lecture02-cpp.ppt
C++ Interview Questions and Answers PDF By ScholarHat
Cs1123 11 pointers
C++ - A powerful and system level language
Return of c++
Object oriented programming. (1).pptx
Oops lecture 1
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
Software Engineering
Objective-C for iOS Application Development
L6
Cs1123 3 c++ overview
c++ ppt.ppt
C++ & Data Structure - Unit - first.pptx
Ad

Recently uploaded (20)

PDF
Business Analytics and business intelligence.pdf
PDF
Fluorescence-microscope_Botany_detailed content
PPTX
Acceptance and paychological effects of mandatory extra coach I classes.pptx
PPT
ISS -ESG Data flows What is ESG and HowHow
PDF
Clinical guidelines as a resource for EBP(1).pdf
PPTX
1_Introduction to advance data techniques.pptx
PPTX
Computer network topology notes for revision
PPTX
Introduction to Knowledge Engineering Part 1
PDF
Galatica Smart Energy Infrastructure Startup Pitch Deck
PDF
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
PDF
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
PDF
Foundation of Data Science unit number two notes
PDF
annual-report-2024-2025 original latest.
PPTX
Data_Analytics_and_PowerBI_Presentation.pptx
PPTX
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
PPTX
STUDY DESIGN details- Lt Col Maksud (21).pptx
PPT
Quality review (1)_presentation of this 21
PPTX
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
PDF
168300704-gasification-ppt.pdfhghhhsjsjhsuxush
Business Analytics and business intelligence.pdf
Fluorescence-microscope_Botany_detailed content
Acceptance and paychological effects of mandatory extra coach I classes.pptx
ISS -ESG Data flows What is ESG and HowHow
Clinical guidelines as a resource for EBP(1).pdf
1_Introduction to advance data techniques.pptx
Computer network topology notes for revision
Introduction to Knowledge Engineering Part 1
Galatica Smart Energy Infrastructure Startup Pitch Deck
Recruitment and Placement PPT.pdfbjfibjdfbjfobj
BF and FI - Blockchain, fintech and Financial Innovation Lesson 2.pdf
Foundation of Data Science unit number two notes
annual-report-2024-2025 original latest.
Data_Analytics_and_PowerBI_Presentation.pptx
advance b rammar.pptxfdgdfgdfsgdfgsdgfdfgdfgsdfgdfgdfg
STUDY DESIGN details- Lt Col Maksud (21).pptx
Quality review (1)_presentation of this 21
MODULE 8 - DISASTER risk PREPAREDNESS.pptx
168300704-gasification-ppt.pdfhghhhsjsjhsuxush

Lecture1

  • 2. 2 Overview • Sign roster list • Syllabus and Course Policies • Introduction to C++ • About Lab 1 • Fill Questionnaire
  • 3. 3 Introduction to C++ • Programming Concept • Basic C++ • C++ Extension from C
  • 4. 4 Focus • Focus on – Programming Concepts – Programming Design Techniques • Don’t get lost in – Language Technical Details
  • 5. 5 What is programming? Programming is taking A problem Find the area of a rectangle A set of data length width A set of functions area = length * width Then, Applying functions to data to solve the problem
  • 6. 6 Programming Concept Evolution • Unstructured • Procedural • Object-Oriented
  • 7. 7 Procedural Concept • The main program coordinates calls to procedures and hands over appropriate data as parameters.
  • 8. 8 Procedural Concept (II) • Procedural Languages – C, Pascal, Basic, Fortran – Facilities to • Pass arguments to functions • Return values from functions • For the rectangle problem, we develop a function int compute_area (int l, int w){ return ( l * w ); }
  • 9. 9 Object-Oriented Concept • Objects of the program interact by sending messages to each other
  • 10. 10 Objects An object is an encapsulation of both functions and data • Objects are an Abstraction – represent real world entities – Classes are data types that define shared common properties or attributes – Objects are instances of a class • Objects have State – have a value at a particular time • Objects have Operations – associated set of operations called methods that describe how to carry out operations • Objects have Messages – request an object to carry out one of its operations by sending it a message – messages are the means by which we exchange data between objects
  • 11. 11 OO Perspective Let's look at the Rectangle through object oriented eyes: • Define a new type Rectangle (a class) – Data • width, length – Function • area() • Create an instance of the class (an object) • Request the object for its area In C++, rather than writing a procedure, we define a class that encapsulates the knowledge necessary to answer the question - here, what is the area of the rectangle.
  • 12. 12 class Rectangle { private: int width, length; public: Rectangle(int w, int l) { width = w; length = l; } main() { Rectangle rect(3, 5); cout << rect.area()<<endl; } int area() { return width*length; } }; Example Object Oriented Code
  • 13. 13 Object-Oriented Programming Languages • Characteristics of OOPL: – Encapsulation – Inheritance – Polymorphism • OOPLs support : – Modular Programming – Ease of Development – Maintainability
  • 14. 14 Characteristics of OOPL • Encapsulation: Combining data structure with actions – Data structure: represents the properties, the state, or characteristics of objects – Actions: permissible behaviors that are controlled through the member functions Data hiding: Process of making certain data inaccessible • Inheritance: Ability to derive new objects from old ones – permits objects of a more specific class to inherit the properties (data) and behaviors (functions) of a more general/base class – ability to define a hierarchical relationship between objects • Polymorphism: Ability for different objects to interpret functions differently
  • 15. 15 Basic C++ • Inherit all ANSI C directives • Inherit all C functions • You don’t have to write OOP programming in C++
  • 16. 16 Basic C++ Extension from C • comments /* You can still use the old comment style, */ /* but you must be // very careful about mixing them */ // It's best to use this style for 1 line or partial lines /* And use this style when your comment consists of multiple lines */ • cin and cout (and #include <iostream.h>) cout << "hey"; char name[10]; cin >> name; cout << "Hey " << name << ", nice name." << endl; cout << endl; // print a blank line • declaring variables almost anywhere // declare a variable when you need it for (int k = 1; k < 5; k++){ cout << k; }
  • 17. 17 Basic C++ Extension from C (II) • const – In C, #define statement • Preprocessor - No type checking. • #define n 5 – In C++, the const specifier • Compiler - Type checking is applied • const int n = 5; // declare and initialize • New data type – Reference data type “&”. int ix; /* ix is "real" variable */ int & rx = ix; /* rx is “alias” for ix. Must initialize*/ ix = 1; /* also rx == 1 */ rx = 2; /* also ix == 2 */
  • 18. 18 C++ - Advance Extension • C++ allows function overloading – In C++, functions can use the same names, within the same scope, if each can be distinguished by its name and signature – The signature specifies the number, type, and order of the parameters expressed as a comma separated list of argument types
  • 19. 19 C++ • Is a better C • Expressive • Supports Data Abstraction • Supports OOP • Supports Generic Programming – Containers • Stack of char, int, double etc – Generic Algorithms • sort(), copy(), search() any container Stack/Vector/List
  • 20. 20 Take Home Message • There are many different kinds of programming paradigms, OOP is one among them. • In OOP, programmers see the execution of the program as a collection of dialoging objects. • The main characteristics of OOPL include encapsulation, inheritance, and polymorphism.