SlideShare a Scribd company logo
1 of 40
Download to read offline
CS-200
Object Oriented Programming
4(3+1)
MuhammadUsman
MS(Computer Science) – Artificial Intelligence
Course Objectives
 Understand object-oriented programming features in C++
 Apply these features to program design and implementation
 Understand object-oriented concepts and how they are
supported by C++
 Gain some practical experience of C++
 Understand implementation issues related to object-oriented
techniques
 Build good quality software using object-oriented techniques
 Understand the role of patterns in object-orienteddesign.
Textbook and Tools
Textbook
 Object-OrientedProgramming in C++
4th Ed., Robert Lafore; SAMS Publishing
 C++ How to Programming
9th Editionby Deitel & Deitel
Programming Tools
 Dev C++
 Microsoft Visual Studio
Mid-Term
Examination
30% 30 Marks
Assignments &
Quizzes
20%
20 Marks
4 Quizzes (10 Marks)
(2 Quiz before Mid & 2 Quiz After Mid)
4 Assignments (10 Marks)
(2 Assignments before Mid & 2 Assignments After Mid)
Final Examination 50% (25 % of Mid-Term Must Include) 50 Marks
Class Evaluation and Contact
 Contact
 Class Representative(s)
 mhmdusmaan@gmail.com / muhammad.usman@abasynisb.edu.pk
Introduction to C++
C++ Origins
Low-level languages
Machine, assembly
High-level languages
 C, C++, ADA, COBOL, FORTRAN
Object-Oriented-Programming in C++
C++ Terminology
Programs and functions
Basic Input/Output (I/O) with cin and cout
Display 1.1
A Sample C++ Program (1 of 2)
Display 1.1
A Sample C++ Program (2 of 2)
Constants
Naming your constants
Literal constants are "OK", but provide
little meaning
e.g., seeing 24 in a pgm, tells nothing about
what it represents
Use named constants instead
Meaningful name to represent data
const int NUMBER_OF_STUDENTS = 24;
Called a "declared constant" or "named constant"
Now use it’s name wherever needed in program
Added benefit: changes to value result in one fix
Arithmetic Operators:
Display 1.4 Named Constant (1 of 2)
 Standard Arithmetic Operators
 Precedence rules – standard rules
Arithmetic Operators:
Display 1.4 Named Constant (2 of 2)
C++ Variables
C++ Identifiers
Keywords/reserved words vs. Identifiers
Case-sensitivity and validity of identifiers
Meaningful names!
Variables
A memory location to store data for a program
Must declare all data before use in program
Data Types:
Display 1.2 Simple Types (1 of 2)
Data Types:
Display 1.2 Simple Types (2 of 2)
Assigning Data
Initializing data in declaration statement
Results "undefined" if you don’t!
int myValue = 0;
Assigning data during execution
Lvalues (left-side) & Rvalues (right-side)
Lvalues must be variables
Rvalues can be any expression
Example:
distance = rate * time;
Lvalue: "distance"
Rvalue: "rate * time"
Assigning Data: Shorthand Notations
Data Assignment Rules
Compatibility of Data Assignments
Type mismatches
General Rule: Cannot place value of one type into variable of
another type
intVar = 2.99; // 2 is assigned to intVar!
Only integer part "fits", so that’s all that goes
Called "implicit" or "automatic type conversion"
Literals
2, 5.75, "Z", "Hello World"
Considered "constants": can’t change in program
Literal Data
Literals
Examples:
2 // Literal constant int
5.75 // Literal constant double
"Z" // Literal constant char
"Hello World" // Literal constant string
Cannot change values during execution
Called "literals" because you "literally typed"
them in your program!
Escape Sequences
 "Extend" character set
 Backslash,  preceding a character
 Instructs compiler: a special "escape
character" is coming
 Following character treated as
"escape sequence char"
 Display 1.3 next slide
Display 1.3
Some Escape Sequences (1 of 2)
Display 1.3
Some Escape Sequences (2 of 2)
Arithmetic Precision
 Precision of Calculations
 VERY important consideration!
Expressions in C++ might not evaluate as you’d "expect"!
 "Highest-orderoperand" determines type of arithmetic"precision"
performed
 Commonpitfall!
Arithmetic Precision Examples
Examples:
17 / 5 evaluates to 3 in C++!
Both operands are integers
Integer division is performed!
17.0 / 5 equals 3.4 in C++!
Highest-order operand is "double type"
Double "precision" division is performed!
int intVar1 =1, intVar2=2;
intVar1 / intVar2;
Performs integer division!
Result: 0!
Individual Arithmetic Precision
Calculations done "one-by-one"
1 / 2 / 3.0 / 4 performs 3 separate divisions.
First→ 1 / 2 equals 0
Then→ 0 / 3.0 equals 0.0
Then→ 0.0 / 4 equals 0.0!
So not necessarily sufficient to change
just "one operand" in a large expression
Must keep in mind all individual calculations
that will be performed during evaluation!
Type Casting
Casting for Variables
Can add ".0" to literals to force precision
arithmetic, but what about variables?
We can’t use "myInt.0"!
static_cast<double>intVar
Explicitly "casts" or "converts" intVar to
double type
Result of conversion is then used
Example expression:
doubleVar = static_cast<double>intVar1 / intVar2;
 Casting forces double-precision division to take place
among two integer variables!
Type Casting
Two types
Implicit—also called "Automatic"
Done FOR you, automatically
17 / 5.5
This expression causes an "implicit type cast" to
take place, casting the 17 → 17.0
Explicit type conversion
Programmer specifies conversion with cast operator
(double)17 / 5.5
Same expression as above, using explicit cast
(double)myInt / myDouble
More typical use; cast operator on variable
Shorthand Operators
 Increment & Decrement Operators
 Just short-hand notation
 Increment operator, ++
intVar++; is equivalent to
intVar = intVar + 1;
 Decrement operator, --
intVar--; is equivalent to
intVar = intVar – 1;
Shorthand Operators: Two Options
Post-Increment
intVar++
Uses current value of variable, THEN increments it
Pre-Increment
++intVar
Increments variable first, THEN uses new value
"Use" is defined as whatever "context"
variable is currently in
No difference if "alone" in statement:
intVar++; and ++intVar; → identical result
Post-Increment in Action
Post-Increment in Expressions:
int n = 2,
valueProduced;
valueProduced = 2 * (n++);
cout << valueProduced << endl;
cout << n << endl;
This code segment produces the output:
4
3
Since post-increment was used
Pre-Increment in Action
Now using Pre-increment:
int n = 2,
valueProduced;
valueProduced = 2 * (++n);
cout << valueProduced << endl;
cout << n << endl;
This code segment produces the output:
6
3
Because pre-increment was used
Console Input/Output
I/O objects cin, cout, cerr
Defined in the C++ library called
<iostream>
Must have these lines (called pre-
processor directives) near start of file:
#include <iostream>
using namespace std;
Tells C++ to use appropriate library so we can
use the I/O objects cin, cout, cerr
Console Output
What can be outputted?
Any data can be outputted to display screen
Variables
Constants
Literals
Expressions (which can include all of above)
cout << numberOfGames << " games played.";
2 values are outputted:
"value" of variable numberOfGames,
literal string " games played."
Cascading: multiple values in one cout
Separating Lines of Output
New lines in output
Recall: "n" is escape sequence for the
char "newline"
A second method: object endl
Examples:
cout << "Hello Worldn";
Sends string "Hello World" to display, & escape
sequence "n", skipping to next line
cout << "Hello World" << endl;
Same result as above
Formatting Output
 Formatting numeric values for output
 Values may not display as you’d expect!
cout << "The price is $" << price << endl;
If price (declared double) has value78.5, you
might get:
 The price is $78.500000 or:
 The price is $78.5
 We must explicitly tell C++ how to output numbers in our
programs!
Input Using cin
cin for input, cout for output
Differences:
">>" (extraction operator) points opposite
Think of it as "pointing toward where the data goes"
Object name "cin" used instead of "cout"
No literals allowed for cin
Must input "to a variable"
cin >> num;
Waits on-screen for keyboard entry
Value entered at keyboard is "assigned" to num
Prompting for Input: cin and cout
Always "prompt" user for input
cout << "Enter number of dragons: ";
cin >> numOfDragons;
Note no "n" in cout. Prompt "waits" on same
line for keyboard input as follows:
Enter number of dragons: ____
Underscore above denotes where keyboard entry
is made
Every cin should have cout prompt
Maximizes user-friendly input/output
Program Style
 Bottom-line: Make programs easy to read and modify
 Comments, two methods:
 // Two slashes indicate entire line is to be ignored
 /*Delimiters indicates everything between is ignored*/
 Both methods commonly used
 Identifier naming
 ALL_CAPS for constants
 lowerToUpper for variables
 Most important: MEANINGFUL NAMES!
Libraries
 C++ Standard Libraries
 #include <Library_Name>
 Directive to"add" contents of library file to
your program
 Called "preprocessor directive"
Executes before compiler, and simply "copies"
library file into your program file
 C++ has many libraries
 Input/output, math, strings, etc.
Namespaces
 Namespaces defined:
 Collection of name definitions
 For now: interested in namespace "std"
 Has all standard library definitions we need
 Examples:
#include <iostream>
using namespace std;
 Includes entire standard library of name definitions
 #include <iostream>
using std::cin;
using std::cout;
 Can specify just the objects we want
Summary 1
 C++ is case-sensitive
 Use meaningful names
 For variables and constants
 Variables must be declared before use
 Should also be initialized
 Use care in numeric manipulation
 Precision, parentheses, order of operations
 #include C++ libraries as needed
Summary 2
Object cout
Used for console output
Object cin
Used for console input
Use comments to aid understanding of
your program
Do not overcomment

More Related Content

What's hot

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAAiman Hud
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2yasir_cesc
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c languageRavindraSalunke3
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingAbha Damani
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingRasan Samarasinghe
 
introductory concepts
introductory conceptsintroductory concepts
introductory conceptsWalepak Ubi
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIBlue Elephant Consulting
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiSowmyaJyothi3
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSSuraj Kumar
 
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical OperatorsIntro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical OperatorsBlue Elephant Consulting
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants Hemantha Kulathilake
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in CColin
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAKTabsheer Hasan
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerVineet Kumar Saini
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...Mark Simon
 

What's hot (17)

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
[C++][a] tutorial 2
[C++][a] tutorial 2[C++][a] tutorial 2
[C++][a] tutorial 2
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 
Unit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programmingUnit 1 introduction to visual basic programming
Unit 1 introduction to visual basic programming
 
Esoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programmingEsoft Metro Campus - Certificate in c / c++ programming
Esoft Metro Campus - Certificate in c / c++ programming
 
introductory concepts
introductory conceptsintroductory concepts
introductory concepts
 
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part IIIntro To C++ - Class 03 - An Introduction To C++ Programming, Part II
Intro To C++ - Class 03 - An Introduction To C++ Programming, Part II
 
Constants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya JyothiConstants Variables Datatypes by Mrs. Sowmya Jyothi
Constants Variables Datatypes by Mrs. Sowmya Jyothi
 
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONSVISUAL BASIC 6 - CONTROLS AND DECLARATIONS
VISUAL BASIC 6 - CONTROLS AND DECLARATIONS
 
Basic
BasicBasic
Basic
 
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical OperatorsIntro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
Intro To C++ - Class 13 - Char, Switch, Break, Continue, Logical Operators
 
COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants COM1407: Type Casting, Command Line Arguments and Defining Constants
COM1407: Type Casting, Command Line Arguments and Defining Constants
 
Moving Average Filter in C
Moving Average Filter in CMoving Average Filter in C
Moving Average Filter in C
 
Programming concepts By ZAK
Programming concepts By ZAKProgramming concepts By ZAK
Programming concepts By ZAK
 
C Programming Unit-2
C Programming Unit-2C Programming Unit-2
C Programming Unit-2
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
The Swift Programming Language - Xcode6 for iOS App Development - AgileInfowa...
 

Similar to Lecture # 1 introduction revision - 1

Lecture # 1 - Introduction Revision - 1 OOPS.pptx
Lecture # 1 - Introduction  Revision - 1 OOPS.pptxLecture # 1 - Introduction  Revision - 1 OOPS.pptx
Lecture # 1 - Introduction Revision - 1 OOPS.pptxSanaullahAttariQadri
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance levelsajjad ali khan
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************Emad Helal
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...bhargavi804095
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented TechnologiesUmesh Nikam
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)ExcellenceAcadmy
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)ExcellenceAcadmy
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++Marco Izzotti
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyGrejoJoby1
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++Manzoor ALam
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++cpjcollege
 

Similar to Lecture # 1 introduction revision - 1 (20)

Lecture # 1 - Introduction Revision - 1 OOPS.pptx
Lecture # 1 - Introduction  Revision - 1 OOPS.pptxLecture # 1 - Introduction  Revision - 1 OOPS.pptx
Lecture # 1 - Introduction Revision - 1 OOPS.pptx
 
C++ basic.ppt
C++ basic.pptC++ basic.ppt
C++ basic.ppt
 
Chapter2
Chapter2Chapter2
Chapter2
 
C++ programming language basic to advance level
C++ programming language basic to advance levelC++ programming language basic to advance level
C++ programming language basic to advance level
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Introduction to C++ lecture ************
Introduction to C++ lecture ************Introduction to C++ lecture ************
Introduction to C++ lecture ************
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
cpp-streams.ppt,C++ is the top choice of many programmers for creating powerf...
 
C++ lecture 01
C++   lecture 01C++   lecture 01
C++ lecture 01
 
Object Oriented Technologies
Object Oriented TechnologiesObject Oriented Technologies
Object Oriented Technologies
 
Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)Python Training in Chandigarh(Mohali)
Python Training in Chandigarh(Mohali)
 
Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)Python Training Course in Chandigarh(Mohali)
Python Training Course in Chandigarh(Mohali)
 
Chapter02-S11.ppt
Chapter02-S11.pptChapter02-S11.ppt
Chapter02-S11.ppt
 
L03vars
L03varsL03vars
L03vars
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
Practical basics on c++
Practical basics on c++Practical basics on c++
Practical basics on c++
 
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo JobyC++ and OOPS Crash Course by ACM DBIT | Grejo Joby
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
 
C++
C++C++
C++
 
02 functions, variables, basic input and output of c++
02   functions, variables, basic input and output of c++02   functions, variables, basic input and output of c++
02 functions, variables, basic input and output of c++
 
OOPS using C++
OOPS using C++OOPS using C++
OOPS using C++
 

Recently uploaded

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Christo Ananth
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfKamal Acharya
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . pptDineshKumar4165
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Bookingdharasingh5698
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01KreezheaRecto
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdfKamal Acharya
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Christo Ananth
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfRagavanV2
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxfenichawla
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...SUHANI PANDEY
 

Recently uploaded (20)

Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...Call for Papers - International Journal of Intelligent Systems and Applicatio...
Call for Papers - International Journal of Intelligent Systems and Applicatio...
 
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdfONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
ONLINE FOOD ORDER SYSTEM PROJECT REPORT.pdf
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
Thermal Engineering Unit - I & II . ppt
Thermal Engineering  Unit - I & II . pptThermal Engineering  Unit - I & II . ppt
Thermal Engineering Unit - I & II . ppt
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 BookingVIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
VIP Call Girls Ankleshwar 7001035870 Whatsapp Number, 24/07 Booking
 
Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01Double rodded leveling 1 pdf activity 01
Double rodded leveling 1 pdf activity 01
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
Online banking management system project.pdf
Online banking management system project.pdfOnline banking management system project.pdf
Online banking management system project.pdf
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
Call for Papers - Educational Administration: Theory and Practice, E-ISSN: 21...
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
Unit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdfUnit 1 - Soil Classification and Compaction.pdf
Unit 1 - Soil Classification and Compaction.pdf
 
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptxBSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
BSides Seattle 2024 - Stopping Ethan Hunt From Taking Your Data.pptx
 
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Kothrud ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
(INDIRA) Call Girl Bhosari Call Now 8617697112 Bhosari Escorts 24x7
 

Lecture # 1 introduction revision - 1

  • 2. Course Objectives  Understand object-oriented programming features in C++  Apply these features to program design and implementation  Understand object-oriented concepts and how they are supported by C++  Gain some practical experience of C++  Understand implementation issues related to object-oriented techniques  Build good quality software using object-oriented techniques  Understand the role of patterns in object-orienteddesign.
  • 3. Textbook and Tools Textbook  Object-OrientedProgramming in C++ 4th Ed., Robert Lafore; SAMS Publishing  C++ How to Programming 9th Editionby Deitel & Deitel Programming Tools  Dev C++  Microsoft Visual Studio
  • 4. Mid-Term Examination 30% 30 Marks Assignments & Quizzes 20% 20 Marks 4 Quizzes (10 Marks) (2 Quiz before Mid & 2 Quiz After Mid) 4 Assignments (10 Marks) (2 Assignments before Mid & 2 Assignments After Mid) Final Examination 50% (25 % of Mid-Term Must Include) 50 Marks Class Evaluation and Contact  Contact  Class Representative(s)  mhmdusmaan@gmail.com / muhammad.usman@abasynisb.edu.pk
  • 5. Introduction to C++ C++ Origins Low-level languages Machine, assembly High-level languages  C, C++, ADA, COBOL, FORTRAN Object-Oriented-Programming in C++ C++ Terminology Programs and functions Basic Input/Output (I/O) with cin and cout
  • 6. Display 1.1 A Sample C++ Program (1 of 2)
  • 7. Display 1.1 A Sample C++ Program (2 of 2)
  • 8. Constants Naming your constants Literal constants are "OK", but provide little meaning e.g., seeing 24 in a pgm, tells nothing about what it represents Use named constants instead Meaningful name to represent data const int NUMBER_OF_STUDENTS = 24; Called a "declared constant" or "named constant" Now use it’s name wherever needed in program Added benefit: changes to value result in one fix
  • 9. Arithmetic Operators: Display 1.4 Named Constant (1 of 2)  Standard Arithmetic Operators  Precedence rules – standard rules
  • 10. Arithmetic Operators: Display 1.4 Named Constant (2 of 2)
  • 11. C++ Variables C++ Identifiers Keywords/reserved words vs. Identifiers Case-sensitivity and validity of identifiers Meaningful names! Variables A memory location to store data for a program Must declare all data before use in program
  • 12. Data Types: Display 1.2 Simple Types (1 of 2)
  • 13. Data Types: Display 1.2 Simple Types (2 of 2)
  • 14. Assigning Data Initializing data in declaration statement Results "undefined" if you don’t! int myValue = 0; Assigning data during execution Lvalues (left-side) & Rvalues (right-side) Lvalues must be variables Rvalues can be any expression Example: distance = rate * time; Lvalue: "distance" Rvalue: "rate * time"
  • 16. Data Assignment Rules Compatibility of Data Assignments Type mismatches General Rule: Cannot place value of one type into variable of another type intVar = 2.99; // 2 is assigned to intVar! Only integer part "fits", so that’s all that goes Called "implicit" or "automatic type conversion" Literals 2, 5.75, "Z", "Hello World" Considered "constants": can’t change in program
  • 17. Literal Data Literals Examples: 2 // Literal constant int 5.75 // Literal constant double "Z" // Literal constant char "Hello World" // Literal constant string Cannot change values during execution Called "literals" because you "literally typed" them in your program!
  • 18. Escape Sequences  "Extend" character set  Backslash, preceding a character  Instructs compiler: a special "escape character" is coming  Following character treated as "escape sequence char"  Display 1.3 next slide
  • 19. Display 1.3 Some Escape Sequences (1 of 2)
  • 20. Display 1.3 Some Escape Sequences (2 of 2)
  • 21. Arithmetic Precision  Precision of Calculations  VERY important consideration! Expressions in C++ might not evaluate as you’d "expect"!  "Highest-orderoperand" determines type of arithmetic"precision" performed  Commonpitfall!
  • 22. Arithmetic Precision Examples Examples: 17 / 5 evaluates to 3 in C++! Both operands are integers Integer division is performed! 17.0 / 5 equals 3.4 in C++! Highest-order operand is "double type" Double "precision" division is performed! int intVar1 =1, intVar2=2; intVar1 / intVar2; Performs integer division! Result: 0!
  • 23. Individual Arithmetic Precision Calculations done "one-by-one" 1 / 2 / 3.0 / 4 performs 3 separate divisions. First→ 1 / 2 equals 0 Then→ 0 / 3.0 equals 0.0 Then→ 0.0 / 4 equals 0.0! So not necessarily sufficient to change just "one operand" in a large expression Must keep in mind all individual calculations that will be performed during evaluation!
  • 24. Type Casting Casting for Variables Can add ".0" to literals to force precision arithmetic, but what about variables? We can’t use "myInt.0"! static_cast<double>intVar Explicitly "casts" or "converts" intVar to double type Result of conversion is then used Example expression: doubleVar = static_cast<double>intVar1 / intVar2;  Casting forces double-precision division to take place among two integer variables!
  • 25. Type Casting Two types Implicit—also called "Automatic" Done FOR you, automatically 17 / 5.5 This expression causes an "implicit type cast" to take place, casting the 17 → 17.0 Explicit type conversion Programmer specifies conversion with cast operator (double)17 / 5.5 Same expression as above, using explicit cast (double)myInt / myDouble More typical use; cast operator on variable
  • 26. Shorthand Operators  Increment & Decrement Operators  Just short-hand notation  Increment operator, ++ intVar++; is equivalent to intVar = intVar + 1;  Decrement operator, -- intVar--; is equivalent to intVar = intVar – 1;
  • 27. Shorthand Operators: Two Options Post-Increment intVar++ Uses current value of variable, THEN increments it Pre-Increment ++intVar Increments variable first, THEN uses new value "Use" is defined as whatever "context" variable is currently in No difference if "alone" in statement: intVar++; and ++intVar; → identical result
  • 28. Post-Increment in Action Post-Increment in Expressions: int n = 2, valueProduced; valueProduced = 2 * (n++); cout << valueProduced << endl; cout << n << endl; This code segment produces the output: 4 3 Since post-increment was used
  • 29. Pre-Increment in Action Now using Pre-increment: int n = 2, valueProduced; valueProduced = 2 * (++n); cout << valueProduced << endl; cout << n << endl; This code segment produces the output: 6 3 Because pre-increment was used
  • 30. Console Input/Output I/O objects cin, cout, cerr Defined in the C++ library called <iostream> Must have these lines (called pre- processor directives) near start of file: #include <iostream> using namespace std; Tells C++ to use appropriate library so we can use the I/O objects cin, cout, cerr
  • 31. Console Output What can be outputted? Any data can be outputted to display screen Variables Constants Literals Expressions (which can include all of above) cout << numberOfGames << " games played."; 2 values are outputted: "value" of variable numberOfGames, literal string " games played." Cascading: multiple values in one cout
  • 32. Separating Lines of Output New lines in output Recall: "n" is escape sequence for the char "newline" A second method: object endl Examples: cout << "Hello Worldn"; Sends string "Hello World" to display, & escape sequence "n", skipping to next line cout << "Hello World" << endl; Same result as above
  • 33. Formatting Output  Formatting numeric values for output  Values may not display as you’d expect! cout << "The price is $" << price << endl; If price (declared double) has value78.5, you might get:  The price is $78.500000 or:  The price is $78.5  We must explicitly tell C++ how to output numbers in our programs!
  • 34. Input Using cin cin for input, cout for output Differences: ">>" (extraction operator) points opposite Think of it as "pointing toward where the data goes" Object name "cin" used instead of "cout" No literals allowed for cin Must input "to a variable" cin >> num; Waits on-screen for keyboard entry Value entered at keyboard is "assigned" to num
  • 35. Prompting for Input: cin and cout Always "prompt" user for input cout << "Enter number of dragons: "; cin >> numOfDragons; Note no "n" in cout. Prompt "waits" on same line for keyboard input as follows: Enter number of dragons: ____ Underscore above denotes where keyboard entry is made Every cin should have cout prompt Maximizes user-friendly input/output
  • 36. Program Style  Bottom-line: Make programs easy to read and modify  Comments, two methods:  // Two slashes indicate entire line is to be ignored  /*Delimiters indicates everything between is ignored*/  Both methods commonly used  Identifier naming  ALL_CAPS for constants  lowerToUpper for variables  Most important: MEANINGFUL NAMES!
  • 37. Libraries  C++ Standard Libraries  #include <Library_Name>  Directive to"add" contents of library file to your program  Called "preprocessor directive" Executes before compiler, and simply "copies" library file into your program file  C++ has many libraries  Input/output, math, strings, etc.
  • 38. Namespaces  Namespaces defined:  Collection of name definitions  For now: interested in namespace "std"  Has all standard library definitions we need  Examples: #include <iostream> using namespace std;  Includes entire standard library of name definitions  #include <iostream> using std::cin; using std::cout;  Can specify just the objects we want
  • 39. Summary 1  C++ is case-sensitive  Use meaningful names  For variables and constants  Variables must be declared before use  Should also be initialized  Use care in numeric manipulation  Precision, parentheses, order of operations  #include C++ libraries as needed
  • 40. Summary 2 Object cout Used for console output Object cin Used for console input Use comments to aid understanding of your program Do not overcomment