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

Similar to Fundamentals of Programming in C++.ppt (20)

C++ - A powerful and system level language
C++ - A powerful and system level languageC++ - A powerful and system level language
C++ - A powerful and system level language
dhimananshu130803
 
Return of c++
Return of c++Return of c++
Return of c++
Yongwei Wu
 
Object oriented programming. (1).pptx
Object oriented programming.      (1).pptxObject oriented programming.      (1).pptx
Object oriented programming. (1).pptx
baadshahyash
 
Oops lecture 1
Oops lecture 1Oops lecture 1
Oops lecture 1
rehan16091997
 
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
lecture NOTES ON OOPS C++  ON CLASS AND OBJECTSlecture NOTES ON OOPS C++  ON CLASS AND OBJECTS
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
NagarathnaRajur2
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
Tharindu Weerasinghe
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
Dhaval Kaneria
 
L6
L6L6
L6
lksoo
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
c++ ppt.ppt
c++ ppt.pptc++ ppt.ppt
c++ ppt.ppt
FarazKhan89093
 
c++ Unit I.pptx
c++ Unit I.pptxc++ Unit I.pptx
c++ Unit I.pptx
Kongunadu College of Engineering and Technology
 
C++ & Data Structure - Unit - first.pptx
C++ & Data Structure - Unit - first.pptxC++ & Data Structure - Unit - first.pptx
C++ & Data Structure - Unit - first.pptx
KONGUNADU COLLEGE OF ENGINEERING AND TECHNOLOGY
 
Modern C++ Lunch and Learn
Modern C++ Lunch and LearnModern C++ Lunch and Learn
Modern C++ Lunch and Learn
Paul Irwin
 
Intro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suIntro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the su
ImranAliQureshi3
 
OOP PPT 1.pptx
OOP PPT 1.pptxOOP PPT 1.pptx
OOP PPT 1.pptx
lathass5
 
Lecture02
Lecture02Lecture02
Lecture02
elearning_portal
 
lecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoyelecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoye
quetsqrj
 
Introduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plusIntroduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plus
University of Sindh
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
shivam460694
 
UsingCPP_for_Artist.ppt
UsingCPP_for_Artist.pptUsingCPP_for_Artist.ppt
UsingCPP_for_Artist.ppt
vinu28455
 
C++ - A powerful and system level language
C++ - A powerful and system level languageC++ - A powerful and system level language
C++ - A powerful and system level language
dhimananshu130803
 
Object oriented programming. (1).pptx
Object oriented programming.      (1).pptxObject oriented programming.      (1).pptx
Object oriented programming. (1).pptx
baadshahyash
 
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
lecture NOTES ON OOPS C++  ON CLASS AND OBJECTSlecture NOTES ON OOPS C++  ON CLASS AND OBJECTS
lecture NOTES ON OOPS C++ ON CLASS AND OBJECTS
NagarathnaRajur2
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
Dhaval Kaneria
 
Cs1123 3 c++ overview
Cs1123 3 c++ overviewCs1123 3 c++ overview
Cs1123 3 c++ overview
TAlha MAlik
 
Modern C++ Lunch and Learn
Modern C++ Lunch and LearnModern C++ Lunch and Learn
Modern C++ Lunch and Learn
Paul Irwin
 
Intro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the suIntro-OOP-PPT- an introduction to the su
Intro-OOP-PPT- an introduction to the su
ImranAliQureshi3
 
OOP PPT 1.pptx
OOP PPT 1.pptxOOP PPT 1.pptx
OOP PPT 1.pptx
lathass5
 
lecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoyelecture5-cpp.pptintroduccionaC++basicoye
lecture5-cpp.pptintroduccionaC++basicoye
quetsqrj
 
Introduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plusIntroduction to Inheritance in C plus plus
Introduction to Inheritance in C plus plus
University of Sindh
 
Nitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptxNitin Mishra 0301EC201039 Internship PPT.pptx
Nitin Mishra 0301EC201039 Internship PPT.pptx
shivam460694
 
UsingCPP_for_Artist.ppt
UsingCPP_for_Artist.pptUsingCPP_for_Artist.ppt
UsingCPP_for_Artist.ppt
vinu28455
 

Recently uploaded (20)

Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Black and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdfBlack and White Illustrative Group Project Presentation.pdf (1).pdf
Black and White Illustrative Group Project Presentation.pdf (1).pdf
AnnasofiaUrsini
 
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 1 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKANMATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
MATERI PPT TOPIK 4 LANDASAN FILOSOFIS PENDIDIKAN
aditya23173
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition IILDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
IDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptxIDF 30min presentation - December 2, 2024.pptx
IDF 30min presentation - December 2, 2024.pptx
ArneeAgligar
 
Unit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptxUnit 3 Poster Sketches with annotations.pptx
Unit 3 Poster Sketches with annotations.pptx
bobby205207
 
Hemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptxHemiptera & Neuroptera: Insect Diversity.pptx
Hemiptera & Neuroptera: Insect Diversity.pptx
Arshad Shaikh
 
How to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 SlidesHow to Create an Event in Odoo 18 - Odoo 18 Slides
How to Create an Event in Odoo 18 - Odoo 18 Slides
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Optimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptxOptimization technique in pharmaceutical product development.pptx
Optimization technique in pharmaceutical product development.pptx
UrmiPrajapati3
 
How to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 SalesHow to Create Quotation Templates Sequence in Odoo 18 Sales
How to Create Quotation Templates Sequence in Odoo 18 Sales
Celine George
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptxSEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
SEXUALITY , UNWANTED PREGANCY AND SEXUAL ASSAULT .pptx
PoojaSen20
 
Ad

Fundamentals of Programming in C++.ppt

  • 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.