0% found this document useful (0 votes)
13 views18 pages

Unit1 1

This document serves as an introduction to Object-Oriented Programming (OOP) using C++, covering its syntax, structure, and key features such as strong type checking, memory management, and exception handling. It outlines the history of C++, its development by Bjarne Stroustrup, and provides examples of basic C++ programs. The document also includes learning objectives and outcomes for students, along with practical exercises to enhance their programming skills.

Uploaded by

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

Unit1 1

This document serves as an introduction to Object-Oriented Programming (OOP) using C++, covering its syntax, structure, and key features such as strong type checking, memory management, and exception handling. It outlines the history of C++, its development by Bjarne Stroustrup, and provides examples of basic C++ programs. The document also includes learning objectives and outcomes for students, along with practical exercises to enhance their programming skills.

Uploaded by

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

DIT1123-Object oriented programming with c++

Chapter 1: Introduction to Object Oriented


Programming and C++ Elements

Kukutla Alekhya
Copyright 2023 ©, ISBAT University, All rights reserved.
Learning Objectives

• Introducing the syntax and structure of C++ programming language, including basic data types,
control structures, functions, classes, and objects.
• Helping learners to understand the differences between C++ and other programming languages
such as C and Java.
• Teaching learners how to write and execute basic C++ programs using an integrated development
environment (IDE) or a compiler.
• Providing an overview of the standard C++ library, including its built-in functions and data
structures.
• Giving learners hands-on practice with C++ programming by guiding them through several examples
and exercises.

2
INTRODUCTION

 C++ isa general purpose languagelanguage.

 Extension to Clanguage.

 Developed by Bjarne stroustrupat bell labs.

 High level and low level language features.


 C++ isan Object Oriented Programming language but isnot purely Object Oriented

 Case-sensitive.
C++ history

• C++ programming language was developed in 1980 by Bjarne Stroustrup at bell laboratories of AT&T
(American Telephone & Telegraph), located in U.S.A.

 History of C++
Early 1980s: Bjarne Stroustrup (Bell Lab)
Provides capabilities for object-oriented programming
 Objects: reusable software components
 Object-oriented programs
FEATURES

 Stronger Type Checking in C++.

 OOPS Features
 C++ supports and allows user defined operators (i.e Operator
Overloading) and function overloading

 Exception Handling

 Virtual functions and also Constructors and Destructors for Objects

 Inline Functions

 Variables can be declared anywhere in the program in C++

© ISBAT UNIVERSITY – 3/25/2020


2020.
Features of C++

1) Simple
C++ is a simple language because it provides a structured approach (to break the problem into
parts), a rich set of library functions, data types, etc.

2) Abstract Data types


In C++, complex data types called Abstract Data Types (ADT) can be created using classes.

3)Structured programming language


C++ is a structured programming language. In this we can divide the program into several parts using
functions.

4) Rich Library
C++ provides a lot of inbuilt functions that make the development fast. Following are the libraries
used in C++ programming are:
<iostream>
<cmath>
5) Memory Management
C++ provides very efficient management techniques. The various memory management operators help save the
memory and improve the program's efficiency. These operators allocate and deallocate memory at run time. Some
common memory management operators available C++ are new, delete etc.

6)Quicker Compilation
C++ programs tend to be compact and run quickly. Hence the compilation and execution time of the C++ language is
fast.

7)Extensible
C++ programs can easily be extended as it is very easy to add new features into the existing program.

8) Object-Oriented
In C++, object-oriented concepts like data hiding, encapsulation, and data abstraction can easily be implemented using
keyword class, private, public, and protected access specifiers. Object-oriented makes development and maintenance
easier.
9)Compiler based
C++ is a compiler-based programming language, which means no C++ program can be executed
without compilation. C++ compiler is easily available, and it requires very little space for storage. First,
we need to compile our program using a compiler, and then we can execute our program.

10) Reusability
With the use of inheritance of functions programs written in C++ can be reused in any other program
of C++.

11) Errors are easily detected


It is easier to maintain a C++ programs as errors can be easily located and rectified. It also provides a
feature called exception handling to support error handling in your program.
Variable declaration

type variable-name;

Where type can be:

Basic Built in types

int //for integral number ( 2 bytes )


double //double precision floating point numbers ( 8 bytes )
float //single precision floating point ( 4 bytes )
char //for character storage ( 1 byte)
bool //Boolean
char a = 'A'; // character type
Example: int a = 1; // integer type
float a = 3.14159; // floating point type
int a, b, c;
double x;
int sum; double a = 6e-4; // double type (e is for exponential)
char my-character;

© ISBAT UNIVERSITY – 3/25/2020


2020.
© ISBAT UNIVERSITY – 3/25/2020
2020.
First C++ Program

 “Hello world” program


#include <iostream>
using namespace std;
/* first program */
main()
{
cout << "Hello world" << endl; // display
}

 This program must be


Typed and saved in a file <name>.cpp (hello.cpp)
Compiled (syntax checked): hello.cpp  hello.obj
Linked (combined with iostream library) : hello.obj  hello.exe
Run (execute) hello.exe

© ISBAT UNIVERSITY – 3/25/2020


2020.
Basics of a Typical C++ Environment
28

 Common Input/output functions


cin
 Standard input stream
 Normally keyboard
cout
 Standard output stream
 Normally computer screen
 Comments: C’s comment / * .. * / OR Begin with // or
 Preprocessor directives: Begin with #
Processed beforecompiling

© ISBAT UNIVERSITY – 3/25/2020


2020.
Stream Output

 Standard output stream cout


 cout is implemented in the iostream library
 Output is sent to stream by the << insertion operator
cout << "Hello world! ";
 What can be output?
String literals between " ", expressions and variables Hello world
 More than one output could be sent to the stream and universe
cout << "Hello" << " world!" << endl; sum = 12
endl means “end of line” 45 km. = 27.9 miles
 causes next output to be displayed in next line

cout << "Hello world" << endl << " and universe" << endl;
int sum = 10 + 2;
cout << "sum = " << sum << endl;
cout << 45 << " km. = ";
cout << 45 * 0.62 << " miles" << endl;
© ISBAT UNIVERSITY – 3/25/2020
2020.
Stream Input

 Standard input stream cin is the keyboard (read “see-in”)


 cin is also implemented in the iostream library
 You can input only to variables
 Input is read from the stream by the >> Extraction operator
cin >> number;
 More than one input could be read from the stream
cin >> variable1 >> variable2 >> variable3 … ;

 Data will be read into the variables in the same order they are in the cin statement
int a, b, anynumber;
cin >> b >> anynumber >> a;
first the value for b, then the value for anynumber, then the value of a must be entered by the
user using the keyboard

© ISBAT UNIVERSITY – 3/25/2020


2020.
EXAMPLE

#include<iostream>
using namespace std;

main()
{
int x;
int y;

cout<<"Enter the Value for X:"<<endl;


cin>>x;
cout<<"Enter the Value for Y:"<<endl;
cin>>y;

cout<<"Value of X: "<< x <<endl;


cout<<"Value of Y: "<< y <<endl;

© ISBAT UNIVERSITY – 3/25/2020


2020.
Learning Outcomes

At the end of this session, students are able to:

• Understanding of a programming language syntax and its definition by example of C++


language.

• Understanding foundation concepts of information and information processing in computer


systems.

• Understand tokens, expressions, and control structures.

16
To Do

1) Write a program on Sum of digits in C++

2) Write a program to reverse number in C++.


18

Thank you

© ISBAT UNIVERSITY – 2023 5/11/2023

You might also like