Notes From C Plu
Notes From C Plu
Notes From C Plu
Here y is exact copy of x now, mean one person with different names. Y is rference variable
of x
Type casting
o To convert one data type into another.
Manipulators:
o Endl and setw are manipulators.
Control structures.
Manipulators
o Manipulators are helping functions that can modify the input/output stream. It does
not mean that we change the value of a variable, it only modifies the I/O stream
using insertion (<<) and extraction (>>) operators.
o Endl is a manipulator and setw is also manipulator used with header file <iomanip>
o Setw set the spaces according to 4 bit see the results idea will be clear.
o Types of manipulators:
Manipulators without arguments like endl;
Manipulators with argument like setw(3) and setprecision(2) for 1.2345
Associativity:
o Means in which order they are evaluated. While precedence is priority given to
operators.
Pointer
o It is a datatype which holds the address of other data type.
Deference operator * means value of the address.
Struct:
Structures are user defined datatypes that store multiple data types within it.
Union
It is almst same as that of struct bt difference lies in memory management
Here in rice, car or pounds only one will be implemted at a time if we will try to access all it
will send garbage value because it overwrite it because they share same memory location.
Functions:
o They work on do once and use forever policy
Function prototyping
o It tells the compiler that yes function exist somewhere in the code go and find it.
Here at line 8 we have defined the function and used it below the main function
Call by reference
\
Here instead of passing value in function parameters we pass address and that address we
get using pointers.
Call by reference using c++ reference variable
Changes in any value of a will also change x
How to return reference variable
Static variable:
Static int c =0;
C++;
Here line static will be executed only one time in code that is c=0 then c=1,2,3,4,5 ...will be
continued.
Not use static variable when using inline function
Default argument
Here we have givn value of factor in function, if we dont give any value of factor during
function call it will take value in function parenthesis as a default if we pass value during
function call it will take that value
Constant argument
o It is used when we don’t want to change the values during function call we use const
keyword in parameters.
It is normally used with pointers.
Recursive function
o Those function that call its own function in the function body like in factorial finding
function n*(n-1)!
Function overloading
o Means that different functions have same name but different parameters
Identifier
o Identifier is the name of variable, class, struct, function or userdefined variable like
int a=20; here a is identifier
o If we have just declared an array without initializing it, then it is mandatory to
metion size
For dynamic memory allocation we use arrow instead of dot in static
memory allocation.
o Constructor
Constructor is called automatically as objected created
This keyword stores the address of current object
This is basically a pointer that points to the current object.
It has no return type
Parameterized constructor
That take parameters in the constructor calling
Copy constructor
It is a constructor that copies all the properties of one object in
itself.
Or constructor that initialize the value of one object into another
object is called cc.
Here in constructor making & is used
Copy constructor make shallow copy by default
Shallow copy and deep copy
IN SHALLOW COPY we are accessing same memory with two names
Deep copy
It is used to when we want that our copies pointing to different
memory locations
Destructor
It is used to deallocate memeory
When it is called it clear the memory taken by the object
No return type no input parameters
In static object declration, destructor is called automatically while in
dynamically object declration destructor need to be called manually,
using delete object_name; in main();
Static keyword for data members,
o If any variable is given static keyword, then there is no need
to create object to access value we just access from main
o
Static function:
They don’t need object to be created
They don’t have this keyword
Can only access static members
Encapsulation:
o It is binding of data members and function to protect it or to hide it or to enhance
the security using private access specifier
o Information hiding or data hiding is also called encapsulation
o We make data members private and functions as public
o Class is best example of encapsulation.
o Fully encapsulated class
In which all data member are private
We will access only in same class
o Advantage: (why)
Data hide (security increase),
If we want, we can make class read only
Inheritance
o In inheritance the derived class, inherits the data members and methods of base
class.
It increases the reusability of code and less code and more efficient.
o Private data members of superclass cannot be inherite, they cannot be accessed in
child class
o Protected data members cannot be accessed outside class but can be accessed in
child class
o Types of inheritance
Single inheritance
Like rectangle class only inherits shape class this is single
Multi level
Multiple inheritance
When one class inherits the properties methods of two or more
classes
o Hierarichal inheritance
When one class serves as parent for more than one class
o Hybrid inheritance
It is combination of more than 1 type of inheritance
o Inheritance ambiguity/diamond problem
Here obj finds confused whether to run func() of A or B
To solve this issue we use scope resolution ooperator and tells the obj that
which function you need to use.
Polymorphism:
o Existing in many forms
o Like my father is father of me, husband of my mom, brother of my phopo, grand paa
of hareem
o Ability of message to be displayed in many forms
o Types:
Compile time polymorphims
We also call it static polymorphism
Types
o Function overloading
o Operator overloading
Run runtime polymorphism
Dynamic
Method/function overriding in it
o Means that if there exist two function with same name, one
in base class and one in derived class then on creation of
o object it will run derived classs function but if no function
exist in derived it will then run base class function
o if signature is same and function name is same it is method
overriding while if signature different function name is same
then function overloading
o method overriding is only possible in inheritance
o virtual function also had run time polymorphism
Abstraction:
o It means hiding implementation
o It means that humain serf wo cheezy dekha do jo essential hai, unessential cheezo
ko hide ker do.
o Aik gaari hai usko hum liver sy brakes press kerty hai gaari rokk jati, humain is cheez
ki parwaaah nahi hai ky peachy liver kya function ker rha, piston kya ker rha or kya
functionalities perform kerny bad gaari stop hui hum brake press ki yeh humary lye
essential tha baaqi sub unessential
o We control abstraction using access specifier.
o Access specifier use ker ky cheezo ko private , public or protected ker dety hai
Advantage
Only you can change your code no one can do i
Friend function:
o Compiler does not allow any function outside the classs to access the private data
members of class.
o
o Friend function takes permission from the class to access its private data member
and it is not considered member function of class
o Because it is not member of class so it cannot be called from the object of the class.
o Usually it contains objects as argument
o Can be declared inside public and private section of class
Virtual function
o If tthere are two same function with same signature in base and derived class and
we create pointer of base class and store address of derived object in it and then we
will try to access the function it will give base class function always. But in case want
to get derived class function we use virtual keyword with the function of base class.
o
o Virtual function cannot be static
o Virtual function can be friend of another class
o
Abstract base class
o Such base class where atlreast one pure virtual function exists.
o Pure virtual function
Such function virtual type func_name()=0 this is pure virtual function this
means that it is mandatory that we will create function of same name and
type in derived class it will not not run function of base class if not found any
function in derived class
Operator overloading
o The operator like +,-,*,&& etc work with built in data types to perform operation like
int a=2 and int b=3 and axb=6 but in case of user defined data types like struct, class
these operation dont work like class a,b then we cannot add a+b or any other
operation on it. For this issue to solve that operator should work with user defined
as well as built in types we overload operator this is called operator overloading.
o Uniry operator overloading
Binary operator overloading
In binary operator overloading, right is taken as argument in
parameters while left is function call like a+b then b will be passed
as argument and a is function call
File handling
o
o How to open a file
o
o File handling is used to read data from the file or write data or output of program in
file.
o When we simply do cout and cin the program executes in memory and data
discarded upon pressing enter. But in file we permanently store data
Joins
o Joins are used to combine rows from two or more tables based on common column
between them
o Inner join:
If there exists common data between two tables then we use inner join
o Outer join
Left outr join
Here gives all teh attributes of left table while gives only those
attribute of right table that are common
Right outer join
It is opposite of left outer join
Full outer join
Dono tables all dta combined milta hai
In mysql we do this using left join UNION right join
Group by
Alter in dbmc
Drop delte the entir tabe whie truncate only delete the table dta not table structure
Mongodb
o
Read
o To retrieve data we use find function
o
`
o First line is used to fetch all documents in collection
o While second line is used to fetch only that document that contains qty equal to 90
{qty:90} this is identifier or selector
Update
o IN UPDATA, first of all we find cocument then update it
o We use set to update the value
o
o It will change only one existenece of subham to yati but if there exists more than 1
subham then we wil use updatemany to update all
Delete
o
o But this delete one document with the name of subhamand if we want to delte all
entries with the name of subham we will use remove.
o
o
Limit function:
o This function is used when we want to find any documents based on limits like
o Db.collextin_name.find().limit(2);
o Now it will show only two documents.
Count function
o It will tells how much number of documents / rows are in a collection
o Db.collection_name.find().count();
o Db.collection_name.find(name: “nouman”).count();
o It wi tell how much no. Of docuements are with na e of Nouman
Upsert
o It measn that if condition does not matc or does not find any document then data
will be inserted. We make upsert: true
o
Operators
o Operators are used to basically apply conditions on data like $gt for greater than
o
o It will show all the IDS that are greater than one
Skip
o Db.inventory.find().skip(1)
o It will skip first document and show rest document
Sort
o Db.inventory.find().sort({qty: -1)
o The -1 used for sorting in desceding order and 1 for sorting in ascending order
Mongodb atlas
o This is replacement of deploying mongob database in pc instead it provided the
facility by providing mongo server aand then facility of cloud database.
Aggregation pipeline
o An aggregation pipeline consists of one or more stages that process documents:
Each stage performs an operation on the input documents. For example, a stage can
filter documents, group documents, and calculate values. The documents that are
output from a stage are passed to the next stage.
Database cluster
o A database cluster is a collection of databases that is managed by a single instance
of a running database server.
o The major difference between a replica set and a cluster is: A replica set copies the
data set as a whole. A cluster distributes the workload and stores pieces of data
(shards) across multiple servers
o Mongodb replica set
A replica set in MongoDB is a group of mongod processes that maintain the
same data set.