0% found this document useful (0 votes)
0 views

Object Oriented Programming with C++-unit 1 introduction new

The document provides an overview of Object-Oriented Programming (OOP) with C++, starting from the evolution of software and various programming approaches, including machine-level, assembly, and high-level programming. It explains the structure of a C++ program, the differences between C and C++, and the use of primitive data types and variables in C++. Additionally, it outlines the steps to compile and execute a C++ program.

Uploaded by

Sathis Rajive
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Object Oriented Programming with C++-unit 1 introduction new

The document provides an overview of Object-Oriented Programming (OOP) with C++, starting from the evolution of software and various programming approaches, including machine-level, assembly, and high-level programming. It explains the structure of a C++ program, the differences between C and C++, and the use of primitive data types and variables in C++. Additionally, it outlines the steps to compile and execute a C++ program.

Uploaded by

Sathis Rajive
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

OBJECT ORIENTED

PROGRAMMING WITH
C++
Unit 1-
Software Evolution
 Since the invention of the computer, many
programming approaches have been used.
 The Primary motivation in all programming
styles is the concern to handle the increasing
 complexity of programs that are reliable and
maintainable.
These Programming techniques include
 1. Machine Level Programming
 2. Assembly Language Programming
 3. High Level Programming
Machine level Language :
Machine level Language :

 Machine code or machine language is a


set of instructions executed directly by a
computer's central processing unit (CPU).
 Each instruction performs a very specific
task, such as a load, a jump, or an ALU
operation on a unit of data in a CPU
register or memory.
 Every program directly executed by a
CPU is made up of a series of such
instructions.
Assembly level Language :
Assembly level Language :
Assembly level Language :

 An assembly language (or assembler language)


is a low-level programming language for a
computer, or other programmable device, in
which there is a very strong (generally one-to-
one) correspondence between the language and
the architecture's machine code instructions.

 Assembly language is converted into executable


machine code by a utility program referred to as
an assembler; the conversion process is referred
to as assembly, or assembling the code.
High level Language :

 High-level language is any programming


language that enables development of a
program in much simpler programming
context and is generally independent of the
computer's hardware architecture.

 High-level language has a higher level of


abstraction from the computer, and focuses
more on the programming logic rather than
the underlying hardware components such as
memory addressing and register utilization.
High level Language :

 The first high-level programming languages were


designed in the 1950s. Now there are dozens of
different languages, including Ada , Algol, BASIC,
COBOL, C, C++, JAVA, FORTRAN, LISP, Pascal, and
Prolog.

 Such languages are considered high-level because


they are closer to human languages and farther from
machine languages.

 In contrast, assembly languages are considered low-


level because they are very close to machine
languages.
High level Language
 High-Level programming approaches are
broadly classified as:
Procedure-Oriented Programming (POP-C
LANGUAGE&C++) &
Object-Oriented Programming (OOP-C++
WITH OBJECTS).
Procedure-Oriented Programming (POP)

 Conventional programming, using high level


languages such as COBOL, FORTRAN and C,
are commonly known as procedure-
oriented programming (POP). In the
procedure-oriented approach, the problem
is viewed as a sequence of things to be done
such as reading, calculating and printing.
 A number of functions are written to
accomplish these tasks. The primary focus
is on functions.
WHY C++-Is C++ better than C?

 C is more suitable for low programming-level


applications but also is one of the foundational
languages for a beginner.

 C++ as an extension of this language provides the


additional OOP concepts that help to build complex
applications faster, better, and more secure.

 C++ is a special purpose programming language


developed by Bjarne Stoustrup at bell labs in 1980.
Features of c++
Difference between C and C++
Difference between C and C++
Structure of C++ program
 A C++ program is structured in a
specific and particular manner. In C++, a
program is divided into the following
three sections:
 Standard Libraries Section

 Main Function Section

 Function Body Section


Structure of C++ program
Structure of C++ program
 Preprocessor Directive
 The Preprocessor Directive begins with
the character #. It is used to include the
necessary header file in a C++ program
before compilation.
 Header files:
 Usually, a program includes different
programming elements such as built-in
functions, classes, keywords, constants,
operators and more which are already
defined in the standard C++ library.
Structure of C++ program
 Consequently, programmers do not have to
declare (or define) the predefined programming
elements explicitly. Further, standard headers
specify in the program through the preprocessor
directive” #include.
 Next, the file <iostream>, which is a standard
file that should come with the C++ compiler, is
short for input-output streams. This command
comprises code for displaying and getting input
from the user.
 Syntax
#include<iostream.h>
Structure of C++ program
 When we use using namespace std into the C++
program, then it does not require to write std:: in
front of standard commands throughout the code.
Namespace std contains all the classes, objects
and functions of the standard C++ library.
 Syntax:

using namespace std;


Global variables
 Global variables are variables that are declared

outside of any function or class and are accessible


from any part of the program.
Structure of C++ program
Main Function
 The main function is the entry point or the

startup function for every C++ program, i.e.


this section defines the main() function of the
program. This is where the program starts
executing, hence this section is a mandatory
part of the structure of the C++ program.
 The function declaration and program

execution, the return type of the main


function is also mentioned in this section.
Structure of C++ program
Comments
 Comments are used to provide

explanations and documentation for the


code only, that is, they are not
executable statements.
 Syntax:

/* */
Compile: filename.cpp ->Alt-f9
WORKING OF C++ program
WORKING OF C++ program
Step-by-Step Guide To Compile And Execute C++ Program

1. Writing the code:

2. Saving the code:

3. Pre-processing:

4. Compiling:

5. Linking:

6. Generating Executable:

7. Execution:
Example C++ program
PRIMITIVE DATA TYPES
 All variables use data-type during
declaration to restrict the type of data to
be stored. Therefore, we can say that
data types are used to tell the variables
the type of data it can
 store. Whenever a variable is defined in
C++, the compiler allocates some
memory for that
 variable based on the data type with
which it is declared. Every data type
requires a different amount of memory.
PRIMITIVE DATA TYPES
PRIMITIVE DATA TYPES
 Integer: The keyword used for integer data types is int. Integers typically require 4 bytes of memory
space and range from -2147483648 to 2147483647.
 Character: Character data type is used for storing characters. The keyword used for the character data
type is char. Characters typically require 1 byte of memory space and range from -128 to 127 or 0 to
255.
 Boolean: Boolean data type is used for storing Boolean or logical values. A Boolean variable can store
either true or false. The keyword used for the Boolean data type is bool.
 Floating Point: Floating Point data type is used for storing single-precision floating-point values or
decimal values. The keyword used for the floating-point data type is float. Float variables typically
require 4 bytes of memory space.
 Double Floating Point: Double Floating Point data type is used for storing double-precision floating-
point values or decimal values. The keyword used for the double floating-point data type is double.
Double variables typically require 8 bytes of memory space.
 void: Void means without any value. void data type represents a valueless entity. A void data type is used
for those function which does not return a value.
 Wide Character: Wide character data type is also a character data type but this data type has a size
greater than the normal 8-bit data type. Represented by wchar_t. It is generally 2 or 4 bytes long.
 sizeof() operator: sizeof() operator is used to find the number of bytes occupied by a variable/data type in
computer memory.
PRIMITIVE DATA TYPES
#include <iostream>
using namespace std;

int main()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of long : " << sizeof(long) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
return 0;
}
Output
Size of char : 1
Size of int : 4
Size of long : 8
Size of float : 4
Size of double : 8
VARIABLES
 Variables are containers for storing data values.
 In C++, there are different types of variables
(defined with different keywords)
 Declaring (Creating) Variables
 To create a variable, specify the type and assign it
a value:
 Syntax
type variableName = value;
 Where type refers to datatype and variableName is
the name of the variable . The equal sign is used
to assign values to the variable.
VARIABLES
 To create a variable that should store a
number, look at the following example:
 Example

 Create a variable called myNum of type

int and assign it the value 15:


 Example

int myNum = 15;


cout << myNum;

You might also like