The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
C++ppt.pptx
1. FILE HANDLING
File handling is used to
store data permanently in
a computer.
01
POLYMORPHISM
The word
“polymorphism” means
having many forms.
02
C PRESENTATION
++
2. The fstream Library
Ofstream– This class represents an output stream.
It’s used for creating files and writing information to
files.
Ifstream– This class represents an input stream. It’s
used for reading information from data files.
Fstream– This class generally represents a file
stream. It comes with ofstream/ifstream capabilities.
This means it’s capable of creating files, writing to
files, reading from data files.
3. These file modes allow
us to create, read, write,
append or modify a file.
The file modes are
defined in the class ios.
FILE MODES
4. File Functions
1. open(): To create a file
SYNTAX:-Open (file_name, mode);
2. close(): To close an existing file
SYNTAX:- void close();
3. get(): to read a single character from the file
4. put(): to write a single character in the file
5. read(): to read data from a file
6. write(): to write data into a file
6. FILE HANDLING
File handling is used to
store data permanently in
a computer.
01
POLYMORPHISM
The word
“polymorphism” means
having many forms.
02
C PRESENTATION
++
7. Polymorphism
Polymorphism :- the same entity
(function or object) behaves
differently in different scenarios.
Real life Example
I am
Polymorphism
9. Difference between run-time and compile-time
Run-time Compile-time
1)Run time is the time period where the
executable code is running.
2)Errors can be detected only after the
execution of the program.
3)Errors that occur during the execution
of a program are called run-time errors.
Run time errors aren’t detected by the
compiler.
1)Compile time is the time period where
the code typed is converted into
executable code.
2)Errors are detected before the
execution of the program.
3)Errors that occur during compile time
are called compile-time errors. Two
types of compile-time errors area)
a) semantics error occurs when the
statements aren’t meaningful to the
compiler.
b)Syntax error occurs when the
programmer doesn’t follow the syntax.
10. Function overloading
#include <iostream>
using namespace std;
class Addition {
public:
int ADD(int X,int Y) // Function with parameter
{
return X+Y; // this function is performing
addition of two Integer value
}
int ADD() { // Function with same name
but without parameter
string a= "HELLO";
string b="SAM"; // in this function
concatenation is performed
string c= a+b;
cout<<c<<endl; }
};
int main(void) {
Addition obj; // Object is created
cout<<obj.ADD(128, 15)<<endl; //first
method is called
obj.ADD(); // second method is called
return 0;
}
Output
143
HELLOSAM
11. Operator overloading
#include <iostream>
using namespace std;
class A
{
string x;
public:
A(){}
A(string i)
{
x=i;
}
void operator+(A);
void display();
};
void A:: operator+(A a)
{
string m = x+a.x;
cout<<"The result of the addition of two objects is : "<<m;
}
int main()
{
A
a1("Welcome");
A a2("back");
a1+a2;
return 0;
}
Output
Welcomeback
12. Virtual Function
#include<iostream>
using namespace std;
class base {
public:
virtual void print()
{
cout << "print base classn";
}
void show()
{
cout << "show base classn";
}
};
class derived : public base {
public:
void print()
{
cout << "print derived classn";
}
void show()
{
cout << "show derived classn";
}
};
int main()
{
base *bptr;
derived d;
bptr = &d;
// Virtual function, binded at runtime
bptr->print();
// Non-virtual function, binded at compile
time
bptr->show();
return 0;
}
Output
print derived class
show base class