1. Sanjivani Rural Education Society’s
Sanjivani College of Engineering, Kopargaon-423 603
(An Autonomous Institute, Affiliated to Savitribai Phule Pune University, Pune)
NAAC ‘A’Grade Accredited, ISO 9001:2015 Certified
Department of Computer Engineering
(NBA Accredited)
Subject- Object Oriented Programming (CO212) Unit 1 –
Fundamentals of OOP
Topic – 1.4 C++ Programming Basics
Prof. V.N.Nirgude
Assistant Professor
Email:
nirgudevikascomp@sanjivani.org.in
Contact No: 9975240215
2. What is C++?
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 2
◼ C++ is a compiled, object-oriented language
◼ It is the “successor” to C,
◼ (the “++” is called the successor operator in C++)
◼ C was derived from a language called B which
derived from BCPL
was in turn
◼ C was developed in the 1970’s by Dennis
Bell Labs
Ritchie of AT&T
◼ C++ was developed in the early
Stroustrup of AT&T Bell Labs.
1980’s by Bjarne
◼ Most of C is a subset of C++
3. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 3
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
◼ Compiler directive:
Tells the compiler
what to do before
compiling
◼ This one includes
source code from
another file
4. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 4
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
◼ Main function
5. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 5
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
◼ Header for
main function
◼ States…
◼ data type for the
return value
◼ identifier for function
◼ list of arguments
between parenthesis
(none for this
function)
6. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 6
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
◼ Braces enclose the
body of the function
◼ They represent the
start and end of the
function
7. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 7
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
◼ Declarations and
statements
◼ Main body of function
◼ “//” represents the start
of a comment
8. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 8
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
Return statement:
◼ specifies the value the
function returns
◼ All (almost) declarations
and statements end with
a semi-colon “;”
9. Simple C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 9
#include <iostream>
int main()
{
// Declarations
// Statements
return 0;
}
◼ This program
doesn’t do
anything!
10. Sample C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 10
#include <iostream>
int main()
{
int number;
cout << “Enter a number” <<endl;
cin >> number;
cout << “You entered: “ <<number;
return 0;
}
Variable declaration:
◼ The identifier
number is declared
as being of data type
int
11. Sample C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 11
#include <iostream>
int main()
{
int number;
cout << “Enter a number” <<endl;
cin >> number;
cout << “You entered: “ <<number;
return 0;
}
◼ cout:
the output statement for
C++
◼ Note the direction of
“<<“
◼ endl:
represents an end-of-line
12. Sample C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 12
#include <iostream>
int main()
{
int number;
cout << “Enter a number” <<endl;
cin >> number;
cout << “You entered: “ <<number;
return 0;
}
◼ cin:
the input statement
for C++
◼ Note the direction
of “>>”
13. Sample C++ Program
DEPARTMENT OF COMPUTER ENGINEERING , SCOE,KOPARGAON 13
#include <iostream>
int main()
{
int number;
cout << “Enter a number” <<endl;
cin >> number;
cout << “You entered: “ <<number;
return 0;
}
Output:
Enter a number:
10
You entered:10