Posts

Input / Output in C++

Preprocessor Directive -  Used to include files. Ex: #include. There are some files in C++ that are used for a specific purpose. Ex: #include<iostream> is used for taking input and printing output. The execution of the code begins from the main function. It is mandatory for any program. Ex: int main().  "cout" is used to display output that is in quotation marks. Ex: cout<<"Hello World";. It will display the output as Hello World . return 0 is important to specify. It marks the end of the function. That means now you can get out of the function. So, we can say that it is the exit status of the function. {}, the curly braces indicate the start and end of a function. Sample Program: #include <iostream> using namespace std ; int main (){     cout << "Hello World \n " ;     return 0 ; } Output: Hello World                                                                                   

Data Types and Modifiers

Data Types Primitive - Integer, Float, Character, Boolean Derived - Function, Array, Pointer, Reference User Defined - Class, Structure, Union, Enum Examples for Primitive Data types: Integer - 1, 4, 100 Float - 3.14, 5.22, 4.243432 Character - @, |, c, f Boolean - True, False or (0, 1) Integer occupies 4 bytes. Since 1 Byte = 8 bits, integer occupies 32 bits in a memory. Range of unsigned integer is 0 to (2^32)-1. To store negative integer, the left most (most significant bit [MSB]) is used to define the sign of the integer. So, if the left most bit is filled with 1, it means that the integer is negative and if it is 0, then it is a positive integer. Therefore, the range of signed integer is -(2^31) to (2^31)-1. Float occupies 4 bytes. We can store up to 7 decimal digits. If we want to store more digits, then we use another data type called Double that occupies 8 bytes. It can store up to 15 decimal digits. Char occupies 1 byte. We use ASCII table that is attached below. Boolean data

AGGREGATE FUNCTIONS DBMS

Image
 In DBMS, aggregate functions are used to combine multiple values of rows to get a single meaningful value.  Various Aggregate functions are: Count(): Count(*): Returns the total number of records Count(column_name): Returns the total number of non-null values in the column. Count(distinct column_name): Returns the total number of distinct non-null values in the column. Sum(): Sum(column_name): Sum of all non-null values in the column Sum(distinct column_name): Sum of all distinct non-null values in the column Avg(): Avg(salary) = Sum(salary) / count(salary) = 310/5 Avg(Distinct salary) = sum(Distinct salary) / Count(Distinct Salary) = 250/4   Min(): Min(salary): Minimum value in the salary column except NULL i.e., 40. Max(salary): Maximum value in the salary i.e., 80.

NESTED QUERIES DBMS

Image
In Nested Queries , a query is written inside a query. The result of inner query is used in the execution of the outer query. There are mainly two types of nested queries: Independent Nested Queries: In independent nested queries, query execution starts from inner query to outer query. The execution of inner query is independent of the outer query, but the result of inner query is used in the execution of the outer query.                            For Example: select S_NAME from STUDENT where S_ID IN                                                                                                                                       (select S_ID from STUDENT_COURSE where C_ID IN                                                                                                                           (select C_ID from COURSE where C_NAME='DSA' or C_NAME='DBMS')); Co-Related Nested queries: In co-related nested query, the output of the inner query depends on the row which

PL/SQL PROCEDURE

A Procedure is simply a block which performs one or more specific tasks.  A procedure contains a header and a body: Header: The header contains name of the procedure and the variables passed to the procedure. Body: The body contains a declaration section, execution section and exception section. We can pass the parameters in the procedure in three ways: IN parameter: It can be referenced by procedure or function. The value of the parameters can't be overwritten by the procedure or the function. OUT parameter: It can't be referenced by procedure or function. The values of the parameters can be overwritten by the procedure or the function. INOUT parameter: It can referenced by the procedure or function. The values of the parameters can be overwritten by the procedure or function. Syntax: CREATE Procedure_name     [parameters] IS     [declaration section] BEGIN     [executable section] [EXCEPTION     Exception_section] END[procedure_name] Example: create procedure "INSER

CLIENT SERVER MODEL - DBMS

Image
 The Client-Server model is a distributed architecture system that divides the task between the servers and clients. Here, when the client sends a request to the server through the internet, the server accepts the requested process and delivers the requested data packets back to the client.  The browser interacts with server as: User enters the URL(Uniform Resource Locator) of the website. The browser then requests the DNS (Domain Name System) server. DNS Server looks up for the address of the WEB Server. DNS Server responds with the IP Address of the WEB Server. Browser sends over an HTTP/HTTPS request to the WEB Server's IP Server sends over the necessary files of the websites. Browsers then renders the files and website is displayed. Advantages: Centralized System Cost Efficient Data recovery Capacity of client and servers can be changed Disadvantages: Clients are prone to virus if present in server or uploaded into the server Servers are prone to Denial of Service (DOS) attacks

Specialization, Generalization, Aggregation in ER Model

Image
Specialization, Generalization, Aggregation in ER Model: Generalization: It is the process of extracting common properties from a set of entities and create generalized entity from it. It is a bottom-up approach in which two or more entities can be generalized to a higher entity, if they some attributes in common. For Example, STUDENT and FACULTY can be generalized to a higher level entity called PERSON. Specialization: Here, an entity is divided into sub entities based on characteristics. It is a top-down approach where higher level entities can be divide into two or more lower level entities. For example, EMPLOYEE entity in an employee management system, can be specialized into DEVELOPER or TESTER.  Aggregation: An ER Diagram is not capable of representing relationship between an entity and a relationship which may be required in some scenarios. In those cases, a relationship with corresponding entities is aggregated into a higher level entity. Aggregation is an abstraction through w

Advantages of DBMS over FILE System

Advantages of DBMS over FILE System Data Redundancy and inconsistency: Redundancy is the concept of repetition of data. Each data may have more than a single copy. The file system cannot control the data as each user keeps the data to run different applications. If two users are maintaining the data of the same file to run different applications, then if one users changes the data, it doesn't reflect in files used by the other users which can lead to inconsistency of the data. DBMS controls redundancy by maintaining a single repository of data that is defined once and accessed by many. Data sharing: The file system doesn't allow to share the data and sharing is too complex. DBMS allows easy sharing of data due to centralized system. Data concurrency: Concurrent access to data means, more than one user accessing the data. Anomalies occur because changes made by a user can be lost because of the changes made by the other user. The file system doesn't provide any facilities to

THREE LEVELS OF DATA INDEPENDENCE

Image
THREE LEVELS OF DATA INDEPENDENCE It divides the entire system into three inter-related but independent modules: Physical Level: Here, information about the location of database objects in the data store is kept. Various DBMS users are unaware of the locations of these objects. The Physical level of database describes how the data is stored in secondary storage devices such as disks and tapes. Conceptual Level: Here, data is represented in the form of various tables. For Example, STUDENT database may contain NAME and COURSE tables, but the users are unaware of their storage. It refers to what kind of data to be stored in a database. External Level: Here, it specifies the view of data in terms of conceptual level tables. It can generate different views of the database for different users. It focuses main on data abstraction.  Data Independence: It means change of data at one level must not affect the another level. Physical Data Independence: Any change in the physical location of the t

SQL

Image
  SQL A  Database  is a collection of data which is organized for easy access and efficient management and updating. It is made of  tables  that store the relevant information. Database Tables A  table  stores data in an organized way consisting of rows and columns similar to the one which we see in Microsoft Excel. Database often contains multiple tables each created and designed for a specific purpose. For example we create a table of Patient Names and their contact details in a particular hospital.  Each  table  has own set of fields based on the data it can store.  A Table can have specified number of columns but can have any number of rows. Primary Key A Primary key is a field in the table that uniquely defines the table records. It must contain a unique value for each row and must not contain  NULL  values.  For Example , The column which contains the value ID would be a good choice for a primary key in the table.  Tables are limited to ONE primary key each and its value must be