Notes From C Plu

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 17

 Here, this line 16 will give value of global c that is 45 and scope resolution operator is used

to access the value of global variabl


 For float number we use float a = 34.3f; we use f because it specifies that it is floating
number otherwise compiler would treat it as double
 Reference variable


 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

OBJECT ORIENTED PROGRAMMING (OOP)

 TYPE OF programming which revolves around object


 Object is entity which has state and behaviour
 Object is instance of class
 Generalization:
o When two or more objects in oo model having same characteristics , then we create
one base class and place all same characteristics on it this base class is called general
class and process is called generalization.
 Sub-typing(extension)
o It means that derived class is behaviourally compatible with base class plus derived
class having some extra characteristics.
 Specialization(restriction)
o When derived class is behaviourally incompatible with the base class means that
when we access characteritics of base class with some restriction like there is age
characteristics and we apply restriction that age is greater than 18 and less than 50
 Overriding
o Means that if two function with same name exist in base and derived class this is
overriding
 Abstract class
o Means the base class from which we derive more classes
o And class derived from abstract class are derived class.
 Association:
o Intereaction of different objects is known as association
 Types
 Class association
o That is implemented in terms of inheritance
 Object association
o Interaction of object of one class with object of other class
o Types:
 Simple association
 Composition
 aggregation
 Class
o Class is a user defined data type
o In empty class without properties the memory of 1 byte is allocted to object in
memory for identification purpose
o If class contains property integer then 04 bytes memory will be allocated and if float
and so on the memory according to their sizes.
o Access modifiers: public, private, protected
o Private can be accessed only within class, while public can be accessed outside class
o Getter and setter
 These are used to access the prvate data members of class
o For dynamic memory allocation


 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

Database management system:

 Database is organized collection of information in computerized format.


 Keys in dbms
o Keys are used to uniquely identify the record/tuples in table
o
o Candidate key:
 Ck is a set of all possible attributes that uniquely identify a tuple or record
 This set of attributes contain the attributes that can uniquely identify record.
 Candidate key can be null
 It is just unique
 It is minimal set of super key
o Primary key
 Primary key is one key that we select most appropriate key that is not null
from the set of candidate key to uniquely identify record
 Primary key is always 1 not more than one in a table and cannot be null
 We don’t take value of primary key from user while we give value to user
 Unique + not null
o Foreign key
 Foreign key is a attribute or set of attribute that is primary key in one table
and in other table it is foreign key
 There can exist multiple foreign keys in a data. And foreign key can repeat.
 Reference integrity:
 Foreign key maintain referential integrity
o Referential integrity refers to the relationship between
tables. Because each table in a database must have a
primary key, this primary key can appear in other tables
because of its relationship to data within those tables. When
a primary key from one table appears in another table, it is
called a foreign key .
o Super key
 Super means combination of one or more attributes (col) that uniquely
identify a record
 One extra attribute is attached with a key like id, name bothe these
collectively find record
 All the super keys cannot be candidate
o Unique key

o Composite key


 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

 It is a document based database, it is nosql database, use to use


 Nosql means data is not saved in the form of tables but it is stored in the form of
documents.
 It stores data in the form of document
 We make databases within the clusters
 db.dropDatabase() this function is used to delete database
 We can use mongodb with almost all programming languages
 In sql, there is database and in database there are tables and inside them there are rows and
cols.
 And in mongodb there is database inside which there are collections and inside collection
there is documents which resembles rows
 Mongodb instance is ON then we connect compass with databases
 Mongodb compass is only used for visualizaiton purpose of database.
 Connection string URI
o It enables connection between mongodb instance and compass or database
 There is no need to connect again and again if mongodb instance is username and password
protected.
 Mongodb create unique ID for documents as unique identifiers
 If we create database but don’t add collections then it will not show in list of databases
 Db.createCollection(‘collection_nae’), this command is used to create colletion
 Show collection is used to show the collection in db.
 Like in sql there is primary key but in mongodb there exists object ID that is unique for each
documetn
 To delete collection
o Db.collectionname.drop()
 Show dbs
o This command allows to show all the databases created.
 CRUD
o This completely defines operations of database
o Create, read, update , delete
o This crud is not mongodb specific this is database specific
o
 CREATE
o We use insert function insertone, insertmany ,bulkwrite to insert document.

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.

You might also like