0% found this document useful (0 votes)
47 views39 pages

C++ Industrial Training

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)
47 views39 pages

C++ Industrial Training

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/ 39

Dr.

Babasaheb Ambedkar Technological University ,


Lonere

C++
Name – Rutuja Babasaheb Salunkhe
Branch – Information Technology
PRN No. – 2030331246057
Seminar Guide – Ms. Ekta Meshram
Content
 Introduction
 History of C++
 What is C++?
 Uses of C++
 Advantages of C++
 Disadvantages of C++
 Standard Libraries
 C++ data types
 C++ variable scope
 Operators
 Functions
 Array
 Inheritance in C++
 Pointer
 String
 File handling in C++
Introduction

Computer programming is the process of designing and writing


computer programs. As a skill set, it includes a wide variety of
different tasks and techniques, but our tutorials are not intended
to teach you everything. Instead, they are meant to provide
basic, practical skills to help you understand and write
computer code that reflects things you see and use in the real
world. A programming language is a formal language
comprising a set of strings that produce various kinds of
machine code output. Programming languages are one kind of
computer language, and are used in computer programming to
implement algorithms. Most programming languages consist of
instructions for computers.
History of C++

 C++ is multi – paradigm programing language that supports object oriented


programing (OOP) created by Bjarne Stroustrup in 1983 at Bell labs , C++ is an
extension of C programming and the programs written in C language can run in C++
compiler.
 The development of C++ actually began four years before its release , in 1979. It did
not starts with the name C++ . Its first name was C with classes.
C++
What is C++?

C++ is a popular programming language. It was created by Bjarne Stroustrup at Bell Labs circa, and released in
1980.
It is used for:
• Game development
• Software development,
• Mathematics
• Web browsers.
What can C++ do?
• C++ can be used for game development.
• C++ can be used for Machine Learning Tools such as TensorFlow.
• C++ can be used for AR/VR Applications such as developing augmented reality and virtual reality
applications. In fact, many of these applications run on Unreal Engine, which is built using C++.
Uses of C++ Language

 C++ is used by programmers to develop computer


software.
 It is used to create general system software.
 Used to build drivers for various computer devices.
 Software for servers and software for specific
applications.
 Used in the creation of video games.
Advantage of C++

 C++ is relatively – low level and is a systems programming


language.
 It has a large community.
 It has a relatively clear and mature standard.
 Reusability and readbility.
Disadvantage of C++

 Data is global or local.


 It emphasis on instructions but not on data.
 It can be generally heavy if not on data.
 Data is global and global data does not have security.
Standard Libraries

 The C++ Standard Library can be categories into two parts:


I. The Standard function library : This library consists of
general- purpose , stand – alone function that are not part of any
class. The function library is inherited from C.
II. The Object Oriented class library : This is a collection of
classes and associated function.
 Standard C++ library incorporates all the standard libraries also ,
with small addition and changes to support type safety.
Structure of C++
Simple Program C++

#include<iostream> /*Header file*/


using namespace std;
int main()/*Main Function*/
{
Cout<<“\n*HELLO*\N”;
/*Output Statements*/
return 0;
}
C++ Data Types

Primary data types int , float , char

User defined data type structure, union ,class , enumeration

Derived data type array , function , pointer , reference


C++ Variables Scope

 A scope is a region of the program and broadly speaking


there are three places , where variables can be declared –
 Inside a function or a block which is called local
variables.
 In the definition of function parameters which is called
formal parameters.
 Outside of all function which is called global variables.
Global Variables
#include<iostream>
using namespace std;
//Global variable declaration.
int g;
int main()
{
// Local variable declaration:
int a , b;
// actual initialization
a = 10;
b = 20;
g = a + b;
cout<<g;
return 0;
}

Output :
30
Operators
 Arithmetic operators

 Relational operators

 Logical operators

 Bitwise operators

 Assignment operators
Arithmetic Operators
#include<iostream> c=a- -;
void main() cout<<“decrement of a by one”

{ <<c;
int a , b , c; return 0; }
cout<<“enter the value for a and b”;
cin>>a>>b;
c= a+b;
cout<<c;
c=a-b;
cout<<c;
c=a*b;
cout<<c;
c=a/b;
cout<<c;
c=a++;
cout<<“ increment of a by one”<<c;
Relational Operators
#include<iostream>
using namespace std; if ( a>=b)
void main() cout<<“a is greater than or equal to
b”;}
{ if(a==b)
int a , b , ; { cout<<“ a is equal to b”;}
a=10;b=13; if( a!=b)
if (a<b) { cout<<“ a is not equal to b”;}
{ cout<<“ a is less than b”;}
if ( a>b) return 0;}
{ cout<< “ a is greater than b”;}
if (a<=b)
{ cout<<“ a is less than or equal to b”;}
Logical Operators

#include<iostream> a=0;
using namespace std; b=10;
void main() if(a&&b)
{ { cout<<"condition is true"; }
int a,b; else
a=12; cout<<"condition is not true“;
b=10; if(!(a&&b))
if(a&&b) { cout<<"condition is true"; }
{ cout<<"condition is true"; } return 0;}
if(alb)
{ cout<<"condition is true"; }
Bitwise Operator

Bitwise operator woks on bits and perform bit – by – bit operation.

P Q P&Q P|Q P^Q


0 0 0 0 0
0 1 0 1 1
1 0 0 1 1
1 1 1 1 0
Assume if A = 60; and B = 13; now in binary format they will be as
follows:
A = 0011 1100 - - - - -> Binary Number for 60
B = 0000 1101 - - - - -> Binary Number for 13

------------ -
A&B= 0000 1100
A|B = 0011 1101
A^B = 0011 0001
~A = 1100 0011
Assignment Operator

An assignment operator , in the context of the C programming language , is a


basic component denoted as “ = “.

int x = 25;
x = 50 ;

Assignment Operator
Functions
Function is a set of statements to perform some task.
Every C++ program has at least one function, which
is main(), and all the most trivial programs can define
additional functions.
Syntax of Function
return-type function-name (parameters)
{
//function – body
}
Declaring , Defining and Calling Function
#include <iostream>
int sum (int x, int y); //declaring function
int main()
{int a = 10;
int b = 20;
int c = sum (a, b); //calling function
cout << c;
}
int sum (int x, int y) //defining function
{
return (x+y);
}
Output = 30
Calling a Function

Function are called by their names. If the function is


without argument , it can be called directly using its
name. But for function with arguments , we have two
ways to call them,

 Call by Value
 Call by Reference
Arrays
Array is defined as a set of homogeneous data items. An Array is a
group of elements that share a common name that are differentiated
from one another by their positions within the array.
It is a data structure which allows a collective name to be given to a
group of elements which all have the same type.
Syntax
datatype arrayname[array size];

The Array which is declared as above is called single-dimension


array
 Example : float salary[10];
float data type
salary array name
[10] array size(integer)

 The size of an array must be an integer constant and


the data type can be any valid C++ data type.
Array Initialization
 In C++ elements of an array can be initialized one by one or using a single statement
float balance[5]={1000.0, 2.0, 3.4,7.0, 50};
 The number of values between braces {} cannot be larger than the number of elements that we declare for the
array between square brackets [].

0 1 2 3 4
balance 1000.0 2.0 3.4 7.0 50.0
Inheritance in C++
The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance
is one of the most important feature of Object Oriented Programming.
Sub Class: The class that inherits properties from another class is called Sub class or Derived Class.
Super Class: The class whose properties are inherited by sub class is called Base Class or Super class.
Pointers
 Pointer is a user defined data type which creates special types of variables which can
hold the address of primitive data type like char, int, float, double or user defined
data type like function, pointer etc. or derived data type like array, structure, union,
enum.

What are Pointers ?


 A pointer is a variable whose value is the address of another variable. Like any
variable or constant, you must declare a pointer before you can work with it.

Syntax

datatype "var-name;
Using Pointers in C+
+
 There are few important operations, which we will do with thepointers
very frequently.
(a) we define a pointer variables
(b) assign the address of a variable to a pointer and
(c) finally access the value at the address available in the pointer
variable .
 This is done by using unary operator that returns the value of the
variable located at the address specified by its operand.
C++ Strings
 The following declaration and initialization create a string
consisting of the word “ Hello”. To hold the null character at
the end of the array , the size of the character array containing
the string is one more than the number of characters in the
word “ Hello”.

 Method 1 : char greeting [6] = { ‘ H’ , ‘e’, ‘l’, ‘l’ , ‘o’ , ‘\0’};


 Method 2 : char greeting [] = “ Hello”;
#include <iostream>
using namespace std;
int main ()
{
char greeting[6] = {'H', 'e', ‘l’, ‘l’, 'o', ‘\0’};
cout << "Greeting message: ";
cout << greeting << endl;
return 0;}

OUTPUT
Greeting message: Hello
File Handling in C++
File Handling concept in C++ language is used for store a data
permanently in computer. Using file handling we can store our data in
Secondary memory (Hard disk).

Why use File Handling

For permanent storage .


The transfer of input- data or output - data from one computer to
another can be easily done by using files.
 For read and write from a file you need another standard C++ library
called fstream , which defines three new data types :

Datatype Description
ofstream This is used to create a file and
write data on files
ifstream This is used to read data from
files
fstream This is used to both read and
write data from / to files
How to Achieve File Handling

For achieving file handling in C++ we need follow following steps


 Naming a file
 Opening a file
 Reading data from file
 Writing data into file
 Closing a file
Function use in file Handling
Function Operation

open() To create a file

close() To close an existing file

get() Read a single character from a


file
put() Write a single character in file.

read() Read data from file

write() Write data into file


File Read and Write Operation
include<iostream>
include<fstream>
/*
The useful classes for working with files in C++ are:
1. fstreambase
2. ifstream - - - - -> derived from fstreambase
3. ofstream - - - - - > derived from fstreambase
*/
// In order work with files in C++, you will have to open it. Primarily, there are 2 ways to open a file:
// 1. Using the constructor
// 2. Using the member function open() of the class
using namespace std;
int main(){
string st = “ hello”
//Opening files using constructor
ofstream out(“sample01.txt”);//write operation
out<<st;
// operation files using constructor and reading it
ofstream in(“sample60b.txt”);//Read operation
// in>>st2;
getline( in ,s2);
cout<<“ st2”;
return 0;
}

You might also like