SlideShare ist ein Scribd-Unternehmen logo
1 von 26
Information Technology
III
Introduction to Programming with C++
History of C and C++
 History of C++
 Extension of C
 Early 1980s: Bjarne Stroustrup (Bell Laboratories)
 Provides capabilities for object-oriented programming
Objects: reusable software components
Model items in real world
Object-oriented programs
Easy to understand, correct and modify
 Hybrid language
C-like style
Object-oriented style
Both
2
Basics of a Typical C++ Environment
 C++ systems
 Program-development environment
 Language
 C++ Standard Library
3
Basics of a Typical C++ Environment4
Phases of C++ Programs:
1. Edit
2. Preprocess
3. Compile
4. Link
5. Load
6. Execute
Loader
Primary
Memory
Program is created in
the editor and stored
on disk.
Preprocessor program
processes the code.
Loader puts program
in memory.
CPU takes each
instruction and
executes it, possibly
storing new data
values as the program
executes.
Compiler
Compiler creates
object code and stores
it on disk.
Linker links the object
code with the libraries,
creates a.out and
stores it on disk
Editor
Preprocessor
Linker
CPU
Primary
Memory
.
.
.
.
.
.
.
.
.
.
.
.
Disk
Disk
Disk
Disk
Disk
Hello World
This is a comment line - the line
is a brief description of program
does.
directives for the preprocessor.
They are not executable code
lines but indications for the
compiler.
<iostream.h> tells the compiler's
preprocessor to include the iostream
standard header file.
cout is the standard
output stream
The return instruction causes the main()
function finish and return the code terminating
the program without any errors during its
execution
This line corresponds to the beginning
of the main function declaration. The
main function is the point C++
programs begin their execution. It is
first to be executed when a program
starts.
Basics of a Typical C++ Environment
 Input/output
 cin
Standard input stream
Normally keyboard
 cout
Standard output stream
Normally computer screen
 cerr
Standard error stream
Display error messages
6
Comments
 It is of 2 types:-
 Single line comments //
 example of single line comment
//this is the very simple example of single line comments
 Multi line comments
/*
This is the example of
multi line comment
*/
A Simple Program: Printing a Line of
Text
8
Escape Sequence Description
n Newline. Position the screen cursor to the
beginning of the next line.
t Horizontal tab. Move the screen cursor to the next
tab stop.
r Carriage return. Position the screen cursor to the
beginning of the current line; do not advance to the
next line.
a Alert. Sound the system bell.
 Backslash. Used to print a backslash character.
" Double quote. Used to print a double quote
character.
Variables
 Variable names
Valid identifier
Series of characters (letters, digits, underscores)
Cannot begin with digit
Case sensitive
length of an identifier is not limited, (but some compilers
only the 32 first characters rest ignore)
Neither spaces nor marked letters can be part of an
identifier
can also begin with an underline character ( _ )
your own identifiers cannot match any key word of the C++
language
9
Variables
 Location in memory where value can be stored
 Common data types
int - integer numbers
char - characters
double - double precision floating point numbers
Float - floating point numbers
Bool - Boolean value (true or false)
10
Signed and Unsigned Integer Types
 For integer data types, there are three sizes:
 Int
 long - larger size of integer,
 short, which are declared as long int and short int.
 The keywords long and short are called sub-type qualifiers.
 The requirement is that short and int must be at least 16 bits, long must be at
least 32 bits,
 short is no longer than int, which is no longer than long.
 Typically, short is 16 bits, long is 32 bits, and int is either 16 or 32 bits.
 all integer data types are signed data types,
 i.e. they have values which can be positive or negative
Declaration of variables
 Declare variables with name and data type before use
int a;
float mynumber;
int MyAccountBalance;
int integer1;
int integer2;
int sum;
int integer1, integer2, sum;
Example
 A program to add two numbers;
#include<iostream>
using namespace std;
int main() {
int a, b; // variable declaration
a = 10;
b= 20;
int addition = a + b;
cout << “answer is:” << addition << endl;
return 0;
}
Scope of variables
Global variables can
be referred to
anywhere in the
code, within any
function, whenever it
is after its declaration.
The scope of the local
variables is limited
to the code level in
which they are
declared.
Constants: Literals
 A constant is any expression that has a fixed value.
 It can be Integer Numbers, Floating-Point Numbers, Characters and
Strings
 Examples
 75 // decimal
 0113 // octal
 0x4b // hexadecimal
 6.02e23 // 6.02 x 10 23
 1.6e-19 // 1.6 x 10 -19
 3.0 // 3.0
 #define PI 3.14159265
 #define NEWLINE 'n'
circle = 2 * PI * r;
cout << NEWLINE;
Defined constants (#define)
 You can define your own names for constants simply by using the
#define preprocessor directive.
 #define identifier value
 Example
 #define PI 3.14159265
 #define NEWLINE 'n'
 #define WIDTH 100
Operators
 Input stream object
 >> (stream extraction operator)
Used with std::cin
Waits for user to input value, then press Enter (Return) key
Stores value in variable to right of operator
Converts value to variable data type
 = (assignment operator)
 Assigns value to variable
 Binary operator (two operands)
 Example:
sum = variable1 + variable2;
17
Arithmetic operators
 The five arithmetical operations
+ addition
- subtraction
* multiplication
/ division
% module
Example
int a, b;
a = 10;
b = 4;
a = b;
b = 7;
a = 2 + (b = 5);
a = b = c = 5;
a -= 5;
a /= b;
a++;
a+=1;
a=a+1;
B=3;
A=++B;
A=B++;
Relational operators
 == Equal
 != Different
 > Greater than
 < Less than
 >= Greater or equal than
 <= Less or equal than
 (7 == 5)
 (5 > 4)
 (3 != 2)
 (6 >= 6)
 Suppose that a=2, b=3and
c=6,
 (a == 5)
 (a*b >= c)
 (b+4 > a*c)
 ((b=2) == a)
Logic operators ( !, &&, || )
 For example:
 ( (5 == 5) && (3 > 6) )
 ( (5 == 5) || (3 > 6))
 Conditional operator ( ? )
 condition ? result1 : result2
 if condition is true the expression will return result1, if not it
will return result2.
 7==5 ? 4 : 3
 7==5+2 ? 4 : 3
 5>3 ? a : b
Precedence of Operators
 Rules of operator precedence
 Operators in parentheses evaluated first
 Nested/embedded parentheses
 Operators in innermost pair first
 Multiplication, division, modulus applied next
 Operators applied from left to right
 Addition, subtraction applied last
 Operators applied from left to right
22
Operator(s) Operation(s) Order of evaluation (precedence)
() Parentheses Evaluated first. If the parentheses are nested, the
expression in the innermost pair is evaluated first. If
there are several pairs of parentheses “on the same level”
(i.e., not nested), they are evaluated left to right.
*, /, or % Multiplication Division
Modulus
Evaluated second. If there are several, they re
evaluated left to right.
+ or - Addition
Subtraction
Evaluated last. If there are several, they are
evaluated left to right.
Types of Errors
 Syntax errors
A syntax error occurs when the programmer fails to obey one of the grammar
rules of the language.
 Runtime errors
A runtime error occurs whenever the program instructs the computer to do
something that it is either incapable or unwilling to do.
 Logic errors
Logic errors are usually the most difficult kind of errors to find and fix, because
there frequently is no obvious indication of the error.
Usually the program runs successfully. It simply doesn't behave as it should.
it doesn't produce the correct answers.
Syntax errors
Syntax Error: undeclared identifer “cout”
Syntax errors
 result = (firstVal - secondVal / factor;
Syntax Error: ’)’ expected
 cout << “Execution Terminated << endl;
Syntax Error: illegal string constant
 double x = 2.0, y = 3.1415, product;
x * y = product;
Syntax Error: not an l-value
Logical errors
 int a, b;
int sum = a + b;
cout << "Enter two numbers to add: ";
cin >> a; cin >> b;
cout << "The sum is: " << sum;
 char done = 'Y';
while (done = 'Y') {
//... cout << "Continue? (Y/N)";
cin >> done;
}

Weitere ähnliche Inhalte

Was ist angesagt?

Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_outputAnil Dutt
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01Wingston
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c languageRavindraSalunke3
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpen Gurukul
 
Basic of c language
Basic of c languageBasic of c language
Basic of c languagesunilchute1
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programmingChitrank Dixit
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageAbhishek Dwivedi
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 FocJAYA
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language CourseVivek chan
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdfSowmyaJyothi3
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computerShankar Gangaju
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C BasicsBharat Kalia
 
C Programming basics
C Programming basicsC Programming basics
C Programming basicsJitin Pillai
 

Was ist angesagt? (20)

Structure of c_program_to_input_output
Structure of c_program_to_input_outputStructure of c_program_to_input_output
Structure of c_program_to_input_output
 
Introduction to Basic C programming 01
Introduction to Basic C programming 01Introduction to Basic C programming 01
Introduction to Basic C programming 01
 
Introduction to c language
Introduction to c languageIntroduction to c language
Introduction to c language
 
OpenGurukul : Language : C Programming
OpenGurukul : Language : C ProgrammingOpenGurukul : Language : C Programming
OpenGurukul : Language : C Programming
 
Python Programming
Python ProgrammingPython Programming
Python Programming
 
Basic of c language
Basic of c languageBasic of c language
Basic of c language
 
Fundamentals of c programming
Fundamentals of c programmingFundamentals of c programming
Fundamentals of c programming
 
Learning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C LanguageLearning c - An extensive guide to learn the C Language
Learning c - An extensive guide to learn the C Language
 
Unit 4 Foc
Unit 4 FocUnit 4 Foc
Unit 4 Foc
 
C material
C materialC material
C material
 
Complete C programming Language Course
Complete C programming Language CourseComplete C programming Language Course
Complete C programming Language Course
 
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdfMANAGING INPUT AND OUTPUT OPERATIONS IN C    MRS.SOWMYA JYOTHI.pdf
MANAGING INPUT AND OUTPUT OPERATIONS IN C MRS.SOWMYA JYOTHI.pdf
 
1. introduction to computer
1. introduction to computer1. introduction to computer
1. introduction to computer
 
C programming language
C programming languageC programming language
C programming language
 
Programming in C Basics
Programming in C BasicsProgramming in C Basics
Programming in C Basics
 
Unit ii
Unit   iiUnit   ii
Unit ii
 
C Programming basics
C Programming basicsC Programming basics
C Programming basics
 
Learn C
Learn CLearn C
Learn C
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
C tokens
C tokensC tokens
C tokens
 

Ähnlich wie C++ lecture 01

Ähnlich wie C++ lecture 01 (20)

C Programming Unit-1
C Programming Unit-1C Programming Unit-1
C Programming Unit-1
 
#Code2 create c++ for beginners
#Code2 create  c++ for beginners #Code2 create  c++ for beginners
#Code2 create c++ for beginners
 
Unit 1 c - all topics
Unit 1   c - all topicsUnit 1   c - all topics
Unit 1 c - all topics
 
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
 
C_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptxC_Programming_Language_tutorial__Autosaved_.pptx
C_Programming_Language_tutorial__Autosaved_.pptx
 
Chapter2
Chapter2Chapter2
Chapter2
 
Introduction%20C.pptx
Introduction%20C.pptxIntroduction%20C.pptx
Introduction%20C.pptx
 
02a fundamental c++ types, arithmetic
02a   fundamental c++ types, arithmetic 02a   fundamental c++ types, arithmetic
02a fundamental c++ types, arithmetic
 
Introduction to C Programming
Introduction to C ProgrammingIntroduction to C Programming
Introduction to C Programming
 
basics of C and c++ by eteaching
basics of C and c++ by eteachingbasics of C and c++ by eteaching
basics of C and c++ by eteaching
 
Complete C++ programming Language Course
Complete C++ programming Language CourseComplete C++ programming Language Course
Complete C++ programming Language Course
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Getting started with c++
Getting started with c++Getting started with c++
Getting started with c++
 
Lập trình C
Lập trình CLập trình C
Lập trình C
 
Basics Of C++.pptx
Basics Of C++.pptxBasics Of C++.pptx
Basics Of C++.pptx
 
keyword
keywordkeyword
keyword
 
keyword
keywordkeyword
keyword
 
C language
C language C language
C language
 
Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++Introduction to Procedural Programming in C++
Introduction to Procedural Programming in C++
 
Ch02
Ch02Ch02
Ch02
 

Mehr von HNDE Labuduwa Galle (8)

Lecture 07 networking
Lecture 07 networkingLecture 07 networking
Lecture 07 networking
 
Lecture 04 networking
Lecture 04 networkingLecture 04 networking
Lecture 04 networking
 
Lecture 03 networking
Lecture 03 networkingLecture 03 networking
Lecture 03 networking
 
Lecture 02 networking
Lecture 02 networkingLecture 02 networking
Lecture 02 networking
 
Lecture 01 networking
Lecture 01 networkingLecture 01 networking
Lecture 01 networking
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
C++ lecture 02
C++   lecture 02C++   lecture 02
C++ lecture 02
 

Kürzlich hochgeladen

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 - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINESIVASHANKAR N
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...Soham Mondal
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCall Girls in Nagpur High Profile
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 

Kürzlich hochgeladen (20)

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 - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINEMANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
MANUFACTURING PROCESS-II UNIT-2 LATHE MACHINE
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
OSVC_Meta-Data based Simulation Automation to overcome Verification Challenge...
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service NashikCollege Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
College Call Girls Nashik Nehal 7001305949 Independent Escort Service Nashik
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 

C++ lecture 01

  • 2. History of C and C++  History of C++  Extension of C  Early 1980s: Bjarne Stroustrup (Bell Laboratories)  Provides capabilities for object-oriented programming Objects: reusable software components Model items in real world Object-oriented programs Easy to understand, correct and modify  Hybrid language C-like style Object-oriented style Both 2
  • 3. Basics of a Typical C++ Environment  C++ systems  Program-development environment  Language  C++ Standard Library 3
  • 4. Basics of a Typical C++ Environment4 Phases of C++ Programs: 1. Edit 2. Preprocess 3. Compile 4. Link 5. Load 6. Execute Loader Primary Memory Program is created in the editor and stored on disk. Preprocessor program processes the code. Loader puts program in memory. CPU takes each instruction and executes it, possibly storing new data values as the program executes. Compiler Compiler creates object code and stores it on disk. Linker links the object code with the libraries, creates a.out and stores it on disk Editor Preprocessor Linker CPU Primary Memory . . . . . . . . . . . . Disk Disk Disk Disk Disk
  • 5. Hello World This is a comment line - the line is a brief description of program does. directives for the preprocessor. They are not executable code lines but indications for the compiler. <iostream.h> tells the compiler's preprocessor to include the iostream standard header file. cout is the standard output stream The return instruction causes the main() function finish and return the code terminating the program without any errors during its execution This line corresponds to the beginning of the main function declaration. The main function is the point C++ programs begin their execution. It is first to be executed when a program starts.
  • 6. Basics of a Typical C++ Environment  Input/output  cin Standard input stream Normally keyboard  cout Standard output stream Normally computer screen  cerr Standard error stream Display error messages 6
  • 7. Comments  It is of 2 types:-  Single line comments //  example of single line comment //this is the very simple example of single line comments  Multi line comments /* This is the example of multi line comment */
  • 8. A Simple Program: Printing a Line of Text 8 Escape Sequence Description n Newline. Position the screen cursor to the beginning of the next line. t Horizontal tab. Move the screen cursor to the next tab stop. r Carriage return. Position the screen cursor to the beginning of the current line; do not advance to the next line. a Alert. Sound the system bell. Backslash. Used to print a backslash character. " Double quote. Used to print a double quote character.
  • 9. Variables  Variable names Valid identifier Series of characters (letters, digits, underscores) Cannot begin with digit Case sensitive length of an identifier is not limited, (but some compilers only the 32 first characters rest ignore) Neither spaces nor marked letters can be part of an identifier can also begin with an underline character ( _ ) your own identifiers cannot match any key word of the C++ language 9
  • 10. Variables  Location in memory where value can be stored  Common data types int - integer numbers char - characters double - double precision floating point numbers Float - floating point numbers Bool - Boolean value (true or false) 10
  • 11. Signed and Unsigned Integer Types  For integer data types, there are three sizes:  Int  long - larger size of integer,  short, which are declared as long int and short int.  The keywords long and short are called sub-type qualifiers.  The requirement is that short and int must be at least 16 bits, long must be at least 32 bits,  short is no longer than int, which is no longer than long.  Typically, short is 16 bits, long is 32 bits, and int is either 16 or 32 bits.  all integer data types are signed data types,  i.e. they have values which can be positive or negative
  • 12. Declaration of variables  Declare variables with name and data type before use int a; float mynumber; int MyAccountBalance; int integer1; int integer2; int sum; int integer1, integer2, sum;
  • 13. Example  A program to add two numbers; #include<iostream> using namespace std; int main() { int a, b; // variable declaration a = 10; b= 20; int addition = a + b; cout << “answer is:” << addition << endl; return 0; }
  • 14. Scope of variables Global variables can be referred to anywhere in the code, within any function, whenever it is after its declaration. The scope of the local variables is limited to the code level in which they are declared.
  • 15. Constants: Literals  A constant is any expression that has a fixed value.  It can be Integer Numbers, Floating-Point Numbers, Characters and Strings  Examples  75 // decimal  0113 // octal  0x4b // hexadecimal  6.02e23 // 6.02 x 10 23  1.6e-19 // 1.6 x 10 -19  3.0 // 3.0  #define PI 3.14159265  #define NEWLINE 'n' circle = 2 * PI * r; cout << NEWLINE;
  • 16. Defined constants (#define)  You can define your own names for constants simply by using the #define preprocessor directive.  #define identifier value  Example  #define PI 3.14159265  #define NEWLINE 'n'  #define WIDTH 100
  • 17. Operators  Input stream object  >> (stream extraction operator) Used with std::cin Waits for user to input value, then press Enter (Return) key Stores value in variable to right of operator Converts value to variable data type  = (assignment operator)  Assigns value to variable  Binary operator (two operands)  Example: sum = variable1 + variable2; 17
  • 18. Arithmetic operators  The five arithmetical operations + addition - subtraction * multiplication / division % module
  • 19. Example int a, b; a = 10; b = 4; a = b; b = 7; a = 2 + (b = 5); a = b = c = 5; a -= 5; a /= b; a++; a+=1; a=a+1; B=3; A=++B; A=B++;
  • 20. Relational operators  == Equal  != Different  > Greater than  < Less than  >= Greater or equal than  <= Less or equal than  (7 == 5)  (5 > 4)  (3 != 2)  (6 >= 6)  Suppose that a=2, b=3and c=6,  (a == 5)  (a*b >= c)  (b+4 > a*c)  ((b=2) == a)
  • 21. Logic operators ( !, &&, || )  For example:  ( (5 == 5) && (3 > 6) )  ( (5 == 5) || (3 > 6))  Conditional operator ( ? )  condition ? result1 : result2  if condition is true the expression will return result1, if not it will return result2.  7==5 ? 4 : 3  7==5+2 ? 4 : 3  5>3 ? a : b
  • 22. Precedence of Operators  Rules of operator precedence  Operators in parentheses evaluated first  Nested/embedded parentheses  Operators in innermost pair first  Multiplication, division, modulus applied next  Operators applied from left to right  Addition, subtraction applied last  Operators applied from left to right 22 Operator(s) Operation(s) Order of evaluation (precedence) () Parentheses Evaluated first. If the parentheses are nested, the expression in the innermost pair is evaluated first. If there are several pairs of parentheses “on the same level” (i.e., not nested), they are evaluated left to right. *, /, or % Multiplication Division Modulus Evaluated second. If there are several, they re evaluated left to right. + or - Addition Subtraction Evaluated last. If there are several, they are evaluated left to right.
  • 23. Types of Errors  Syntax errors A syntax error occurs when the programmer fails to obey one of the grammar rules of the language.  Runtime errors A runtime error occurs whenever the program instructs the computer to do something that it is either incapable or unwilling to do.  Logic errors Logic errors are usually the most difficult kind of errors to find and fix, because there frequently is no obvious indication of the error. Usually the program runs successfully. It simply doesn't behave as it should. it doesn't produce the correct answers.
  • 24. Syntax errors Syntax Error: undeclared identifer “cout”
  • 25. Syntax errors  result = (firstVal - secondVal / factor; Syntax Error: ’)’ expected  cout << “Execution Terminated << endl; Syntax Error: illegal string constant  double x = 2.0, y = 3.1415, product; x * y = product; Syntax Error: not an l-value
  • 26. Logical errors  int a, b; int sum = a + b; cout << "Enter two numbers to add: "; cin >> a; cin >> b; cout << "The sum is: " << sum;  char done = 'Y'; while (done = 'Y') { //... cout << "Continue? (Y/N)"; cin >> done; }