NEB Class 12 Computer Notes
NEB Class 12 Computer Notes
com
Grade: XII
1. What is Database and DBMS? List out the advantages and disadvantages of
DBMS.
2. Explain the different models of DBMS with advantages and disadvantages.
3. Write differentiate between centralized and distributed database system.
4. Who is DBA? What are the major responsibilities of DBA?
5. What is normalization? Explain normalization process with examples.
6. Define the following terms. a) Data Dictionary b) Primary Key
c) Relationship d) DML e) SQL f) Data Integrity g) DDL
h) Data Security i) Database System
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Information:
When data are processed using a database program or software, they are converted to the meaningful
result, called information. Information provides answers to "who", "what", "where", and "when"
questions. Examples, Hari lives in Bharatpur-11, Chitwan.
Data Processing
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Database System:
A database system consists of a collection of interrelated data and a set of application programs to access,
update and manage the data.
Database:
It is organized form of record about some person, organization or something store under certain media.
It is a collection of related information about a subject organized in a useful manner that provides a base
or foundation for procedure, such as retrieving information, drawing conclusion and make decision.
Advantage of database over flat file or file based system
1. Reduction of data redundancies
2. Shared data
3. Data independent
4. Improved integrity
5. Efficient data access
6. Multiple user interface
7. Improved security
8. Improved backup and recovery
9. Supports for concurrent transactions
10. Unforeseen queries can be answered
DBMS:
Database Management System is software that manages the data stored in a database. This is a collection
of software which is used to store data, records, process them and obtain desired information. Since, data
are very important to the end users, we must have a good way of managing data.
A DBMS is a collection of programs that manages the database structure and controls access to the data
stored in the database. The DBMS make it possible to share the data in the database among multiple
applications or users. The DBMS stands between the database and the user.
Examples: MS-Access, Oracle, FoxPro, dBase, SQL server, MySQL, Delphi, Sybase, etc.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
API
APP
Database
API Management System
(DBMS) Database (DB)
User
API
APP
Disadvantages of DBMS
1. Expensive
2. Changing Technology
3. Needs Technical Training
4. Backup is needed
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Field/ Attribute:
A field is a piece of information about an element. A field is represented by a column. Every field has got
a title called the field title.
Record (Tuple):
A record is information about an element such as a person, student, an employee, client, etc. A record
can have much information in different heading or titles.
Table:
A table is the arrangements of rows and columns. Each table must have unique name and must be simple.
It is the place where data and information are stored.
Keys of DBMS:
Key is a field that uniquely identifies the records, tables or data. Key in a table allows us to establish the
relation between multiple tables. Keys are also useful for finding the unique records or combination of
records from a large database tables.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Primary Key: A primary key is one or more columns in a table used to uniquely identify each row
in the table. Primary key cannot contain Null value.
A primary key is a special relational database table column (or combination of columns)
designated to uniquely identify each table record. A table cannot have more than one primary
key.
A primary key’s main features are:
It must contain a unique value under the field.
It cannot contain null values.
Every row must have a primary key value.
Foreign Key: Foreign keys represent relationships between tables. A foreign key is a column whose
values are derived from the primary key of some other table.
Candidate Key: If a relational schema has more than one key, that is called a candidate key. All
the keys which satisfy the condition of primary key can be candidate key. There can be any number
of candidate keys that can be used in place of the primary key if required.
Alternate Key/ Secondary Key: Alternative keys are those candidate keys which are not the
primary key. There can be only one primary key for a table. Therefore all the remaining candidate
keys are known as alternative.
Compound Key: It has two or more attributes that allow you to uniquely recognize specific record.
It is possible that each column may not be unique by itself within the database.
1. DDL (Data Definition Language): DDL is used by the database designers and programmers to
specify the content and structure of the table. It is used to define the physical characteristics of
records. It includes commands that manipulate the structure of objects such as views, tables, and
indexes, etc.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
» CREATE: Create is used to create the database or its objects (like table, index, function, views, store
procedure and triggers).
» DROP: Drop is used to delete objects from the database.
» ALTER: Alter is used to alter the structure of the database.
» TRUNCATE: Truncate is used to remove all records from a table, including all spaces allocated for the
records are removed.
» COMMENT: Comment is used to add comments to the data dictionary.
» RENAME: Rename is used to rename an object existing in the database.
2. DML (Data Manipulation Language): DML is related with manipulation of records such as
retrieval, sorting, display and deletion of records of data. It helps user to use query and display reports
of the table. So it provides technique for processing the database.
3. DCL (Data Control Language): DCL provides additional features for security of table or database.
It includes commands for controlling data and access to the database. Examples of these commands
are commit, Rollback, Grant etc.
Database Model:
A Database model defines the logical design and structure of a database and are used to show how data
will be stored, accessed and updated in a Database Management System. It refers to the layout of a
database and helps in designing a database. The various types of database models are
Different database models
1. Hierarchical database model: this is one of the oldest types of database models. In this model
data is represented in the form of records. Each record has multiple fields. All records are arranged
in database as tree like structure. The relationship between the records is called parent child
relationship in which any child record relates to only a single parent type record.
Gurukul College
Advantages
⚫ It is the easiest model.
⚫ Searching is fast and easy if parent is known.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
⚫ It is very efficient in handling one to one and one to many relationships.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Disadvantages
⚫ It is old and outdated database model.
⚫ It does not support many to many relationships.
⚫ It increases redundancy because same data is to be repeated in different places.
2. Network database model: It replaced hierarchical network database model due to some
limitations on the model. Suppose, if an employee relates to two departments, then the
hierarchical database model cannot able to arrange records in proper place. So network, database
model was emerged to arranged non-hierarchical database. The structure of database is more like
graph rather than tree structure. A network database model is a database model that allows
multiple records to be linked the same owner file. The network model allows each child to have
multiple parents.
Gurukul College
Advantages
⚫ It accepts many to many relationships, so it is more flexible.
⚫ The searching is faster because of multidirectional pointer.
⚫ The network model is simple and easy to design.
⚫ It reduces the redundancy.
Disadvantages
⚫ It is difficult to handle the relationship in complex programs.
⚫ There is less security because of sharing data.
⚫ It increases the processing overhead due to the complex relationship.
3. Relational database model: in this model, the data is organized into tables which contain multiple
rows and columns. These tables are called relations. A row in a table represents a relationship
among a set of values. Since a table is a collection of such relationships, it is generally referred to
the mathematical term relation, from which the relational database model derives its name.
We notice from below table, here each student has a unique roll number and has marks of subject.
Here Roll makes relation between these two tables.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
following:
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Table: Subject
Roll Name Math English Computer
1 Hari 80 90 95
2 Sita 90 80 85
3 Ram 95 95 95
Advantages
⚫ The breaking of complex database table into simple database table becomes possible.
⚫ Database processing is faster than other model.
⚫ There is very less redundancy.
⚫ The integrity rules can easily be implemented.
Disadvantages
⚫ It is more complex than other models.
⚫ There are too many rules because of complex relationships.
⚫ It needs more powerful computers and data storage devices.
4. Object oriented database model: In the object-oriented model, both data and their relationships
are contained in a single structure known as an object. An Object-Oriented Model reflects a very
different way to define and use entities. An object includes information about relationships
between the facts within the object, as well as information about its relationships with other
objects. An objects include data, various types of relationships, and operational procedures, the
object becomes self-contained, thus making the object-at least potentially-a basic building block
for autonomous structures.
Advantages
Semantic content is added.
Visual representation includes semantic content.
Inheritance promotes data integrity.
Disadvantages
Slow development of standards caused vendors to supply their own enhancements, thus
eliminating a widely accepted standard.
It is a complex navigational system.
There is a steep learning curve.
High system overhead slows transactions.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Pname
CName
CAddress
PAddress
College H Principal
Pcontact
Phone
Fig. E-R diagram for relation between college and principal
2. One to many: If one instance of one entity is related with many instances of other entity then
it is called the one to many relationship.
⚫ College ----------------students
⚫ Bank -------------------- Employers
3. Many to many: If many instances of the one entity are related with many instances of another
entity then it is called many to many relationship.
⚫ Teachers --------------- students
⚫ Books ----------------- Readers
⚫ Employers ------------ Customers
Concept of Normalization
Normalization is a database design process in which complex database table is broken down into simple
separate tables. It makes data model more flexible and easier to maintain.
Database Normalization is a technique of organizing the data in the database. It is a systematic
approach of decomposing the tables to eliminate data redundancy and inconsistency. The data is
said to be redundant if there is duplicate or repeated data in the table.
Normalization divides the larger table into the smaller table and links them using relationship. It
increase clarity in organizing data in the database.
For example:
Below table shown is our database without normalized. Here in table we can see that for the large records
of this table, there would be multiple data row of same values especially in the country and city column.
So, we can normalize the table by splitting it into two tables where one table only stores the location area
of each person name and could be referenced by some unique id. Say Area code.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Types of Normalization
1NF (First Normal Form):
A table is said to be in first normal form if it has atomic values. There shouldn't be any repeating
groups of attribute in the table. First normal form sets the very basic rules for an organized
database.
o The data field should be a single (atomic) valued attribute/ columns.
o It eliminates duplicates rows and columns from the same table.
o It minimizes the data redundancy in the database table.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Situation of Dependency:
Let’s take an example of table student with student_id, name, address and age as its columns.
Student_id Name Address age
Here student_id is the primary key which can identify each records uniquely and can be used to fetch
any row of data from this table.
Here we can get name, address and age of the student easily from their student_id. Which means each
column can be fetched using primary key. So, all needed is student_id and every other column depends
on it or can be fetched using it.
This is called dependency or functional dependency. And this kind of dependency must be in table to be
in second normal form.
Subject_id Subjectname
101 Math
102 Science
103 Nepali
Above we have two tables: student and subject for storing student’s and subject’s information. Now, let’s
make a table named Mark storing student’s mark in respective subjects with subject teacher.
In above table student_id is used to get student’s information where as subject_id is used to get subject
name. The combination of student_id and subject_id is the primary in above table. It is because if we
want to get mark of student with id 15 then we cannot get because we don’t know which subject. Here
we have to give sudent_id and subject_id to uniquely identify any row.
Is there a partial dependency in above table? Obviously, yes. In the given table Mark column name
teacher is only dependent on the subject, for math there is Bishnu for science Umesh and so on. But the
primary key is the combination of student_id and subject_id, teacher’s name depend only on subject, i.e.
subject_id not on the student id.
This situation is known as partial dependency, where an attribute/ column in table depends on only a
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
part of primary key not on the whole key.
[ www.prasiddhaacharya.com.np ]
Removing the partial dependency:
Above table can be normalized in second normal form by removing teacher’s name from the Mark table
adding it to Subject table.
Subject:
Subject_id Subjectname Teacher
101 Math Bishnu
102 Science Umesh
103 Nepali Janvi
Mark:
Score_id Student_id Subject_id Marks
1 15 101 55
2 15 102 65
3 16 103 88
Summary:
For table to be in second normal form, it should be in first normal form.
Partial dependency exists, when non primary key attribute depends only on a part of
primary key instead of complete primary key.
Partial dependency can be removed by breaking a table and removing attributes causing
partial dependency.
17
Computer Science Reference Note for Grade-XII
Exam Table:
Exam_ID Exam_Name Full_Marks
11 First Term 500
12 Second Term 300
Example of normalization:
Un-normalized Table:
Employee Id Name Address Department
101 Ram Kathmandu Sales
102 Bikky Bhaktapur Marketing, Export
103 Anusha Lalitpur import
Here the non-primary key attribute salary dependent on the employee id only. Here Employee id and
department are the candidate key. This violates the rule that “no non primary attribute is dependent on
the part of primary key or on the subset of candidate key.”
15
To make table in 2NF we can break it as:
Employee Id Salary
101 20000
102 25000
103 20000
Employee Id Department
101 Sales
102 Marketing
102 Export
103 import
Here, Employee Id is the primary key and all other are non-primary key attributes. The non- primary key
attribute HoD is dependent on non-primary key attribute Department. Here, transitive dependency
occurs. To remove it we can decompose table as:
Employee Id Department Id Name
101 A10 Rikesh
102 A11 Binita
103 A12 Jagdish
Emp_code January
Emp_name February
Address March
Contact no. April
Date of birth May
Department June
Designation July
Basic_salary Daily_allowance
Travel_Allowance Gross_salary
Tax Provident _fund
Normalized database
In above table, we can see that column of subject nome and marks are repeated which are eliminated in
1NF.
Sita 1 12 Account 80
Hari 2 11 Computer 80
Hari 2 11 Account 82
Shyam 2 12 Computer 92
Shyam 2 13 Account 83
In above table name depends upon roll no and class, subject name only depends upon class, subject marks
depends upon name and subject_name. Hence, above table can be decomposed as 2NF:
Sub_id Subject
C1 Computer
A1 Account
Class_id Class
XI 11
XII 12
Std_id Class Roll Class_id
1 Ram 1 XI
2 Sita 1 XII
3 Hari 2 XI
4 Shyam 2 XII
Std_id Sub_id Marks
1 C1 95
1 A1 78
2 C1 98
2 A1 80
3 C1 80
3 A1 82
4 C1 92
4 A1 83
Disadvantages:
The size of centralized database is large which increases the response time of fetching data.
It is difficult to update the centralized database.
If sever gets damaged entire data will be lost.
Distributed database system:
Distributed database doesn’t store all data and information in the single but store on various sites
or places, which are connected by the help of communication, links which helps them to access
the distributed data easily.
In distributed database various portions of a database are stored in multiple different locations
along with the application procedures which are replicated and distributed among various points
in a network.
Memory
Memory
Database
Location 1
Database
Communication
Channel Location 2
Database
Memory
Advantages:
The system can be expanded by including new computers and connecting them to the
distributed system.
Distributed database is more reliable than centralized database.
The performance and service are better.
Large numbers of users are supported.
One server failure will not affect the entire data set.
Disadvantages:
It is difficult to administrate and manage the database
It is expensive to set up.
This database has high risk of hacking and data theft.
Data dictionary:
A data dictionary is a file which contains meta-data that is data about data. It also called information
system catalogue. It keeps all the data information about the database system such as location, size of
the database, tables, records, fields, user information, recovery system, etc.
Data integrity:
Data integrity referees to the validity or consistency of data in database. It ensures that the data should
be accurate and consistent.
Mainly there are 3 types of data integrity constraints used in the database system. They are as:
1. Domain integrity constraints: it defines a set range of data values for given specific data field. And
also determines whether null values are allowed or not in the data field.
2. Entity integrity constraints: it specify that all rows in a table have a unique identifier, known as the
primary key value and it never be null i.e. blank.
3. Referential integrity constrains: it exists in a relationship between the two tables in a database. It
ensures that the relationship between the primary keys in the master table and foreign key in child
table are always maintained.
Data Security:
Data security is protection of data in database system against unauthorized access, modification, failure,
losses or destruction. The authorized access means only right people can get the right access to the
right data.
DBA is the most responsible person in an organization with sound knowledge of DBMS. He/she is the
overall administrator of the program. He/she has the maximum amount of privileges for accessing
database and defining the role of the employee which use the system. The main goal of DBA is to keep
the database server up to date, secure and provide information to the user on demand.
1. He/she should have sound and complete knowledge about DBMS and its operation.
2. He/she should be familiar with several DBMS packages such as MS Access, MY SQL, Oracle etc
3. He/she should have depth knowledge about the OS in which database server is running.
4. He/she should have good understanding of network architecture.
5. He/she should have good database designing skill.
Responsibilities
The SQL statement for creating, dropping, and altering database and table
XAMPP provides a GUI environment to perform any operations on the database. However, it also
provides an option to use SQL statements to perform any operations SQL statements are used in the
SQL menu in phpMyAdmin. The SQL statements used in XAMPP also work well with most of the
databases.
Creating a database:
Syntax: CREATE DATABASE databasename;
Example: CREATE DATABASE School;
Dropping the database (deleting the database):
Syntax DROP DATABASE databasename:
Example: DROP DATABASE School:
Creating a table:
Syntax CREATE TABLE table_name (column1 datatype, column2 datatype, column3 datatype….)
Example: CREATE TABLE Students (StudentID int, FName varchar(255), LName varchar(255), Address
varchar(255), Class varchar(255));
Deleting table
DROP TABLE table_name,
SQL statement to insert, select, update and delete data
Syntax Example: DROP TABLE Students:
Inserting data
Syntax
INSERT INTO table name (column1, column2 column3,...) Example: INSERT INTO Students (StudentID,
FName, LName, Address, Class)
VALUES (valuel, value2, value3.);
VALUES ('101', 'Ram', Sharma', Pokhara', 7);
Selecting data iselecting data from a database);
Syntax SELECT column1, FROM table name column2.
Example: SELECT * FROM Students; (This will select all the columns from the table Students] SELECT
FNAME. LNAME FROM Students: [This will select only the First Name and Last
Name from the table Students.]
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
COMPUTER SCIENCE
Grade: XII
REFERENCE NOTE
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Data Transmission
Data may be transferred from one device to another by means of some communication media. The
electromagnetic or light waves that transfer data from one device to another device in encoded form are
called signals. Data transmissions across the network can occur in two forms i.e.:
a. Analog signal
b. Digital signal
Analog Signal
The transfer of data in the form of electrical signals or continuous waves is called analog signal or analog
data transmission. An analog signal is measured in volts and its frequency is in hertz (Hz).
Digital Signal
The transfer of data in the form of digit is called digital signal or digital data transmission. Digital signals
consist of binary digits 0 & 1. Electrical pulses are used to represent binary digits. Data transmission
between computers is in the form of digital signals.
Modulation
The modulation is the process of changing or encoding the carrier wave at certain amplitude (height) and
frequency (timing) is called modulation.
The process of changing some characteristics (amplitude, frequency or phase) of a carrier wave in
accordance with the intensity of the signal is known as modulation. Modulation means to change.
There are three types of modulation:
a. Amplitude Modulation (AM): Amplitude modulation is an increase or decrease of the carrier
voltage (Ec), will all other factors remaining constant.
b. Frequency Modulation (FM): Frequency modulation is a change in the carrier frequency (fc) with
all other factors remaining constant.
c. Phase Modulation (PM): Phase modulation is a change in the carrier phase angle (θ). The phase
angle cannot change without also affecting a change in frequency. Therefore, phase modulation
is in reality a second form of frequency modulation.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
destination passing several stages. The block diagram of general communication system is described
below:
C. Transmitter:
As the name suggests transmitter is responsible for transmitting and processing the electrical signals
through the communication channel. In long distance radio communication, signal amplification is
necessary for transferring data. Transmitter processes the signals such as restriction of range of audio
frequencies, amplification and modulation of signals. All these processes are done just to ease the
transmission of signals through the channel.
D. Transmission channel or channel:
Transmission channel is the transmission medium through data signals or information passes from source
to destination. It is the medium through which the message travels from the transmitter to the receiver.
It provides the connection between the sender / transmitter or receiver. Communication channel may be
wired/ guided or wireless/unguided. The wired medium or also called point to point channels where
devices are connected through the cables. Whereas wireless medium connect devices wirelessly through
electromagnetic wave signals.
Sometime unwanted signal tend to interfere with the information that unwanted signal is called noise.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
E. Receiver:
The main function of the receiver is to reproduce the message signal in electrical form from the
distorted received signal. This reproduction of the original signal is accomplished by a process known as
the demodulation or detection. Demodulation is the reverse process of modulation carried out in
transmitter.
F. Output Transducer/Destination:
The transducer presented at output side of the communication system is called output transducer. It is
responsible of converting electrical signals into non electrical signals like sound. It is also known as
destination and is responsible for converting message signals into its original form from the electrical
form. For instance, speaker is a destination or transducer in voice communication.
Data communication is the process of exchanging data among the computing devices. Data may be in
different form like file, text, image, sound etc. These data are transmitted between a source and a
destination. Source device is responsible for generating data and destination device is responsible for
receiving the data generated by source. Communication like, email, IRC, VOIP etc. are examples of data
communication. Data communication is the transmission of electronic from one computing device to
another. The data communication comprises of following elements:
1. Sender (source): It is the device that generates and sends that message.
2. Medium: It is the channel or physical path through which the message is carried from the sender
to the receiver. The medium can be wired like twisted pair wire, coaxial cable, fiber-optic cable or
wireless like laser, radio waves, and microwaves.
3. Receiver (sink): It is the device that receives the message.
4. Data: It is the information or data to be communicated. It can consist of text, numbers, pictures,
sound or video or any combination of these.
5. Protocol: It is a set of rules that govern the communication between the devices. Both the sender
and the receiver follow same protocols to communicate with each other.
Message
Protocol Protocol
Transmission medium
The data communication takes place between two devices connected together either by wired or
wireless media. The sender device generates the data message and send it through the
communication channel using some protocol. After the message is sent the receiver receives the
message using the similar protocol.
6. Encoder: The computer works with digital signals. The communicational channels usually use
analog signals. Therefore, to send data through a communication channel, the digital signals are
encoded into analog signals or into a form which can be transmitted through transmission
medium. This is called encoding. The device that carries out this function is called encoder.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
7. Decoder: The Computer works with digital signals. The communication channels usually use
analog signals. Therefore, to receive data from a communication channel, the coded analog signals
or any other encoded form is converted back to digital signals. This is called decoding. The device
that carries out this function is called decoder.
Mode of Communication
Mode of communication normally refers to the ways in which communication takes place or data gets
transmitted between source and destination nodes. Modes of data transmission direct the direction,
mechanism of data flow between devices.
1. Simplex Communication:
In this type of communication data transmission takes place only in one direction. It is also called a
unidirectional communication mode.
Radio, Television, Newspaper and keyboard to CPU Communication are some of the most common
example of simplex communication.
Features:
Data are transmitted in only one direction.
The sender sends data and receiver receives only.
There is not bidirectional communication.
Listeners cannot reply immediately.
Radio and television broadcast are its examples.
2. Duplex Communication:
In duplex communication, mode data transmission is possible from both directions. The receiver can
immediately respond to the sender. The duplex communication can be categorized into two groups.
a. Half Duplex:
In this type of communication mode data can be transmitted in both directions, but only in one direction
at a time. Both sender and receiver cannot transfer the data at a time. While sending data it cannot
receive it and while receiving data it cannot send.
Features:
Data are transmitted in both direction but single direction at one time.
Receiving end acts as mere listener while sender sends data and vice versa.
The communication is slower.
Willkie Talkie used by the police man is the best example of half-duplex communication mode.
b. Full Duplex
Full Duplex communications allows data to flow the information at the same time. Speaking on telephone
of full Duplex communication mode in which both the sender and receiver can speak simultaneously.
Bidirectional communication at the same time is called full duplex communication mode.
Features:
Data are transmitted in both direction at the same time.
When one end sends data other end can receive as well as send data.
Communication is faster.
Telephone is an example of full duplex mode.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
3 The bandwidth of LAN is The data transmission rate The data transmission rate is
high. i.e. data transmission is slower in comparison to slowest in comparison to
rate. LAN. LAN and MAN.
Transmission media:
A transmission media is defined as the means of communication between two networking devices that
helps to transfer data from sender to receiver and vice versa.
Transmission channel is the path through which data are transmitted from source to destination.
The path through which data transmit form source to destination is known as communication
media.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Coaxial Cable:
Coaxial cable is a type of copper cable specially built with a metal shield and other components
engineered to block signal interference. It is primarily used by cable TV companies to connect their
satellite antenna facilities to customer homes and businesses.
Coaxial cable contains two conductors inner and outer, which are separated by an insulator. These two
conductors lies parallel to each other. The inner conductor is made up of copper wire which is covered by
an inner insulator. The inner insulator is again covered by outer conductor or metal foil. Outer metal
wrapping is used as a protection against noise and as the second conductor which completes the circuit.
The outer conductor is covered with an insulating cover.
Advantages:
1. It is faster and reliable than twisted pair cable.
2. It can transfer data over medium range of distance.
Disadvantages
1. It is not appropriate for relatively larger distance.
2. It is expensive than twisted pair cable.
3. It is rarely used in computer network.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. Radio wave:
Radio wave are the signals ranging frequency in between 3 KHz and 1 GHz.
When the antenna transmits the radio wave; they are propagated in all directions. Due to this the
sending and receiving antenna doesn’t need to be in line of sight position. Antenna is responsible for
converting outgoing data packets into radio waves and vice-versa.
Features:
It is wireless communication technology that transmits voice or data over the air using a lower
frequency band than microwaves.
The signal is travel in up and down manner so that it can reach any place until the strength of
waves falls.
AM and FM radios and cordless phones use radio waves for transmission.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
2. Microwave:
Microwave, in contrast, have been used in data communications for a long time. They have a higher
frequency than radio wave and therefore, they can handle larger amounts of data. There are, of course,
problems with microwaves attenuation and environmental interference.
Microwave transmission is the line of sight transmission.
The transmit station must be in visible contact with the receive station.
The microwave is unidirectional.
This sets the limit on the distance between stations depending on the local geography.
The microwave is another type of electromagnetic waves that have a frequency range of 1 GHz to
300 GHz.
In this transmission, whenever the signals are transmitted through an antenna, the signals can make
narrow to focus to a particular point. And in this transmission, there is a requirement of proper
alignment of sending antenna and receiving antenna.
3. Infrared:
Infrared offers a great unbound photonic solution. Like fiber-optic cabling, infrared communications use
light. So, they are not bound by the limitations of electricity. They are normally used for short range
communication such as in communication of remote and TV, Ac etc.
Satellite Transmission:
These are the artificial satellites which are placed in the space for the purpose of communication
between different antennas available of on the earth. These artificial satellites facilitate the transmission
of signals between stations of the earth. They relays and amplifies radio telecommunication by creating
communication channel between source transmitter and destination transmitter.
Jitter:
When we make a call over internet with anyone and suddenly line drops and their voice starts
breaking up, its called jitter.
Jitter is defined as a variation in the delay of received packets.
Jitter is when there is a time delay in the sending of these data packets over your network
connection.
Singing:
Singing is the result of sustained oscillations due to positive feedback in telephone amplifiers
or amplifying circuits.
Singing may be regarded as echo that is completely out of control. This can occur at the
frequency at which the circuit is resonant.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Echo:
Echo in telephone systems is the return of a talker's voice. It is most apparent to the talker himself
or herself. Secondarily, it can also be an annoyance to the listener.
Echo is a major annoyance to the telephone user. It affects the talker more than the listener. Two
factors determine the degree of annoyance of echo: its loudness and its length of delay.
Crosstalk:
Crosstalk is a disturbance caused by the electric or magnetic fields of one telecommunication
signal affecting a signal in an adjacent circuit.
It is an effect a wire on another. One wire acts as a sending antenna and the transmission
medium acts as the receiving antenna. Just like in telephone system, it is a common experience
to hear conversation of other people in the background. This is known as cross talk.
Distortion:
Distortion is the change in the form or shape of the signal. Signals are made up of different
frequencies are composite signals.
Distortion occurs in these composite signals. Any change in a signal that alters the basic
waveform or the relationship between various frequency components is called distortion. It is
usually a degradation of the signal.
Noise:
Noise is another impairment in data communication. It is another problem of data
communication. During data communication there are some random or unwanted signals mix
up with the original signal is called noise.
Noises can corrupt the signals in many ways along with the distortion introduced by the
transmission media.
Bandwidth:
Bandwidth is the amount of data transmitted through the transmission channel at certain
period of time. High bandwidth means higher bits of data are transmitted and low bandwidth
means less bits of data are transmitted through the communication channel.
The bandwidth of analog device is measured in Hertz (Hz) and bandwidth of digital device is
measured in bps (bits per second). It is also known as data holding capacity of transmission
channel.
Receiver:
Receiver, in electronics, any of various devices that accept signals, such as radio waves, and
convert them (frequently with amplification) into a useful form. Examples are telephone
receivers, which transform electrical impulses into audio signals, and radio or television
receivers, which accept electromagnetic waves and convert them into sound or television
pictures.
Network architecture:
Network architecture refers to the various services provided by the network and it also deals with how
data is transmitted from one computer to others.
1. Client server network: An arrangement of computers to resource sharing and communicate each
other through a central device (server) to all workstations (clients) is called client server architecture
one or more computers in the network act as server which provides services to other computers which
are called clients.
The server is a high capacity high speed computer with a large memory.
Server contains the network operating system.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
The central server manages, organize, and coordinate all network clients on the network.
The most common service is provided by different servers are file services, print services,
Message services and database services.
Advantages
1. Centralized administration is possible through this network.
2. High security can be provided by suing appropriate server.
3. It is appropriate for large organization.
4. Data recovery and backup process is easier.
Disadvantages
1. If server fails whole network is affected.
2. It is expensive due to use of dedicated server.
3. It is complex to establish and manage.
4. Experienced administrator is required to operate.
2. Peer-peer network: In peer-to-peer architecture computers are connected individually in pair (one-
to-one connection). A peer-to-peer network is the type of network in which all computers in the
network act both a client and a server i.e. all computers can both request and provide services.
Each workstations act as both a client and a server.
There is no central repository for information and no central server to maintain.
Peer to peer network are generally simpler and less expensive.
A peer to peer network is also known as a distributed network.
Peer to peer computing or networking is a distributed application architecture that partitions
task or workstations between peers.
Peers are equally privileged and equal participants in the application.
Each node shares its sources with other nodes in the network.
Advantages
1. It is simple cheap and easier to set up.
2. Since there is no dedicated server, user can manage their own server.
3. Failure of a computer in a network doesn't effect the other computer in a network.
Disadvantages
1. Data security is very poor in this type of architecture.
2. Data recovery and backup is difficult.
3. It is not appropriate for large scale organization.
4. Network administration is difficult it without dedicated Server.
2. Star Topology:- Computers in the network are connected to each other with the help of central
connecting device hub or switch or server. It is based on client server architecture. It is the most
popular and widely used topology for LAN.
Advantages
- It is simple, reliable and easy to set up and re-configuration.
- It is flexible to connect new computer and remove existing computer in the network.
- It is very easy to find out fault.
- If any computer in the network goes down, then other computers can continue their functions.
Disadvantages
- It requires very large amount of cables.
- It is expensive topology.
- If there is any problem in central device hub or switch then the entire network will be down.
- The data traffic is high in central device hub.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
3. Ring Topology:- Computers are interconnected to each other by making a closed circular structure
that means each computer is connected to other two adjacent computer in either network
architecture.
5. Tree Topology:- Tree topology is the extension of bus or star topology. Data can flow from top to
bottom and vice versa.
Advantages
Reliable
Scalable
Flexible
Effective
Disadvantages
Complexity of design
Costly connecting devices
Costly infrastructure
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. Physical Layer: This layer concerned with transmission of bit it determines voltage level for 0 & 1. It
also determines the data rate of the system. This layer involves standardized protocol dealing with
electrical & signaling interface.
2. Data Link Layer: It handles error in physical layer. This layer ensures the correct delivery of frame to
the destination address. It consists of 2 parts or 2 sub-layers. i.e.
i. Logic Link Control
ii. Media Access Control
3. Network Layer: This layer is concerned with transmission of packet. N/w layer protocol chooses the
best path to send a package called routing. Two protocols are widely used in n/w layer.
i. X.25 Protocol
ii. Internet Protocol
4. Transport Layer: It provides the mechanism for the exchange of data between end systems. It ensures
that the data received is in fact in order. Following jobs are performed by this layer.
i. Port Addressing
ii. Segmentation & Reassemble
iii. Connection Control
5. Session Layer: It is responsible for requesting logical connection to be established for communication
process. This logical connection is termed as session. It also provides data synchronization between two
communication terminals.
6. Presentation layer: This layer translates format data to adapt to the needs of the application layer &
nodes at both receiving & sending end of communication process. It handles data communication,
formatting, encryption, decryption, etc.
7. Application Layer: It is the top-most layer of OSI model & provides user access to the n/w. It provides
services that support user application, such as database access, email & file transfer, etc.
5. Router:
A router transmits information from one network to another. The router selects the best path to route a
message, based on the destination address and origin. The router can direct traffic to prevent head-on
collisions and smart enough to know when to direct traffic along back roads and shortcuts.
- Direct signal traffic efficiently.
- Route message between any two protocols.
- Route message between different topologies.
- Route message across fiber optic, coaxial, and twisted-pair cabling.
6. Gateways:
Gateways are just like routers but much more complex and powerful than routers. They are slower than
router and expensive. A gateway has all the features of router and bridges but it can translate instruction
set on sending network into receiving network.
- Gateways make communication possible between different architecture and environments.
- Gateways having higher layer functionalities and works on multiple layer protocols.
7. Wi-Fi:-
The term Wi-Fi suggests wireless Fidelity. It is hardware and software devices. It is wireless technology
and network connecting device. Wi-Fi is not a technical term. The technical term of Wi-Fi is "IEEE802.11"
- It has limited range.
- Wi-Fi is used in many personal computers, video game consoles, MP3 players, smart phones, printers,
digital camera, laptops computers and other devices.
- Wi-Fi is used to create wireless LAN to connect computer system.
8. Bluetooth:
Bluetooth is a wireless technology standard for exchange data over short distance from fixed and mobile
devices. Bluetooth is used to create personal area networks (PANs) with high levels of security.
9. Infared (IR):
Infared (IR) light is electromagnetic radiation with a wavelength longer than that of visible light and below
the red light. These wavelengths correspond to a frequency range of approximately 100 GHz to 100 THz
and include most of the thermal radiation emitted by objects near room.
Internet
The Internet is an interconnected network of thousands of networks and millions of computers linking
business, education institutions, government agencies, and individuals together.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Gateway
A gateway is a network node that servers as an access point to another network, often involving not only
a change of addressing but also a different networking technology.
IP Address
An Internet Protocol address (IP Address) is an unique identification number assigned to each devices
connected in a network that uses Internet protocol for communication. The typical IP address looks like
216.27.67.137
IP address are expressed in decimal as above which is easier for us to remember, but computers
communicate in binary. So same IP address looks like
11011000.00011011.00111101.10001001
IP address has four sets of number separated by a period ( . ), These sets are Called Octets. IP address
perform mainly two functions. One is identification of Network and Identification of particular host in
that network.
MAC address
Media Access Control (MAC) address also known as hardware or physical address is unique number
associated with a network adapter (NIC). It is used to uniquely identify each device (node) of a network.
MAC address is usually assigned by the manufacturer of a network interface card (NIC) and are stored in
its ROM. All NIC developed contains unique MAC address. It is a 12 digit hexadecimal number (48 bit in
length) and are Witten in following formats.
MM:MM:MM:SS:SS:SS or MM-MM-MM-SS-SS-SS
The first half of the address contains ID number of the adapter regulated by an Internet standards body
and other half represent the number assigned by the manufacturer. For example: 00:A0:C9:14:C8:29
The prefix 00A0C9 indicates manufactures Intel Corporation and 14C829 indicates a particular host.
Intranet:
An intranet is a private network that uses internet protocols, to securely share part of an organization's
information between its employees. An intranet is a Local Area Network or Wide Area Network that uses
TCP/IP protocol but, belongs to a corporation, school, or organization.
The intranet is accessible only to the organization's workers. If the intranet is connected the Internet,
then it is secured by a firewall to prevent unauthorized users from gaining access to it.
Advantages of an Intranet
1. Workforce productivity: Employees can easily access and share information in-between their
workgroups which enhances productivity
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
2. Time: With intranets, organizations can make more information available to employees in any time.
3. Communication: Intranets can serve as powerful tools for communication within an organization.
Extranet:
An extranet is a private intranet that can be accessed by outside users over the secure channel. To gain
entrance to the extranet's resource, an external user must log on to the networks by providing a valid
user ID and password. The extranet is a combination of the public Internet and the closed intranet.
Intranet users are your own employees who know a lot Internet user know much less about
about the company, its organizational structure and your company and also care less
special terminology. about it.
The intranet is used for everyday work inside the The Internet is mainly used to find
company. out information.
Intranet can work on low and mid-bandwidth. Internet requires higher band width.
Network Tool
Network tools are used for supporting easier and effective network connections. Some of the network
tools are:
1. Packet tracer:
Packet Tracer is an innovative and powerful network simulator that can be used for a practice build
own network with routers, switches, wireless, and much more. It allows to experiment with network
behaviour, build models and to ask "what if" questions. It is used to trace the movement of data
packets in data communication. Packet Tracer provides simulation, visualization, authoring,
assessment, and collaboration capabilities to facilitate the teaching and learning of complex
technology concepts.
2. Remote login: Remote login allows a user terminal to connect to a host computer via a network or
direct telecommunications link, and to interact with that host computer as if the user terminal were
directly connected to that host computer. Remote Login is a process in which user can login into a
remote site i.e. computer, and use services that are available on the remote computer. With the help
of remote login a user can understand result of transferring result of processing from the remote
computer to the local computer.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Protocols:
A communication protocol is a formal description of digital message formats and the rules for exchanging
that message in between computer systems. Protocols define a set of formal rules describing how to
transmit data especially across a network.
1. TCP/IP (Transmission Control Protocol/Internet Protocol): TCP/IP is a layered set of protocols TCP is
reliable, but complex transport-layer protocol. It is stream connection-oriented and reliable transport
protocol. TCP/IP is the protocol used by Internet. It adds connection-oriented and reliability features. TCP
is responsible for making sure that the data is transmitted to other end. It keeps track of what is sent, and
re transmits any data that has not reached its destination. The Internet Protocol (IP) is the principal
communication protocol used for transmitting data packets across and network using the Internet
Protocol Suite. Internet exist due to TCP/IP.
2. FTP (File Transfer Protocol): This protocol is used for transferring data between client and server over
TCP/IP (Internet). Hence, it is responsible for uploading and downloading files to and from the server.
3. UDP (User Datagram Protocol): UDP is simple, connection less, unreliable transport protocol. It
performs very limited error checking. It is mainly used for transmitting multimedia data, which requires
faster transmission and error checking is not used.
4. SMTP (Simple Mail Transfer Protocol): SMTP is a standard protocol for transmitting electronic mail
(email) by the internet. It is a Internet mail protocol. It is a TCP/IP protocol used to send emails
5. POP (Post Office Protocol): POP is also a protocol for transmitting email. It is simple but has limited
functionality. It is an application layer Internet standard protocol used by clients to access e-mail from a
server over a TCP/IP connection i.e. internet. POP3 (POP version 3) is used at present. POP3 is supported
by most modern webmail services such as Gmail and Yahoomail.
6. HTTP (Hypertext Transfer Protocol): HTTP networking protocol for distributed, collaborative,
hypermedia information systems. It is used transmitting hypertext or HTML based document. It is the
foundation of data communication for the World Wide Web used by web browser to communication with
respective servers.
7. HTTPS (Hypertext Transfer Protocol Secure): HTTPS is combination of Protocol with the SSL/TLS
protocol to provide encrypted identification of a network. HTTPS connections are often used in World
Wide Web for sensitive transactions. The main objective of HTTPS is to create a secure channel over an
insecure network
Layer Protocols
Application FTP, TFTP, Telnet, Gopher, HTTP
Presentation SMTP, NFS
Session Telnet, SNMP
Trasport TCP, UDP
Network IP
Data Link ARP, RARP, RIP
Physical Ethernet, Token Ring, FDDI
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Bibliography
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
The End
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Grade: XII
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Web technology
Introduction
Web Technology is the tools and techniques which enables two or more computing devices to
communicate over a network i.e. Internet.
Web Technology consist of two words, the web refers to the World Wide Web generally known as World
Wide Web.
WWW is the cyber space containing webpages, documents, and any other resources which are identified
and located with the help of their URLs.
Technology refers to the tools and techniques that makes these resources available on the Web such as,
web browsers to view content of web, Programming languages and frameworks for the development of
websites, Database to store data at back end, protocols for communicating on the web, multimedia
elements etc.
Web development
It is the process of designing and developing website which are hosted through internet or intranet. The
process of developing web can range from developing static page to a complex such as web based
application social media sites, E-commerce.
Web development includes web design, web content development, client side scripting, server side
scripting, web engineering etc. Since, web development consists of several inter-related task which can
be accomplish by different types of developer who focuses on different aspect of web creation.
Frontend Backend
Client Side Server Side
Website Design Database
HTML PHP
CSS Java
JavaScript Python
AJAX Ruby
UI/UX Servers
Some UI technologies Some Backend technologies
Ruby .NET
Scripting Language:
JavaScript is a scripting language. A scripting language is a lightweight programming language.
JavaScript code can be inserted into any HTML page, and it can be executed by all types of web
browsers.
JavaScript is used to make web pages interactive. It runs on your visitor's computer and doesn't
require constant downloads from your website. JavaScript and Java are completely different
language, both in concept and design.
Unlike HTML, JavaScript is case sensitive-therefore watch your capitalization closely when you write
JavaScript statements, create or call variables, objects and functions.
A scripting language is a programming language designed for integrating and communicating with other
programming language. It is used in server side as well as client side. Some of the most widely used
scripting language are JavaScript, VBScript, PHP, Perl, Python, Ruby etc.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. Python: Python is a very popular and demanding programming language now because it is suitable
for developing very simple to complex applications. It is also used to connect database systems.
Python has simple English like syntax.
2. Perl: Practical Extraction and Reporting Language, first released in 1987 is a powerful language
with advance features. Perl is a stable, cross platform programming language. It is a general-
purpose programming language originally developed for text manipulation and now used for a
wide range of tasks including system administration, web development, network programming,
GUI development, and more.
3. Ruby: Ruby is a dynamic, open source programming language with a focus on simplicity and
productivity. It has an elegant syntax that is natural to read and easy to write.
4. Bash: A Bash script is a plain text file which contains a series of commands. It is widely available on
various operating systems and is a default command interpreter on most GNU/Linux systems.
5. Node.js: Node.js is used to create dynamic page contents. It can create, open, read, write, delete,
and close file on the server.
6. ASP.net: It is used to develop dynamic websites, web applications, and web services. ASP.NET is a
web application framework developed and marketed by Microsoft to allow programmers to build
dynamic web sites.
7. VBScript: Visual Basic Script (VBScript) is an open source web programming language developed
by Microsoft. It is superset of JavaScript and adds optional static typing class based object oriented
programming VBScript is lightweight scripting language. As VBScript is only used by IE browsers
JavaScript is preferred over VBScript.
8. JavaScript: JavaScript is most well-known and widely used scripting language for web pages. All
java script files are stored in file having is extension. JavaScript and Java programming language
are two different things: JavaScript is generally used for making websites interactive and dynamic.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
9. jQuery: JQuery is a JavaScript library that simplifies writing code and enables rapid web
development. JQuery simplifies HTML document traversing and manipulation, and browser event
handling. The main concept of jQuery is "write less, do more".
10. PHP: Hypertext Preprocessor (PHP) is widely used scripting language. PHP scripts are executed on
the server. It is used to manage dynamic content, databases, session tracking and building e-
commerce sites. It is integrated with a popular database MySQL.
Client-side scripting is performed to generate a code that can run on the client side i.e (front end) browser
without needing the server-side (back end) processing. Basically, client-side scripts are placed inside an
HTML document.
The client-side scripting can be used to layout the content of the web. For example, when a user makes a
request through web browser for a webpage to the server, it just sent the HTML and CSS as plain text, and
the browser interprets and renders the content of web in the client end (user).
Client-side scripting is designed to run as a scripting language which can be executed by web browser.
Front end developer is someone who design and develop client side of a website. Generally he or she
works in user interface (UI) of a website. Front end developer must be at least fluent in three different
languages i.e. HTML, CSS, JavaScript whereas, there are several other libraries which can be used for front
end development.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Server-side scripting also known as back-end runs on the server where the application is hosted. Server-
side is used to serve content depending upon the user request. Back end helps to create dynamic web
based application that allows user to interact and communicate with the application. Back end language
also helps to connect front end with data base. So that, User can store and retrieve data as per the
requirement. Back-end developer is responsible for server-side programming. Some of the popular
server-side (back-end) scripting language are ASP, JavaScript (using SSJS (Server-side JavaScript e.g.
node.js), Perl, PHP, Ruby, Python etc.
The client-side scripting emphasizes making the interface of the web application or website (UI) more
appealing and functional. Whereas, server-side scripting emphasizes on data accessing methods, error
handling and fast processing etc.
Advantages
1) You can create dynamic pages.
2) Can connect to database that resides on the web server.
3) Can access files from the server to client browser Users are not able to block the contents from
server
4) The actual code is not visible to the client
5) Authentication and verification of user is possible
6) It supports many databases like MySQL Oracle,
7) Efficient storage and delivery of information
8) Customized user experience.
9) Controlled access to content
10) Notification and communication
11) Users do not need to download plug-in like java or flash
12) The content management system (CMS) makes editing simpler
Note: Full-stack developer understand both Front end and back end development process. They can
accomplish entire project. Full stack developer must have expertise in client site and server site Scripting
language. Moreover, he/she has a great knowledge of integrating database with the application.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<head>
<title> Inline javascript Example</title>
<body>
<form>
<center><input type="button" value="ClickMe" onclick="alert('Button Clicked: ')">
</center></form>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Internet Technology
The Internet is the global system of interconnected computer networks that uses the Internet protocol
suite to communicate between networks and devices. It is a network of networks that consists of private,
public, academic, business, and government networks of local to global scope, linked by a broad array of
electronic, wireless, and optical networking technologies. The Internet carries a vast range of information
resources and services, such as the inter-linked hypertext documents and applications of the World Wide
Web, electronic mail, telephony, and file sharing.
Static Website:
Static Web pages are very simple. It is written in languages such as HTML, JavaScript, CSS, etc. Static
websites are the websites that doesn’t change the content or layout dynamically with every request to
the web server. Static websites display exactly the same information whenever anyone visits it. User
sees the updated content of Static Website only when a web author manually updates them with a text
editor or any web editing tool used for creating websites. Static webpages do not have to be simple
plain text. They can feature multiple design and even videos.
Dynamic website:
Dynamic websites are those websites that changes the content or layout with every request to the
webserver. These websites have the capability of producing different content for different visitors from
the same source code file. There are two kinds of dynamic web pages i.e. client side scripting and server
side scripting. The client-side web pages changes according to your activity on the web page. On the
server-side, web pages are changed whenever a web page is loaded.
Example: login & signup pages, application & submission forms, inquiry and shopping cart pages. A
Typical Architecture of dynamic website
There are different languages used to create dynamic web pages like PHP, ASP, .NET and JSP.
Whenever a dynamic page loads in browser, it requests the database to give information depending
upon user’s input. On receiving information from the database, the resulting web page is applied to
the user after applying the styling codes.
JavaScript
JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric
applications. It is complimentary to and integrated with Java. JavaScript is very easy to implement because
it is integrated with HTML. It is open and cross-platform.
This tutorial has been prepared for JavaScript beginners to help them understand the basic functionality
of JavaScript to build dynamic web pages and web applications.
Features
JavaScript is a lightweight, interpreted programming language.
Designed for creating network-centric applications.
Complementary to and integrated with Java.
Complementary to and integrated with HTML.
It is case sensitive language.
JavaScript is supportable in operating system.
It provides good control to the users over the web browsers.
<script>
document.write("Hello JavaScript by JavaScript");
</script>
Advantages of JavaScript
1. Less server interaction: You can validate user input before sending the page off to the server. This
saves server traffic, which means fewer loads on your server.
2. Easy to learn: By learning few commands and simple rules of syntax, you can easily build
applications using JavaScript.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
3. Immediate feedback to the visitors: They don't have to wait for a page reload to see if they have
forgotten to enter something.
4. Increased interactivity: You can create interfaces that react when the user hovers over them with
a mouse or activates them via the keyboard.
5. Quick Development: Scripts can be developed in short period of time
6. Richer interfaces: You can use JavaScript to include such items as drag-and-drop components and
sliders to give a Rich Interface to your site visitors.
7. Transmitting information: About the users' reading habits and browsing activities to various
websites. Web pages frequently do this for web analytics, ad tracking personalization or other
purposes.
8. Easy Debugging and Testing: As JavaScript is interpreted line by line, it is easy to find error and
make changes.
9. Interactive content, for example games, and playing audio and video.
10. Validating input values of a Web form to make sure that they are acceptable before being
submitted to the server.
Uses of JavaScript
Client side validation
Dynamic drop down menus.
Displaying date and time.
Displaying pop-up windows and dialog boxes
Displaying clocks.
Event handling.
Developing Mobile applications
Creating web browser based games.
Building web servers
Adding interactivity to website.
1. Embedding code:-
To add the JavaScript code into the HTML pages, we can use the <script>. .... </script> tag of the HTML that
wrap around JavaScript code inside the HTML program. Users can also define JavaScript code in
the <body> tag
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
because it completely depends on the structure of the web page that the users use.
<html>
<head>
<title> page title</title>
<script>
document.write("Welcome to Java Script Programming");
</script>
</head>
<body>
<p>In this example we saw how to add JavaScript in the head section </p>
</body>
</html>
We can also define the JavaScript code in the <body> tags or body section.
Let's understand through an example.
<html>
<head>
<title> Body Section Example</title> </head>
<body>
<script>
document.write("Welcome to Javatpoint");
</script>
<p> In this example we saw how to add JavaScript in the body section </p>
</body>
</html>
2. Inline code:-
Generally, this method is used when we have to call a function in the HTML event attributes. There are
many cases (or events) in which we have to add JavaScript code directly eg., OnMover event, OnClick, etc.
Let's see with the help of an example, how we can add JavaScript directly in the html without using
the <script>. </script> tag.
Let's look at the example.
<html>
<head>
<title> Inline code example</title> </head>
<body>
<p>
<a href="#" onClick="alert('Welcome !');">Click Me</a>
<button onclick="alert('Hello Class 12')">Click Here</button>
</p>
<p> In this example we saw how to use inline JavaScript or directly in an HTML tag.
</p> </body> </html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
3. External file:-
We can also create a separate file to hold the code of JavaScript with the (.js) extension and later
incorporate/include it into our HTML document using the src attribute of the <script> tag. It becomes very
helpful if we want to use the same code in multiple HTML documents. It also saves us from the task of
writing the same code over and over again and makes it easier to maintain web pages.
In this example, we will see how we can include an external JavaScript file in an HTML document.
Let's understand through a simple example.
<html>
<head>
<title>Including a External JavaScript File</title>
</head>
<body>
<form>
<input type="button" value="Result" onclick="display()"/>
</form>
<script src="hello.js">
</script>
</body>
</html>
Now let's create separate JavaScript file = Hello.js
function display()
{
alert("Hello Friends!");
}
JavaScript Fundamentals
Script
JavaScript statements are written within <script>…..</script>. The <script> tag alerts the browser
program to start interpreting all the statements between these tags as a script. A simple syntax of your
JavaScript will appear as follows:
Syntax: <script>
block of Statements
</script>
Statements:
JavaScript statements are composed of Values, Operators, Expressions, Keywords, and Comments. The
program consists of many statements. The statements are executed, one by one, in the same order as
they are written. It is often called JavaScript code.
var area = l*b;
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
JavaScript comments
The JavaScript comments are meaningful way to deliver message. It is used to add information about the
code, warnings or suggestions so that end user can easily interpret the code.
The JavaScript comment is ignored by the JavaScript engine i.e. embedded in the browser.
There are two types of comments in JavaScript.
1. Single-line Comment
2. Multi-line Comment
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Inner HTML
Using inner HTML, the output can be displayed into the HTML element. The innerHTML property sets or
returns the HTML content (inner HTML) of an element.
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello JavaScript!";
</script>
2. Window. Alert
Using window.alert( ), the output can be displayed into an alert box. window.confirm() and
window.prompt() are also other method to output into an alert box.
<html>
<head> <title> Display functions in Javascript </title>
</head>
<body>
<h1> Output Message with window alert</h1> <br>
<script>
alert(7+5);
</script>
</body></html>
3. Console.log
Using console.log( ), the output can be displayed into the browser console. To use console of web
browser, right click in web browser and select inspect. The console will display.
<html>
<head> <title>Display functions in Javascript </title>
</head>
<body>
<h1> Demo of console.log</h1> <br>
<script>
Console.log("7+5");
</script>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Reserved Words:
Lists of all the reserved words in JavaScript are given in the following table. They cannot be used as Java
Script variables, functions, methods, loop labels, or any object names.
Abstract Else instance of Switch
boolean enum int synchronized
break export interface this
byte extends long throw
Case False Native Throws
Catch Final New transient
Char Finally Null True
Class Float Package Try
Const For Private Type of
Continue Function Protected Var
Debugger Go to Public Void
Default If Return Volatile
Delete Implements Short While
Do Import Static With
Double In Super
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
JavaScript Variable
1. JavaScript Local variable
2. JavaScript Global variable
A JavaScript variable is simply a name of storage location. There are two types of variables in JavaScript:
local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as identifiers).
1. Name must start with a letter (a to z or A to Z), underscore ( _ ), or dollar( $ ) sign.
2. After first letter we can use digits (0 to 9), for example value1.
3. Reserved words cannot be used as names.
4. JavaScript variables are case sensitive, for example x and X are different variables.
Correct JavaScript variables
1. var x = 10;
2. var _value="Hari";
Incorrect JavaScript variables
1. var 123=30;
2. var *aa=320;
Example of JavaScript variable
Let’s see a simple example of JavaScript variable.
<html>
<head>
<title> Example of Variable </title>
<body>
<script>
var x = 10;
var y = 20;
var z=x+y;
document.write(z);
</script>
</body>
</html>
JavaScript Operators
JavaScript operators are symbols that are used to perform operations on operands. For example:
var sum=10+20;
Here, + is the arithmetic operator and = is the assignment operator.
There are following types of operators in JavaScript.
1. Arithmetic Operators
2. Comparison (Relational) Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
6. Special Operators
7. Unary Operator
8. String Operator
9. Conditional Operator
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Examples
<html>
<body>
<h2>Arithmetic Operations</h2>
<p>A typical arithmetic operation takes two numbers (or expressions) and produces a new
number.</p>
<p id="Hello"></p>
<script>
let a = 3;
let x = (100 + 50) * a;
document.getElementById("Hello").innerHTML=x; // document.write(x); OR window.alert(x);
</script>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<body>
<h1>JavaScript Operators</h1>
<h2>The + Operator</h2>
<p>The + operator concatenates (adds) strings.</p>
<script>
let text1 = "Rajesh";
let text2 = "Hamal";
let text3 = text1 + " " + text2;
document.write(text3);
</script>
</body>
</html>
<html>
<body>
<h1>JavaScript Arithmetic</h1>
<h2>The += Operator</h2>
<script>
var x = 10;
x += 5;
document.write(x);
</script>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Operator Description
1) (?:) Conditional Operator returns value based on the condition. It is like if-else.
2) , Comma Operator allows multiple expressions to be evaluated as single
statement.
3) Delete Delete Operator deletes a property from the object.
4) In In Operator checks if object has the given property
5) Instanceof checks if the object is an instance of given type
6) new creates an instance (object)
7) typeof checks the type of object.
8) Void it discards the expression's return value.
Function Definition
Before we use a function, we need to define it. The most common way to define a function in JavaScript
is by using the function keyword, followed by a unique function name, a list di parameters (that might be
empty), and a statement block surrounded by curly braces.
Syntax:
<script type="text/javascript">
function function_name (parameter-list)
{
//statements
}
</script>
Calling a Function
The code written inside a function does not execute unless it is called. To call a function somewhere later
in the script, you would simply need to write the name of that function as shown in the following code.
<html>
<title>
</title>
<head>
<script type="text/javascript">
function Hello()
{
document.write ("Hello Class 12");
}
</script>
</head>
<body>
<p>Click the following button to call the function </p>
<form>
<input type="button" onclick="Hello()" value= "Click Here">
</form>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Example 2
<html>
<body>
<script>
function showMessage()
{
document.write ("Hello Class 12");
document.write ("Good Morning");
}
showMessage()
</script>
</body>
</html>
Function Parameters
A function can take multiple parameters separated by comma. The function parameters can have value
of any data type.
<html>
<body>
<h2> Function with Parameters </h2>
<script>
var a= 3
var b= 4
add(a,b);
function add(a,b)
{
var sum=a+b;
document.write("sum of two number is="+sum); // OR alert("sum of two number is="+sum);
}
</script>
</body>
<html>
Function Return
The return statement is used to return a particular value from the function to the function caller. The
function will stop executing when the return statement is called. The return statement should be the last
statement in a function because the code after the return statement will be unreachable.
<html>
<head>
<title> Example of Function Return</title> </head>
<body>
<h1> Example of the JavaScript's return statement </h1>
<script>
var a=12;
var b= 20;
var res = fun(a, b);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
function fun(x, y)
{
var r= x*y;
return (r);
}
document.write(res);
</script>
</body>
</html>
Above program is a simple example of using the return statement. Here, returning the result of the
product of two numbers and returned the value to the function caller.
The variable res is the function caller; it calls the function fun() and passes two parameters as the
arguments of the function.
The result will be store in the res variable. Final output 240 is the product of arguments 12 and 20.
Control Structures
1. If-else
2. switch case
3. for loop
4. while loop
5. do while loop
The JavaScript if-else statement is used to execute the code whether condition is true or false. There are
three forms of if statement in JavaScript.
1. If Statement
2. If else statement
3. if else if statement
JavaScript If statement
It evaluates the content only if expression is true. The signature of JavaScript if statement is given below.
if(expression)
{
//content to be evaluated
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<head>
<title> Number to check Positive or not </title>
</head>
<body>
<script type= "text/javascript">
var num= prompt("Enter Number");
if (num>0)
{
document.write("Given number is Positive");
}
</script>
</body>
</html>
It evaluates the content whether condition is true of false. The syntax of JavaScript if-else statement is
given below.
if(expression)
{
//content to be evaluated if condition is true
}
else
{
//content to be evaluated if condition is false
}
<html>
<body>
<script>
var num= prompt("Enter Number");
if (num>0)
{
document.write("Given number is Positive");
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
else
{
document.write("Given number is Negative");
}
</script>
</body>
</html>
Let’s see the example of if-else statement in JavaScript to find out the even or odd number.
<script>
var a=17;
if(a%2==0)
{
document.write("a is even number");
}
else
{
document.write("a is odd number");
}
</script>
<html>
<body>
<script>
var num= prompt("Enter Number");
var x=num%2;
if (x==0)
{
document.write("Given number is Even");
}
else
{
document.write("Given number is Odd");
}
</script>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
if(expression1)
{
//content to be evaluated if expression1 is true
}
else if(expression2)
{
//content to be evaluated if expression2 is true
}
else if(expression3)
{
//content to be evaluated if expression3 is true
}
else
{
//content to be evaluated if no expression is true
}
Let’s see the simple example of if else if statement in JavaScript.
<script>
var a=20;
if(a==10)
{
document.write("a is equal to 10");
}
else if(a==15)
{
document.write("a is equal to 15");
}
else if(a==20)
{
document.write("a is equal to 20");
}
else
{
document.write("a is not equal to 10, 15 or 20");
}
</script>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Write a Program to input a number and check that is positive, negative or not.
<html>
<body>
<script>
var a=prompt("Enter Number");
if(a>0)
{
document.write("Number is positive");
}
else if(a<0)
{
document.write("Number is Negative");
}
else
{
document.write("Number is Zero");
}
</script>
</body>
</html>
JavaScript Switch
The JavaScript switch statement is used to execute one code from multiple expressions. It is just
like else if statement that allow us to choose only one option among the many given options. But
it is convenient than if..else..if because it can be used with numbers, characters etc.
switch(expression)
{
case value1:
code to be executed;
break;
case value2:
code to be executed;
break;
......
default:
code to be executed if above values are not matched;
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<head>
<script>
var grade='B';
var result;
switch(grade)
{
case 'A':
result="A Grade";
break;
case 'B':
result="B Grade";
break;
case 'C':
result="C Grade";
break;
default:
result="No Grade";
}
document.write(result);
</script>
</head>
</html>
<html>
<head>
<title> Switch Case Example For to find Name of the day.</title>
</head>
<body>
<script>
var n=prompt("Enter a number between 1 and 7");
switch(n)
{
case(n="1");
document.write("The day is Sunday");
break;
case(n="2");
document.write("The day is Monday");
break;
case(n="3");
document.write("The day is Tuesday");
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
break;
case(n="4");
document.write("The day is Wednesday");
break;
case(n="5");
document.write("The day is Thursday");
break;
case(n="6");
document.write("The day is Friday");
break;
default:
document.write("Invalid day");
break;
</script>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<head>
<script>
for (i=1; i<=5; i++)
{
document.write(i + "<br/>") // OR document.write(i);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
</script>
</head>
</html>
Output: 12345
JavaScript While loop:
The while loop is an entry controlled loop in which condition is checked before the execution of loop.
Syntax
while (condition)
{
// code block to be executed
}
Example, WAP to display even number from 1 to 20.
<script>
var i=2;
while (i<=20)
{
document.write(i);
i=i+2;
}
</script>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Or
<html>
<head>
<title> To find out sum of Given two numbers </title>
<script type="text/JavaScript">
function add()
{
var a,b,c;
a=Number(document.getElementaryById("first").value);
b=Number(document.getElementaryById("second").value);
c=a+b;
document.getElementaryById("answer").value=c;
}
</script>
</head>
<body>
Enter the First Numebr: <input id="first"> <br>
Enter the Second Number: <input id="second"> <br> <hr>
<button onclick="add()"> Addition </button>
<input id="answer">
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Syntax:
var object_name = { name: value1, name2: value2, nameN: valueN };
Example
<html>
<body>
<script>
var emp={id:101,name:"Ram Prasad",salary:50000}
document.write(emp.id+" "+emp.name+" "+emp.salary
document.write(emp.id+" "+emp.name+" "+emp.salary);
</script>
</body>
</html>
In the above example, object name is defined as emp and it has three properties id, name and salary. The
value of object can be accessed easily using object name period and properties name.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<body>
<h2>JavaScript Objects</h2>
<p>Creating a JavaScript Object:</p>
<p id="demo"></p>
<script>
const person = {firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue"};
</html>
<html>
<head>
< title></title>
< script>
var vehicle = {
color:"green",
weight:50,
height:5,
move:function()
{
document.write("vehicle moves");
}
};
vehicle.move();
</script>
</head>
<body>
</body>
</html>
In the above example, method is defined as move. The method can be accessed easily using
object name period and method name.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Let's see the simple example of document object that prints name with welcome message.
<script type="text/javascript">
function printvalue()
{
var name=document.form1.name.value;
alert("Welcome: "+name);
}
</script>
<form name="form1">
Enter Name:<input type="text" name="name"/>
<input type="button" onclick="printvalue()" value="print name"/>
</form>
1. getElementById( )
The document.getElementById() method returns the element of specified id. We can use
document.getElementById() method to get value of the input text. But we need to define id for the
input field.
Example
<html>
<body>
<p id="demo"></p>
<p id="try"></p>
<script>
var x="How are you"
document.getElementById("demo").innerHTML = x;
document.getElementById("try").innerHTML= " I am fine and you"
</script>
In the example above, getElementById is a method, while innerHTML is a property.
Let's see the simple example of document.getElementById() method that prints cube of the given
number.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<script>
function getcube()
{
var n=document.getElementById("number").value;
alert(n*n*n);
}
</script>
<form>
Enter No:<input type="text" id="number" name="number"/><br/>
<input type="button" value="cube" onclick="getcube()"/>
</form>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
2. getElementsByName()
The document.getElementsByName() method returns all the element of specified name. The syntax of
the getElementsByName() method is given below:
document.getElementsByName("name") Here, name is required.
Example of document.getElementsByName() method
In this example, we going to count total number of genders. Here, we are using getElementsByName()
method to get all the genders.
<script>
function totalelements()
{
var g=document.getElementsByName("gender");
alert("Total Genders:"+g.length);
}
</script>
<form>
Male:<input type="radio" name="gender" value="male">
Female:<input type="radio" name="gender" value="female">
<script type="text/javascript">
function countpara()
{
var totalpara=document.getElementsByTagName("p");
alert("total p tags are: "+totalpara.length);
}
</script>
<p>This is a pragraph</p>
<p>Here we are going to count total number of paragraphs by getElementByTagName() method.
</p>
<p>Let's see the simple example</p>
<button onclick="countpara()">count paragraph</button>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Javascript - innerHTML
The innerHTML property can be used to write the dynamic html on the html document.
It is used mostly in the web pages to generate the dynamic html such as registration form,
comment form, links etc.
Example of innerHTML property
In this example, we are going to create the html form when user clicks on the button.
In this example, we are dynamically writing the html form inside the div name having the id
mylocation. We are identifying this position by calling the document.getElementById() method.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
JavaScript Events
The change in the state of an object is known as an Event. In html, there are various events which
represents that some activity is performed by the user or by the browser. When JavaScript code is included
in HTML, JavaScript react over these events and allow the execution. This process of reacting over the
events is called Event Handling. Thus, JavaScript handles the HTML events via Event Handlers.
For example, when a user clicks over the browser, add js code, which will execute the task to be performed
on the event.
Some of the HTML events and their event handlers are:
Mouse events:
Event Performed Event Handler Description
Click Onclick When mouse click on an element
Mouseover Onmouseover When the cursor of the mouse comes over the
element
Mouseout Onmouseout When the cursor of the mouse leaves an element
Mousedown Onmousedown When the mouse button is pressed over the element
Mouseup Onmouseup When the mouse button is released over the element
Mousemove Onmousemove When the mouse movement takes place.
Keyboard events:
Event Performed Event Handler Description
Keydown & Keyup onkeydown & onkeyup When the user press and then release the
key
Form events:
Event Performed Event Handler Description
Focus onfocus When the user focuses on an element
Submit onsubmit When the user submits the form
Blur Onblur When the focus is away from a form element
Change onchange When the user modifies or changes the value of a form
element
Window/Document events
Event Performed Event Handler Description
Load Onload When the browser finishes the loading of the page
Unload onunload When the visitor leaves the current webpage, the browser
unloads it
Resize Onresize When the visitor resizes the window of the browser
Let's discuss some examples over events and their handlers.
Click Event
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<head> Javascript Events </head>
<body>
<script>
function clickevent()
{
document.write("This is Java Click Events");
}
</script>
<form>
<input type="button" onclick="clickevent()" value="Click To View"/>
</form>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
</body>
</html>
Focus Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onfocus="focusevent()"/>
<script>
function focusevent()
{
document.getElementById("input1").style.background=" aqua";
}
</script>
</body>
</html>
Keydown Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onkeydown="keydownevent()"/>
<script>
function keydownevent()
{
document.getElementById("input1");
alert("Pressed a key");
}
</script>
</body>
</html>
Load event
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<head>Javascript Events</head>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
</br>
<body onload="window.alert('Page successfully loaded');">
<script>
document.write("The page is loaded successfully");
</script>
</body>
</html>
Image Object
Form Validation
It is important to validate the form submitted by the user because it can have inappropriate values. So,
validation is must to authenticate user.
JavaScript provides facility to validate the form on the client-side so data processing will be faster than
server-side validation. Most of the web developers prefer JavaScript form validation.
Through JavaScript, we can validate name, password, email, date, mobile numbers and more fields.
In this example, we are going to validate the name and password. The name can’t be empty and password
can’t be less than 6 characters long.
Here, we are validating the form on form submit. The user will not be forwarded to the next page until
given values are correct.
<html>
<body>
<script>
function validateform()
{
var name=document.myform.name.value;
var password=document.myform.password.value;
if (name==null || name=="")
{
alert("Name can't be blank");
return false;
}
else if(password.length<6)
{
alert("Password must be at least 6 characters long.");
return false;
}
}
</script>
<body>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
if(firstpassword==secondpassword){
return true;
}
else{
alert("password must be same!");
return false;
}
}
</script>
Number Validation
Let's validate the textfield for numeric value only. Here, we are using isNaN() function.
<script>
function validate()
{
var num=document.myform.num.value;
if (isNaN(num))
{
document.getElementById("numloc").innerHTML="Enter Numeric value only";
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
return false;
}
Else
{
return true;
}
}
</script>
<form name="myform" onsubmit="return validate()" >
Number: <input type="text" name="num"><span id="numloc"></span><br/>
<input type="submit" value="submit">
</form>
JavaScript validation with image
Let’s see an interactive JavaScript form validation example that displays correct and incorrect
image if input is correct or incorrect.
<script>
function validate()
{
var name=document.f1.name.value;
var password=document.f1.password.value;
var status=false;
if(name.length<1)
{
document.getElementById("nameloc").innerHTML=
" <img src='unchecked.gif'/> Please enter your name";
status=false;
}
Else
{
document.getElementById("nameloc").innerHTML=" <img src='checked.gif'/>";
status=true;
}
if(password.length<6)
{
document.getElementById("passwordloc").innerHTML=
" <img src='unchecked.gif'/> Password must be at least 6 char long";
status=false;
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
}
Else
{
document.getElementById("passwordloc").innerHTML=" <img src='checked.gif'/>";
}
return status;
}
</script>
<form name="f1" action="#" onsubmit="return validate()">
<table>
<tr><td>Enter Name:</td><td><input type="text" name="name"/>
<span id="nameloc"></span></td></tr>
<tr><td>Enter Password:</td><td><input type="password" name="password"
/>
<span id="passwordloc"></span></td></tr>
<tr><td colspan="2"><input type="submit" value="register"/></td></tr>
</table>
</form>
JavaScript email validation
We can validate the email by the help of JavaScript.
There are many criteria that need to be follow to validate the email id such as:
<script>
function validateemail()
{
var x=document.myform.email.value;
var atposition=x.indexOf("@");
var dotposition=x.lastIndexOf(".");
if (atposition<1 || dotposition<atposition+2 || dotposition+2>=x.length)
{
alert("Please enter a valid e-
mail address \n atpostion:"+atposition+"\n dotposition:"+dotposition);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
return false;
}
}
</script>
<body>
<form name="myform" method="post" action="#" onsubmit="return validateemail
();">
Email: <input type="text" name="email"><br/>
<input type="submit" value="register">
</form>
JavaScript Programs
1. This program adds 5 numbers and writes the answer as an HTML output.
<!doctype html>
<html> <body>
<script>
var i, n=5, sum=0; arr = new Array(1, 2, 3, 5, 9);
for(i=0; i<5; i++)
sum = sum + arr[i]; document.write(sum);
</script></body></html>
2. JavaScript program to check whether a number is a prime number or not. This program does
not take input from user.
<!doctype html>
<html>
<body> <script>
var num, i, c=0;
num=9;
for(i=2; i<num; i++)
{
if(num%2==0)
{
C++;
break;
}
}
if(c==0)
document.write(num+" is a Prime Number");
else
document.write(num+" is not a Prime Number");
</script> </body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
<body>
<script>
function myFormValidate ( )
{
var name = document.myform.name.value; var password =
document.myform.password.value;
if (name==null || name=="")
{
alert("Please, Enter Name");
return false;
}
else if (password.length < 5)
{
alert ("Password must be at least 5 characters long.");
return false;
}
}
</script>
<body>
<form name = "myform" method = "post" action = "abc.php" onsubmit = "return myFormValidate ( )" >
Name: <input type = "text" name = "name"><br/>
Password: <input type = "password" name = "password"><br/>
<input type = "submit" value = "Login">
</form>
</body>
</html>
JQuery
JQuery is a fast, small, lightweight, "write less, do more", and feature-rich JavaScript library. It makes
things like HTML document traversal and manipulation, event handling animation, and Ajax much simpler
with an easy-to-use API (Application Programming Interface) that works across browsers. With a
combination of versatility and extensibility, jQuery has changed the way that millions of people write
JavaScript.
JQuery is a JavaScript library. The purpose of jQuery is to make it much easier to use JavaScript on your
website. JQuery simplifies a lot of the complicated things from JavaScript like AJAX (Asynchronous
JavaScript and XML) calls and DOM (Document Object Model) manipulation. Some of the biggest
companies which uses jQuery on the Web are
1. Google 2. Microsoft 3. IBM
Features of jQuery:
Some of important feature of jQuery are listed as follows:
1. The jQuery is very small, fast, lightweight JavaScript library
2. It is very fast and extensible.
3. It has a lot of built-in animation effects which can use directly in websites.
4. It is used to improve the performance of an application.
5. It is used to develop browser's compatible web applications effectively.
6. It uses mostly new features of new browsers.
7. It is platform-independent.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. Simple 1. Simplicity
2. Interpreted 2. Efficiency
3. Faster 3. Security
4. Open Source 4. Flexibility
5. Platform Independent 5. Familiarity
6. Case Sensitive
7. Error Reporting Advantages of PHP / what problem does it
8. Real-Time Access Monitoring solve.
9. Loosely Typed Language 1. PHP is Free
2. PHP is Cross Platform
3. PHP is widely used
4. PHP hides its complexity
5. PHP is built for Web Programming
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Introduction to PHP:
PHP is an open-source, interpreted, and object-oriented scripting language that can be executed at the
server-side. PHP is well suited for web development. Therefore, it is used to develop web applications (an
application that executes on the server and generates the dynamic page.).
Before learning PHP, you must have the basic knowledge of HTML, CSS, and JavaScript. So, learn these
technologies for better implementation of PHP.
CSS - CSS helps to make the webpage content more effective and attractive.
PHP is widely used in web development nowadays. PHP can develop dynamic websites easily. But you
must have the basic the knowledge of following technologies for web development as well.
1. HTML
2. CSS
3. JavaScript
4. Ajax
5. XML and JSON
6. jQuery
PHP is a server-side scripting language, which is used to design the dynamic web applications with MySQL
database.
1. It handles dynamic content, database as well as session tracking for the website.
2. You can create sessions in PHP.
3. It can access cookies variable and also set cookies.
4. It helps to encrypt the data and apply validation.
5. PHP supports several protocols such as HTTP (Hypertext Transfer Protocol), POP3 (Post office
Protocol-3), SNMP (Simple Network Management Protocol), LDAP (Lightweight Directory Access
Protocol), IMAP (Internet Message Access Protocol), and many more.
6. Using PHP language, you can control the user to access some pages of your website.
7. As PHP is easy to install and set up, this is the main reason why PHP is the best language to learn.
8. PHP can handle the forms, such as - collect the data from users using forms, save it into the
database, and return useful information to the user. For example - Registration form.
Weaknesses of PHP
1. PHP's main strength flexibility is also its weakness. It can be a little too forgiving of errors.
2. With no strict rules, inexperienced programmers have the freedom to create some very bad
solutions to simple problems.
3. Bad packages that got popular in the community are still reused when developers are trying
something new or rushed for time. Some of these mistakes lead to security risks.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
4. As a mature tool PHP has some legacy baggage. There are lots of internal consistencies, especially
surrounding references and values.
5. This is mostly due to updates, which add features that clash with earlier features,
6. PHP is an interpreted language, which can reduce speed.
7. PHP 7 increased performance over previous versions by a significant amount while maintaining
most language compatibility.
8. The changes didn't affect the learning curve or existing applications much while improving
performance. Still, it executes more slowly than compiled languages.
9. Scaling and maintaining PHP is a complicated endeavor.
10. Context matters a great deal in dynamically typed languages, so tracking down errors gets harder
the larger an application grows.
11. Experienced PHP developers can mitigate this problem y planning for scalability, but there's only
so much they can do to reduce maintenance issues down the road.
1. Encapsulation: This is concerned with hiding the implementation details and only exposing the
methods. It used to reduce software development complexity.
2. Inheritance: This is concerned with the relationship between classes. The main purpose of inheritance
is the re-usability.
3. Polymorphism: This is concerned with having a single form but many different implementation ways.
The main purpose of polymorphism is to simplify maintaining applications and making them more
extendable.
PHP in Object oriented programming PHP is an object oriented scripting language. It supports all of the
above principles. The above principles are achieved via:
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Basics of PHP:
Setting up the environment
To run PHP a web development is needed. This needs a PHP compatible web server and interpreter.
Package like WAMP, LAMP, and XAMP etc. can be used which includes a web server.
<?php
echo "Hello Class 12";
?>
</body>
</html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<?php
ECHO "Hello Class 12<br>";
echo "Hello Class 12<br>";
EcHo "Hello Class 12<br>";
?>
</body>
</html>
Comments in PHP
Comments are used to make code more readable. There are two types of comments –single line and multi-
line comments. A single line comments starts with // while multi-line comment begins with /* and end
with */.
<html>
<body>
<?php
// This is a single-line comment
</body>
</html>
<html>
<body>
<?php
/*
This is a multiple-lines comment block
that spans over multiple
lines
*/
?>
</body>
</html>
Loosely typed language: PHP is a loosely typed language, it means PHP automatically converts the
variable to its correct data type.
PHP Variables
A variable can have a short name (like x and y) or a more descriptive name (age, carname,
total_volume).
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Global variable
The global variables are the variables that are declared outside the function. These variables can be
accessed anywhere in the program. To access the global variable within a function, use the GLOBAL
keyword before the variable. However, these variables can be directly accessed or used outside the
function without any keyword. Therefore there is no need to use any keyword to access a global variable
outside the function.
Let's understand the global variables with the help of an example:
<?php
function local_var()
{
$num = 45; //local variable
echo "Local variable declared inside the function is: ". $num;
}
local_var();
?>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<?php
$name = "Sanaya Sharma"; //Global Variable
function global_var()
{
global $name;
echo "Variable inside the function: ". $name;
echo "</br>";
}
global_var();
echo "Variable outside the function: ". $name;
?>
o echo
o print
echo and print are language constructs, and they never behave like a function. Therefore, there is no
requirement for parentheses. However, both the statements can be used with or without parentheses.
We can use these statements to output variables or strings.
<?php
echo "<h2>PHP is Fun!</h2>";
echo "Hello world!<br>";
echo "I'm about to learn PHP!<br>";
echo "This ", "string ", "was ", "made ", "with multiple parameters."; <br> <hr>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
PHP Integer
Integer means numeric data with a negative or positive sign. It holds only whole numbers, i.e., numbers
without fractional part or decimal points.
Rules for integer:
o An integer can be either positive or negative.
o An integer must not contain decimal point.
o Integer can be decimal (base 10), octal (base 8), or hexadecimal (base 16).
o The range of an integer must be lie between 2,147,483,648 and 2,147,483,647 i.e., -2^31 to 2^31.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Example:
<?php
$dec1 = 34;
$oct1 = 0243;
$hexa1 = 0x45;
echo "Decimal number: " .$dec1. "</br>";
echo "Octal number: " .$oct1. "</br>";
echo "HexaDecimal number: " .$hexa1. "</br>";
?>
Output:
Decimal number: 34
Octal number: 163
Hexadecimal number: 69
PHP Float
A floating-point number is a number with a decimal point. Unlike integer, it can hold numbers with a
fractional or decimal point, including a negative or positive sign.
Example:
<?php
$n1 = 19.34;
$n2 = 54.472;
$sum = $n1 + $n2;
echo "Addition of floating numbers: " .$sum;
?>
Output:
Addition of floating numbers: 73.812
PHP String
A string is a non-numeric data type. It holds letters or any alphabets, numbers, and even special characters.
String values must be enclosed either within single quotes or in double quotes. But both are treated
differently. To clarify this, see the example below:
Example:
<?php
$company = "Javatpoint";
//both single and double quote statements will treat different
echo "Hello $company";
echo "</br>";
echo 'Hello $company';
?>
Output:
Hello Javatpoint
Hello $company
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
PHP Array
An array is a compound data type. It can store multiple values of same data type in a single variable.
Example:
<?php
$bikes = array ("Royal Enfield", "Yamaha", "KTM");
var_dump($bikes); //the var_dump() function returns the datatype and values
echo "</br>";
echo "Array Element1: $bikes[0] </br>";
echo "Array Element2: $bikes[1] </br>";
echo "Array Element3: $bikes[2] </br>";
?>
Output:
array(3) { [0]=> string(13) "Royal Enfield" [1]=> string(6) "Yamaha" [2]=> string(3) "KTM" }
Array Element1: Royal Enfield
Array Element2: Yamaha
Array Element3: KTM
PHP object
Objects are the instances of user-defined classes that can store both values and functions. They must be
explicitly declared.
Example:
<?php
class bike {
function model() {
$model_name = "Royal Enfield";
echo "Bike Model: " .$model_name;
}
}
$obj = new bike();
$obj -> model();
?>
Output:
Bike Model: Royal Enfield
PHP Resource
Resources are not the exact data type in PHP. Basically, these are used to store some function calls or
references to external PHP resources. For example - a database call. It is an external resource.
This is an advanced topic of PHP, so we will discuss it later in detail with examples.
PHP Null
Null is a special data type that has only one value: NULL. There is a convention of writing it in capital letters
as it is case sensitive.
The special type of data type NULL defined a variable with no value.
Example:
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<?php
$n = NULL;
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
PHP Operators
PHP Operator is a symbol i.e used to perform operations on operands. In simple words, operators are used
to perform operations on variables or values. For example:
$num=10+20; //+ is the operator and 10,20 are operands
In the above example, + is the binary + operator, 10 and 20 are operands and $num is variable.
PHP Operators can be categorized in following forms:
1. Arithmetic Operators
2. Assignment Operators
3. Bitwise Operators
4. Comparison Operators
5. Incrementing/Decrementing Operators
6. Logical Operators
7. String Operators
8. Array Operators
9. Type Operators
10. Execution Operators
Arithmetic Operators
The PHP arithmetic operators are used to perform common arithmetic operations such as addition,
subtraction, etc. with numeric values.
Operator Name Example Explanation
+ Addition $a + $b Sum of operands
- Subtraction $a - $b Difference of operands
* Multiplication $a * $b Product of operands
/ Division $a / $b Quotient of operands
% Modulus $a % $b Remainder of operands
** Exponentiation $a ** $b $a raised to the power $b
Assignment Operators
The assignment operators are used to assign value to different variables. The basic assignment operator
is "=".
Operator Name Example Explanation
= Assign $a = $b The value of right operand is
assigned to the left operand.
+= Add then Assign $a += $b Addition same as $a = $a + $b
-= Subtract then Assign $a -= $b Subtraction same as $a = $a - $b
*= Multiply then Assign $a *= $b Multiplication same as $a = $a * $b
/= Divide then Assign $a /= $b Find quotient same as $a = $a / $b
(quotient)
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Bitwise Operators
The bitwise operators are used to perform bit-level operations on operands. These operators allow the
evaluation and manipulation of specific bits within the integer.
Operator Name Example Explanation
& And $a & $b Bits that are 1 in both $a and $b are set to 1, otherwise 0.
| Or (Inclusive or) $a | $b Bits that are 1 in either $a or $b are set to 1
^ Xor (Exclusive or) $a ^ $b Bits that are 1 in either $a or $b are set to 0.
~ Not ~$a Bits that are 1 set to 0 and bits that are 0 are set to 1
<< Shift left $a << $b Left shift the bits of operand $a $b steps
>> Shift right $a >> $b Right shift the bits of $a operand by $b number of places
Comparison Operators
Comparison operators allow comparing two values, such as number or string. Below the list of comparison
operators are given:
Operator Name Example Explanation
== Equal $a == $b Return TRUE if $a is equal to $b
=== Identical $a === $b Return TRUE if $a is equal to $b, and they are of same
data type
!== Not identical $a !== $b Return TRUE if $a is not equal to $b, and they are not
of same data type
!= Not equal $a != $b Return TRUE if $a is not equal to $b
<> Not equal $a <> $b Return TRUE if $a is not equal to $b
< Less than $a < $b Return TRUE if $a is less than $b
> Greater than $a > $b Return TRUE if $a is greater than $b
<= Less than or $a <= $b Return TRUE if $a is less than or equal $b
equal to
>= Greater than $a >= $b Return TRUE if $a is greater than or equal $b
or equal to
<=> Spaceship $a <=>$b Return -1 if $a is less than $b
Return 0 if $a is equal $b
Return 1 if $a is greater than $b
Incrementing/Decrementing Operators
The increment and decrement operators are used to increase and decrease the value of a variable.
Operator Name Example Explanation
++ Increment ++$a Increment the value of $a by one, then return $a
$a++ Return $a, then increment the value of $a by one
-- Decrement --$a Decrement the value of $a by one, then return $a
$a-- Return $a, then decrement the value of $a by one
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Logical Operators
The logical operators are used to perform bit-level operations on operands. These operators allow the
evaluation and manipulation of specific bits within the integer.
Operator Name Example Explanation
And And $a and $b Return TRUE if both $a and $b are true
Or Or $a or $b Return TRUE if either $a or $b is true
Xor Xor $a xor $b Return TRUE if either $ or $b is true but not both
! Not ! $a Return TRUE if $a is not true
&& And $a && $b Return TRUE if either $a and $b are true
|| Or $a || $b Return TRUE if either $a or $b is true
<?php
$name=$_GET["name"];//receiving name field value in $name variable
echo "Welcome, $name";
?>
The data passed through post request is not visible on the URL browser so it is secured. You can send large
amount of data through post request.
Let's see a simple example to receive data from post request in PHP.
File: form1.html
<html>
<head> <title> Post Method </title>
</head>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<body>
<form action="login.php" method="post">
<table>
<tr><td>Name:</td><td> <input type="text" name="name"/></td></tr>
<tr><td>Password:</td><td> <input type="password" name="password"/></td></tr>
<tr><td colspan="2"><input type="submit" value="login"/> </td></tr>
</table>
</form> </body> </html>
File: login.php
<?php
$name=$_POST["name"];
$password=$_POST["password"];
echo "Welcome: $name, your password is: $password";
?>
PHP Programs
1. Write a php code to enter your name and display it.
<html>
<head>
<title> Your name </title>
</head>
<body>
<B> Enter your Name</B> <br/>
<form method="POST">
<input type="text" name="name"/> <br/>
<input type="submit" value="submit"/>
</form>
<?php
$name=$_POST['name'];
echo "Your Name=$name";
?>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
</body>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<html>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
<form method="POST">
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Database Connectivity
Database: To organize the data in systematic and manageable form, the database is required. The
database is the system where data and information are stored and organized systematically.
The stored data can be retrieved easily when required.
Data are stored in tabular form.
The number of columns and rows forms the table.
The column of the table is known as a field that has a unique field name and the row of the table is known
as records which represent individual information. Each table has a unique field known as a primary key.
Each of the records of the primary field is different which make distinct from other records for
identification.
MySQL is the most popular database system used with PHP. With PHP, we can connect to and manipulate
MYSQL databases. It is a database system used on the web that runs on a server. It can be used for
organized databases for both small and large applications. It is comparatively more fast, reliable, and easy
to use than other databases. It uses standard SQL and compiles on a number of platforms.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = new mysqli($servername, $username, $password);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
COMPUTER SCIENCE
Grade: XII
PROGRAMMING IN C
REFERENCE NOTE
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. Write a program to input any three numbers and find out which one is largest numbers.
2. Write a program to display day using the switch statement depending upon the number entered.
i.e. input 1 for Sunday, 7 for Saturday.
3. Write a program to input a number and check whether it is prime or not.
4. Write a program to display the sum of even and odd numbers from 1 to 50.
5. Write a program to accept the age of 10 different employees and count the number of employee.
a. Whose age is more than or equal to 60
b. Whose age is less than 35
6. Write a program to enter elements for 3x3 matrixes and Display its sum.
7. Write a program to accept 10 different numbers in array and sort in descending order.
8. Write a program to input a number and find out that number is palindrome or not.
9. Write a program to input the names of N numbers of students and sort them in alphabetical order.
10. Write a program to read a number and make the sum of individual digits and print using recursion
technique.
11. Write a program that reads different names and address into the computer and rearrange the
names into alphabetical order using the structure variables.
12. Write a program to read N students record store them in data file and display the content in
appropriate format by using fprintf and fscanf function.
Unit 4- Programming in C
What is C? Explain its development process.
C is a high level language because no need for any architecture knowledge in normal English form.
C is a compiler because it can translate the whole program at a time so we can call compiler. C is structured
programming language. It is called also procedural oriented programming language, function oriented
language, module programming language. It is simple, reliable and easy to use.
What are the features of C? What are its advantages and disadvantages?
C is a computer language and a programming tool which has grown popular because programmers
preferred it. It is a tricky language but a masterful one.
The C programming languages has the following features:
i) It has small size.
ii) It has extensive use of function call.
iii) It is a strong structural language having powerful data definition methods.
iv) It has low level (Bit Wise) programming available.
v) It can handle low level activities.
vi) Pointer makes it very strong for memory manipulations.
vii) It has level constructors.
viii) It can produce efficient programs.
ix) It can be complied on variety of computers.
Advantage of C language
It is machine independent programming language.
It is easy to learn and implement C language.
It can be implemented from mobile device to mainframe computers.
It is the mother of all modern programming language.
Disadvantage of C Language
There is no runtime checking.
It has poor error detection systems.
On large programs, it is hard to fix errors.
It does not support modern programming methodologies oriented programming language.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Upper case and lowercase are allowed but not same, i.e. Text not same as text.
Only one special character underscores (_) will used.
For example, int a_b; Where a and _b are valid identifiers.
Keywords:-
Keywords are the reserved words which have standard, predefined meaning in C language. Keywords
cannot be used as names for the variables or other user defined program elements. There are 32 keywords
available in C. common examples are as follows.
auto double if static break else int
struct case enum long switch char extern
const float near typedef register union continue
far return unsigned default for short void
do goto signed while
Tokens:
In a C source code, the basic element recognized by the compiler is known as tokens. A token is source-
program text that the compiler does not break down into components elements.
The keywords like int, float, if, for etc.
Identifiers like main, printf, void etc.
Constants like a,b,c etc.
String literals like name, address, phone etc.,and
Operators like &&, ! etc.
Punctuation characters such as [ , ] , { , } , ( , ) , ; , : are also tokens.
2) Explain data types used in programming with examples.
Data types:
It is the set of keywords to declare variables. A set of data that specifies the possible range of values in a
program and stored in memory are called data types. Data types are used to define variables before use it.
Types of data types in C.
1) Primary data types
2) Secondary data types
Primary Data Types: The basic fundamental of data having unit feature on C programming is called Primary
Data Type. Example
Data Type Type Memory Require Format Specifies
Char Character 1 byte %C
Int Integer 4/2 byte %d
Float Floating point number 4 byte %f
Long Floating number 4 byte %ld
Double Large floating point number 8 byte %lf
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Format Specifier: The output and input data are display and receive in specific pattern. Format
specifier uses the token % and character(s) after it. It is used to format for all types of data i.e.
integer, float, character and string.
Format Specifier Used by scanf() function
%d , % i Signed integer + or – number o to 9
%f Scans floating point numbers.
%s String, Collection of character i.e. word
%c Character, one single key stroke.
Operator:
An operator is a symbol that operates on a certain data type. The operator generally remains between the
two operands. An expression is a combination of variables, constants, and operators written according to
the syntax of the language. The data items that operators act upon are called operands.
Types of operator
1. Arithmetic Operator(Binary Operator)
2. Relational Operator (Comparison Operator)
3. Logical Operator (Boolean Operator)
4. Assignment Operator
5. Increment and Decrement Operators (Unary Operator)
6. Conditional Operator (Ternary Operator)
7. Bitwise Operator
8. Comma Operator
9. Size of Operator
1. Arithmetic Operator
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
The arithmetic operators perform arithmetic operations and can be classified into unary and binary
arithmetic operations. The arithmetic operators can operate on any built-in data type. A list of arithmetic
operators and their meanings are given below:
Operator Meaning
+ additional or unary plus
- subtraction or unary minus
* multiplication
/ division
% modulo division (returns remainder after division)
2. Relational Operator
The relational operators help to compare two similar quantities and depending on their relation, take some
decisions. If the condition is true, it evaluates to an integer 1 and zero if the condition is false. The basic
types of relational operator are:
Operator Meaning
< less than
> greater than
<= less than or equal to
>= greater than or equal to
== equal to
!= not equal to
3. Logical Operator
The logical operators are used to give logical value either true or false. They compare or evaluate logical
and relational expressions. There are three logical operators.
Operator Meaning Examples
&& Logical AND (a>b) && (a>c)
|| Logical OR (a>b) || (a>c)
! Logical NOT !(a==b)
4. Increment and Decrement Operators:
The increment and decrement operators are very commonly used in C language. The increment operators
and decrement operators are extensively used in the loops using structures such as for, while, do, etc. The
syntax of the operators is given below.
++<variable name> Pre increment
--<variable name> Pre decrement
<variable name>++ Post increment
<variable name)-- Post decrement
The pre increment operator increases the value of the variable by 1 and then the processing does whereas
post increment first processes and increase the value of it by 1.
5. Conditional Operator:
A conditional operator is very rarely used. This can be carried out with the conditional operator (? : ) An
expression that makes use of the conditional operator is called a conditional expression. This can replace
the if-else statement. The syntax of conditional operator is:
During evaluating the conditional expression, expression_1 is evaluated at the first step. If expression_1 is
true (nonzero), then expression_2 is evaluated and this becomes the value of the conditional expression.
Library function:
The special functions that are well defined in C programming languages are called library functions such as
printf(), scanf(),strlen(), sqrt(), tolower(), toupper(), getchar(), putchar() etc.
Control Structure:
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Control structures are those programming constructs which control the flow of program statements
execution in a program. Types of Control Structure
i) Branching / Decision ( Selective Control Structure)
ii) Looping (Repetitive Control Structure)
iii) Jumping (Unconditional Control Structure)
1. Decision (Selective) Control Structure
It is mainly used for decision making. It is also called conditional statements. Selection is made on
the basis of condition. We have options to go when the given condition is true or false. The flow of
program statements execution is totally directed by the result obtained from checking condition.
Types
a) Conditional Statements
i. if statements:
It is used to execute an instruction or block of instructions only if a condition is fulfilled.
Syntax,
if(condition)
{
Statements;
}
E.g. WAP to read a number and find even or odd by using if().
#include<stdio.h>
#include<conio.h>
void main()
{
int a,r;
printf("enter the number");
scanf("%d",&a);
r=a%2;
if(r==0)
{
printf("number is even %d",a);
}
if(r!=0)
{
printf("number is odd %d",a);
}
getch();
}
ii. if else statements
If the condition is true then the if() portion statements are evaluated otherwise else part of the
statements are evaluated.
Syntax,
if( condition)
{
Block of statements;
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
else
{
Block of statements;
}
E.g. WAP input any two numbers and display the largest one.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
printf("enter the number");
scanf("%d",&a);
printf("enter the number");
scanf("%d",&b);
if(a>b)
{
printf("A is greatest number",a);
}
else
{
printf("B is greatest number",b);
}
getch();
}
iii. if() else if() statements
When we have two or more condition to be checked in a series we can use if else if statement. It is
also known as multiple conditional statement or multipath conditional statement /if else ladder.
Syntax,
if(conditiona 1)
{
Statements 1;
}
else if(condition 2)
{
Statement 2;
}
else if(condition n-1)
{
Statement n-1;
}
else
{
Statement n;
}
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
e.g. WAP to find the largest number among three input number .
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
printf("\n Enter any three number");
scanf("%d",&a,&b,&c);
if(a>b&&a>c)
{
printf("\n Largest number is %d",a);
}
else if(b>a&&b>c)
{
printf("\n Largest number is %d", b);
}
else
{
printf("\n Largest number is %d",c);
}
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Percentage division
p>=75 distinction
p>=60 and <75 first
p>=45 and <60 second
p>=35 and <45 third
otherwise failed
#include<stdio.h>
#include<conio.h>
Void main()
{
int eng,nep,comp,acc,eco,total;
Float per;
printf("Enter the five subject mark");
scanf("%d %d %d %d %d",&eng,&nep,&comp,&acc,&eco);
total=eng+nep+comp+acc+eco;
per=total/5;
if(eng>=35&&nep>=35&&comp>=35&&acc>=35%%eco>=35)
{
if(per>=75)
{
printf("\n Distinction");
else if(per>=60)
{
printf("\n First");
}
else if(per>=45)
{
printf("\n Second");
}
else
{
printf("\n Third");
}
}
else
{
printf("\n You are failed");
}
getch();
}
Syntax,
Switch(expression 1)
{
Case condition 1:
Statements ….
break;
.
.
Case condition n-1:
Statements…….
break;
default:
statement n;
}
E.g. WAP which reads any two integer values from user and calculates sum, difference and
product using switch case statement.
#include<stdio.h>
#include<conio.h>
Void main()
{
int a,b,c,ch;
printf("enter the two number");
Scanf("%d",&a,&b);
printf("\n 1. Sum");
printf("\n 2. Difference");
printf("\n 3. Product");
printf("\n Enter your choice");
Scanf("%d",&ch);
switch(ch)
{
case 1:
c=a+b;
Printf("\n Sum of two number is %d,c);
break;
case 2:
c=a-b;
printf("\n difference of two number is %d,c);
break;
case 3:
c=a*b;
printf("\n product of two number is %d,c);
break;
default:
printf("\n Wrong choice");
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
getch();
}
1. Looping Statement
The looping statement is also called repetitive or iterative control structure. Looping statements are the
conditional control flow statements that repeats a certain portion of the program either a specified
number of times or until a particular condition is satisfied or true.
Types of loop
i) For Loop ii) While Loop iii) Do while Loop
1. For Loop:-
The execution of for loop until the condition is true. The for loop is a entry control loop because it
checks the condition at entry point.
Syntax,
for( initialization; condition; increment/ decrement)
{
// statements
}
1. Write a program to print the natural number from 1 to 10.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=10;i++)
{
printf("/n%d",i);
}
getch();
}
2. Write a program to display even number from 1 to 20 and display their sum also.
#include<stdio.h>
#include<conio.h>
void main()
{
int i, s=0;
for(i=1;i<=20; i=i+2)
{
printf("/n even number are %d",i);
s=s+i;
}
printf("sum of even number is %d", s);
getch();
}
3. Write a program to find out sum of the cubes of first 10 numbers.
# include<stdio.h>
# include<conio.h>
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
void main()
{
int i,c, sum=0;
for(i=1;i<=10;i++)
{
c=i*i*i;
sum=sum+c;
}
printf("/n sum of cube is %d", sum);
getch();
}
When for loop is declared inside another for loop is called nested for loop. The life of the inner for loop
is depending over the outer for loop. If the outer for loop condition is true then inner for loop is
evaluated. And will executes all the statements until condition is true if the inner for loop to be false
then the outer for loop condition is reevaluated and so on.
For example for( initialization; condition; increment/ decrement)
{
for( initialization; condition; increment/ decrement)
{
// statemetns
}
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
# include<stdio.h> # include<stdio.h>
# include<conio.h> # include<conio.h>
void main() void main()
{ {
int R,K; int R,K;
for (R=1;R<=5; R++) for (R=5;R<=1; R++)
{ {
for (K=10;K<=50;K=K+10) for (K=1;K<=R;K=K++)
{ {
printf("\n %d",K); printf("\n %d",R);
} }
printf("\n"); printf("\n");
} }
getch(); getch();
} }
While Loop:-
The while loop is also a entry control loop. While loop first checks whether the initial condition is
true or false and finding it to be true, it will enter the loop and execute the statement.
Syntax,
initialization;
while(condition)
{
// statement
increment/decrement
}
1. Write a program to print even number from 1 to 100.
# include<stdio.h>
# include<conio.h>
void main()
{
int i;
i=2
while<i<=100)
{
printf("%d\t", i)
i=i+2;
}
getch();
}
Do while loop:-
This loop is an exit control loop. This loop runs at least the once even though the termination
condition is set to false. This loop test the condition at exit point hence it is called exit control loop.
The syntax of the loop is similar to while loop.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
initialization;
do
{
// statement
increment/decrement
} while(condition);
1. Write a program to display odd number from 100 to 1.
# include<stdio.h>
# include<conio.h>
void main()
{
int i;
i=99;
do
{
printf("%d\t",i);
i=i-2;
}while(i>=0);
getch(); }
2. Write a program to read the employee name, address for the N employee and display by
using while loops.
# include<stdio.h>
# include<conio.h>
void main()
{
int num;
char ename[20],eadd[30];
printf("\n enter the how many employee number");
scanf("%d",& num);
while(num>0)
{
printf("\n enter the name, address");
scanf("%s%s",ename,eadd);
num=num-1;
printf("%s%s",ename,eadd);
}
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
{
if(num==7)
{
continue;
}
printf("%d",num);
}
getch();
} OUTPUT: 1,2,3,4,5,6,8,9
Go to statement:
The goto statement is used to send the pointer to the specified label. If the label is not
defined then the goto statement will not work.
# include<stdio.h>
# include<conio.h>
void main()
{
int num;
Lab:
printf("Enter a number");
scanf("%d", &num);
if(num<100)
{
printf("Mark can't be less then 100");
goto Lab:
}
else
{
printf("Valid mark");
}
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. WAP to input any value and display the that value in reverse order.
# include<stdio.h>
# include<conio.h>
void main()
{
int i,r,n,x;
printf("enter a number");
scanf("%d",&n);
x=0;
while(n>0)
{
r=n%10;
x=x*10+r;
n=n/10;
}
printf("/n reverse number is%d",x);
getch();
}
2. WAP to input positive number and find its factorial number.
# include<stdio.h>
# include<conio.h>
void main()
{
int i,n,f;
printf("enter a number");
scanf("%d", &n);
if (n>0)
{
f=1;
for(i=n;i>=1;i--)
{
f=f*i;
}
printf("/n The factorial value is %d",f);
}
else
{
printf("/n it is not a positive number");
}
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
3. WAP to display the Fibonacci series. 1 1 2 3 5 8 13 ................... n.
#include<stdio.h>
#include<conio.h>
void main()
{
Int i,n;
int x,y,z;
x=0,y=1,z=0;
printf("Enter the number");
scanf("%d",&n);
for(i=1;i<n;i++)
{
printf("%d",z);
z=x+y;
x=y;
y=z;
}
getch();
}
4.WAP read a number and to check the number is prime or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,num;
i=2;
printf("Enter the number");
scanf("%d",&num);
while(i<=num-1)
{
if(num%i==0)
{
printf("Not a prime number");
break;
}
i++;
}
printf("number is prime");
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
5.WAP to find out even number from 1 to 100 and find their sum also.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0;
for(i=2; i<=100;i+2)
{
printf("\n Even number are %d",i);
sum=sum+i;
}
printf("\n Sum of even numbers is %d",sum);
getch();
}
6.WAP to input a number and find out that number is palindrome or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,n,r,x;
x=0;
printf("\n Enter the any number");
scanf("%d",&n);
a=n;
while(n>0)
{
r=n%10;
x=x*10+r;
n=n/10;
}
if(a==x)
{
printf("Number is palindrome");
}
else
{
printf("Number is not palindrome");
}
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
7.WAP to input a positive number and find out the sum of its individual digits.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,r;n,x;
printf("\n Enter a number");
scanf("%d",&n);
if(n>0)
{
x=0;
while(n>0)
{
r=n%10;
x=x+r;
n=n/10;
}
printf("\n the sum of digits is %d",x);
}
else
{
printf("\n It is not a positive number");
}
getch();
}
8.WAP to input a number and check it is Armstrong number or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,r,n,x,a;
printf("Enter a number");
scanf("%d",&n);
a=n;
if(n>0)
{
x=0;
while(n>0)
{
r=n%10;
x=x+r*r*r;
n=n/10;
}
if(a==x)
{
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
printf("\n Armstrong number is %d",a);
}
else
{
printf("\n Number is not Armstrong %d",a);
}
}
else
{
printf("\n It is not positive number");
}
getch();
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
{
printf("\t%d",j);
}
getch();
}
11.WAP to display all perfect square numbers from 100 to 500.
#include<stdio.h>
#include<conio.h>
void main()
{
int s,t;
printf("The square numbers between 100 to 500 are");
for(s=100;s<=500;s++)
{
for (t=1;t<=s;t++)
{
if(s==t*t)
{
printf("%d x %d = %d \n",s,s,t);
}
}
getch();
}
Arrays and String Function:
Arrays : An array is a collection of data of the similar type all of which are referred by a single variable
name. for example, instead of using 50 individual variables to store name of 50 students, we can use an
array to store name of 50 students.
Advantage of arrays.
- It is easier for handling similar types of data in a program.
- It is efficient for solving problems like sorting, searching, indexing etc.
- It is easier to solve matrix related problems.
- Graphics manipulations can be easily be done using array.
Disadvantages of arrays.
- It is not possible to hold dissimilar type of data in an array.
- It is difficult to visualize the multi dimensional array.
- It is static in nature so it is difficult to define the size of array during running time.
There are two types
1. One/signal dimensional: The values on an array variable assigned in one row and more than one
column are called signal dimensional array.
Syntax: type array_name[max. size];
Example int n[10];
int age[]= {18,12,19,20,16,16,17};
2. Two/Double dimensional: Two dimensional arrays are capable of storing data in multiple row and
columns.
Syntax: type array_name[No.Rows] [No.Cols];
Example int n[10][5];
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
int matrix[3][3]= {{0,1,2},{3,4,5},{6,7,8}};
Program: Write a program to read 50 students marks and display them.
#include<stdio.h>
#include<conio.h>
void main( )
{
int i, M[50];
printf("Enter the 50 student Marks"):
for(i=1; i<=50; i++)
{
scanf("%d",&M[i]);
}
printf("The numbers are:");
for(i=1; i<=50; i++)
{
printf("%d\t",M[i]);
}
}
Program: Write a program to input 5 numbers with constant values initialization in array to display the
sum.
#include<stdio.h>
#include<conio.h>
void main( )
{
int i,sum=0;
int num[5]={5,10,15,20,25};
for(I=0;I<5;I++)
{
printf("%d\t",num[i]);
sum=sum+num[I];
}
printf("\n Sum of 5 numbers is:%d",sum);
getch();
}
Program: Write a program to input the age of 20 students and count the number of students having age
in between 20 to 25.
#include<stdio.h>
#include<conio.h>
void main()
{
int i, age[10],c=0;
for(i=0;i<20;i++)
{
printf("enter age of students:");
scanf("%d",&age[I]);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
}
for(i=0;i<20;i++)
{
if(age[i]>=20&& age[i]<=25)
{
c++;
}
}
printf("Total number of students having age between 20 to 25 is %d",c);
getch();
}
Program: Write a program to find the largest number among 'n' numbers.
#include<stdio.h>
#include<conio.h>
Void main()
{
int i, n, num[100],max;
printf("\n Enter the size of array not more than 100");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("Enter array elements");
scanf("%d",&num[i])
}
max=num[0];
for(i=1;i<n;i++)
{
if(num[i]>max)
{
max=num[i];
}
}
printf("\n Largest number in array is %d",max);
getch();
}
Program: Write a program to read a matrix, store it in array and display it.
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr();
int I,J, matrix[3][4];
printf("Enter a matrix of 2x4:\n\n");
for(I=1; I<=3; I++)
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
{
for(J=1; J<=4; J++)
{
scanf("%d",&matrix[I][J]);
}
}
Printf("\n The elements of matirx are: \n\n"):
for(I=1; I<=3; I++)
{
for(J=1; J<=4; J++)
{
printf("%d\t",matrix[I][J]);
}
printf("\n");
}
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
int count2=0;
int i;
for (i=1; i<=10; i++)
{
printf("Enter the ages");
scanf("%d", &age[i]);
}
for (i=1; i<=10; i++){
if (age[i]>=60)
{
count1++;
}
else
{
if(age[i]<=35)
{
count2++;
}
}
}
printf("Employees above or equal to 60 %d",count1);
printf("Employees under or equal 35 %d",count2);
}
Program: Write a program to store N numbers in array and print out the sum with the entire array
variable.
# include<stdio.h>
# include<conio.h>
void main( )
{
int j, sum=0;
int n,num[10];
clrscr();
printf("Enter the how many no. you want to enter"):
scanf("%d",&n);
for (j=1; j<=n; j++)
{
printf("number stored %d",num[i]);
sum=sum+num[j];
}
printf("\n Sum is %d",sum);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Program: Write a program to accept 10 different numbers in array and sort in descending order.
# include<stdio.h>
# include<conio.h>
void main( )
{
clrscr( ):
int array[10];
int i, j ;
for (i=1; i<=10; i++)
{
printf(" Enter the data serially);
scanf("%d",&array[i]);
}
int temp;
for( i=1; i<=10; i++)
{
for (j=i+1; j<=10; j++)
{
if (array[i] < array[j])
{
Temp=array[i];
array[i]=array[j];
array[j]= temp;
}
}
}
printf("Sorting data in descending order\n");
for( i=1; i<=10; i++)
{
printf("%d\n",array[i]);
}
}
Program: Write a program to store twelve numbers in double dimensional array and print out the values
in table with row wise addition.
# include<stdio.h>
# include<conio.h>
void main( )
{
int j, k;
int num[3][4]={1,2,3,4,8,10,11,5,9,6,2,8}
clrscr();
printf("Data stored \t\t sum\n");
for (j=1; j<=3; j++)
{
int sum=0;
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
for (k=1; k<=4; k++)
{
printf("%d \t",num[j][k]);
sum=sum+num[j]+[k];
}
printf("=%d',sum);
printf('\n");
}
}
Program: WAP to enter elements for 2x2 matrix and display its transpose.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int a[2][2];
int i,j;
printf("\n Enter number for 2x2 matrices");
for(i=0;i<2;j++)
{
for(j=0;j<2;j++)
{
printf("Enter number");
scanf("%d",&a[i][j]);
}
}
printf("\n Transpose of Matrix is");
for(i=0;i<2;j++)
{
for(j=0;j<2;j++)
{
printf("%d",a[i][j]);
}
printf("\n");
}
getch();
}
Program: WAP to enter elements for 3x3 matrix and display its sum.
#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
int m1[3][3], m2[3][3],
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
int i,j;
printf("\n Enter number for 2x2 matrices");
for(i=0;i<3;j++)
{
for(j=0;j<3;j++)
{
printf("Enter number for first matrix");
scanf("%d",&m1[i][j]);
}
}
for(i=0;i<3;j++)
{
for(j=0;j<3;j++)
{
printf("Enter number for Second matrix");
scanf("%d",&m2[i][j]);
}
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
printf("\n string=%s",n);
printf("\n length=%d",length);
}
2. strrev( ): It helps to reverse the character of the string.
Syntax:strrev(string);
3. strupr( ): It converts lowercase letters in string to uppercase.
Syntax:strupr(string);
4. strlwr( ): It converts uppercase letters in string to lowercase.
Syntax:strlwr(string);
strcpy( ): It is used to copy the content of one string to
another.Syntax:strcpy(target,source);
5. strcat( ): It is used to concatenate source string to the target string.
Syntax:strcat(target,source); or strcat(source,target);
6. strcmp( ): It compares two strings on following basis.
Syntax:strcmp(string1,string2);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Program: Write a program to read two strings in array and compare two strings and check that string is
palindrome or not.
# include<stdio.h>
# include<conio.h>
# include<string.h>
void main( )
{clrscr( );int a;
char string1[20];
char string2[20];
printf("Enter a word");
scanf("%s",string1);
strcpy(string2,string1);
a=strcmp(string2, strrev(string2));
if (a==0)
{
printf("palindrome");
}
else
{
printf("Not palindrome");
}
}
Function:
Functions are the building block of statements, which takes some data, manipulate them and can return a
value. Bug free function can be used repeatedly from other part of the program. There are two types of
functions:
1. Library Functions (built in or ready made): C has the facilities to provide library function for
performing some operation. These functions are present in the c library and they are predefined.
for eg.
a. scanf( );
b. printf( );
c. getchar( );
d. putchar( );
2. User Defined functions (Defined by user according to need): user can creates their own function
for performing this type of a function are called user define function.
Syntax of user defined functions
# include<stdio.h>
# include<conio.h>
void main( )
{
function ( );
..............
.............
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
function ( )
{
body of the function
}
WAP to calculate simple interest using function
#include
float interest(float); //function declaration
int main()
{ float si;
si=interest(); //function call
printf("Simple interst is %.2f\n",si);
}
float interest() //function definition
{
float p,t,r,i;
printf("Enter Principal, Time and Rate");
scanf("%f%f%f",&p,&t,&r);
i=(p*t*r)/100;
return i; //function return value
}
WAP to calculate area of rectangle using function.
#include
int area (void);
void main()
{
int a;
a = area();
printf(“area is %d”,a);
}
int area()
{
int l,b,ar;
printf(“Enter length and breadth”);
scanf(“%d%d”,&l,&b);
ar = l*b
return ar;
}
Advantage:
1. Big programs can be divided into smaller module using functions.
2. Program development will be faster.
3. Program debugging will be easier and faster.
4. Use of functions reduce program complexity.
5. Program length can be reduced through code reusability.
6. Use of functions enhance program readability.
7. Several developer can work on a single project.
8. Functions are used to create own header file i.e mero.h
9. Functions can be independently tested.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Without passing arguments
Program: Write a program to find out sum and square of two input number without passing arguments
function.
# include<stdio.h>
# include<conio.h>
int sum( );
int square( );
void main()
{
sum( );
square( );
}
int sum( )
{
int a,b, sum;
printf("enter any two number");
scanf("%d%d",&a,&b);
sum=a+b;
printf("sum is=%d',sum);
return(sum);
}
int square( )
{
int a,b, square;
printf("enter any number");
scanf("%d%d",&a);
square=a*a;
printf("square is=%d',square);
return(square);
}
Recursive Function:
The function which performs recursion is called recursive function. Recursion is a process by which a
function calls itself repeatedly until some specified condition has been satisfied.
Those function which calls itself is known as recursive function and the concept of using recursive functions
to repeat the execution of statements as per the requirement is known as recursion. The criteria for
recursive functions are:
1. The function should call itself.
2. There should be terminating condition so that function calling will not be for infinite number of
time.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Program: Write a program to calculate factorials by using recursion process.
#include<stdio.h>
#include<conio.h>
int fact(int);
void main( )
{
clrscr();
int
printf("
Enter a
number"
);
scanf("
%d",&n)
;
printf("The factorial of %d is %d",n,fact(n));
}
int fact(int n)
{
if(n<=1)
return (1)
else
{
return(n*fact(n-1)); or z=(n*fact(n-1));
} return z;
}
Program: Write a program read a number and make the sum of individual digits & print using recursion
technique.
#include<stdio.h>
#include<conio.h>
int sum(int)
void main()
{
clrscr();
int n;
printf("Enter the any number");
scanf("%d",&n);
printf("The sum of individual digits is %d",sum);
int sum(int n)
{
int a;
if(n>0)
{
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
a=n%10;
n=n/10;
ruturn(a+sum(n));
}
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
}
int sum (int n)
{
if (n<=0)
return 0;
else
return (n+sum(n-1));
}
Accessing a Function:
There are two types of accessing a function.
1. Call by value: Only the values of arguments are same to the function and any change made to the
formal arguments do not change the actual arguments.
Program: Write a C program try to exchange two values by using call by value accessing function.
# include<stdio.h>
# include<conio.h>
int swap (int, int)
void main( )
{
int a,b;
a=10
b=20
printf("Value of a=%d and b=%d",a,b);
swap (a,b);
printf("Value of a=%d and b=%d",a,b);
}
int swap(int x, int y)
{
int r;
r=x;
x=y;
y=r;
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
2. Call by reference: When we pass address to a function the parameters receiving the address should
be pointer. The process of calling a function by using pointer to pass the address of the variable is
known as call by reference.
Program: Write a C program to exchange two values by using call by reference accessing function.
# include<stdio.h>
# include<conio.h>
int swap(int *, int *)
void main( )
{
int a,b;
a=10
b=20
printf("Value of a=%d and b=%d",a,b);
swap(&a,&b);
printf("Value of a=%d and b=%d",a,b);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
We can also declare a structure
struct student
{
int roll;
char name[50];
int age;
char section;
float height;
} s1,s2;
We can also declare array of variables at a time of declaring a structure as:
struct student
{
int roll;
char name[50];
int age;
char section;
float height;
} s[100];
Union:
Unions like structure contain members whose individual data types may differ from one another.
However the member that composes a union all share the same storage area within the computer memory
were as each member within a structure is assigned its own unique storage area.
Syntax Union union_name
{
Union_member (s);
}
S.N. Structure S.N. Union
1 Structure is designed by using 'struct' 1 Union is designed by using 'union' keyword.
keyword.
2 Syntax: struct structure_name 2 Syntax: union union_name
{ {
Data_type member1; Data_type member1;
Data_type member1; Data_type member1;
} }
3 All the member of the structure variable 3 Only one member of the union variable can be
can be processed at a given time. processed at a time because only one member
of the union variable can be active at a time.
4 We use structure variable if memory is 4 We use union variables if memory is less and
large and have to store values all of the have to store one variable in one of the
variables. declared variables or members.
5 Structures are broadly used in 5 Unions are not used broadly as much as
programming. structures.
6 Structure declaration takes large amount 6 Union declaration shares the same area of
of spaces to store data and values. memory to save storage space.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Example 1, Write a C program to read different structure variables and display them.
#include<stdio.h>
#include<conio.h>
void main( )
{
struct student
{
int roll;
char name[30];
char section;
float height;
} s1
printf("\n Enter roll numer");
scanf("%d",&s1.roll );
printf("\n Enter name:");
gets(s1.name);
printf("\n Enter section:");
scanf("%c",&s1.section);
printf("\n Enter height");
scanf("%f,&s1.height);
printf("\n You have entered:\n);
printf(" Roll Numer %d Name is %s section %c and height is %f",
s1.roll,s1.name,s1.section,s.height);
}
Program: Write a program to input the employee name and their basic salary of n employees and display
the record in proper format.
#include<stdio.h>
#include<conio.h>
void main ()
{
struct employee
{
char name[10];
int salary;
};
struct employee e[100],t;
int i,j,n;
printf("\n How many records");
scanf("%d", &n);
for(i=0; i<n; i++)
{
printf("\n Enter name of employee");
gets(e[i].name);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
}
}
}
Printf("\n\n The records of the student after sorting\n");
Printf("\n Name of student Address ");
for (i=0; i<=n; i++)
{
printf("\n %s %s", s[i].name,s[i].address);
}
}
Pointer
A pointer is a variable that a points to a references a memory location where data is stored. Each memory
cell in the computer has an address which can be used to access its location. A pointer variable points to a
memory location rather than a value.
- We can access and change the contents of the memory location.
- A pointer variable contains the memory location of another variable.
- The asterisk tells the compiler that you are creating a pointer variable.
The pointer declaration syntax is as shown below.
Pointer_type *pointer_variable_name;
For e.g. int *p;
Address (&) and indirection (*) operator
The address (&) operator and immediately preceding variable returns the address of the variable
associated with it. Hence, the address of (&) operator returns the address of memory location in which the
variable is stored.
The indirection (*) operator is used to extract value from the memory location stored in the
particular memory location whose address is stored in pointer variable.
The syntax of declaring address operator to pointer variable is as follows.
Pointer_variable = &variable_name;
For Example
int *ptr, num=25;
ptr = #
Program: Write a complete program to display address and value of the pointer variable.
#include<stdio.h>
void main( )
{
int *p;
int age=17;
p=&age;
printf("\n Value of age is %d", age); output= 17
printf("\n Value of age is %d",*p); output=17
printf("\n Value of age is %d",*(&age)); output=17
printf("\n Address of age is %u",p); output=2686784
printf("\n Address of age is %u",&age); output=2686784
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Pointer to Arithmetic
#include<stdio.h>
#include<conio.h>
void main( )
{
int *p;
int age= 17
p=&age;
printf(" \nValue of age is %d",age); output=17
printf("\n Increment on age is %d",++age); output=18
printf("\n Address of age is %u",p); output=2686784
printf("\n Increment in pointer is %u",++p); output=
}
Write a C program to increment pointer.
#include<stdio.h>
#include<conio.h>
void main( )
{
int n[ ]={10,20,30,40};
int *aptr=n;
int i;
printf("\n Pointer notation");
for (i=1; i<=4; i++);
{
printf("*(aptr+%d)=%d\n",i*(aptr+i)); output =10
} =20
} =30
=40
Assignment pointer value to function
Program: Write a program to pass pointer variable to function sum them and display after returning it.
#include<stdio.h>
#include<conio.h>
Int add(int *p, int *k)
void main( )
{
int a,b,c=0;
printf("\n Enter two numbers");
scanf("%d %d",&a,&b);
c=add(&a,&b);
printf("\n Sum of two numbers %d and %d is %d",a,b,c);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Advantage of Pointer
- Runtime memory creation.
- Runtime memory deletion.
- Hard Access through pointer.
- Data Structure Based Pointer.
- Applications of Pointer Ms-word, Excel, Access, SQL.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
The modes of the data file are as follows:
S.N. Mode Description
1 "r" / "rt" It opens a text file to read only mode.
2 "w" / "wt" It creates a text file to write only mode.
3 "a" / "at" It appends text to already data containing file.
4 "r+t" It opens a text file for read and write mode.
5 "w+t" It creates a text file for read and write mode.
6 "a+t" It opens or creates a text file and read mode.
7 "rb" It opens a binary file for read only mode.
8 "wb" It creates a binary file for write only mode.
9 "ab" It opens or create a binary file for append mode.
10 "r+b" It opens a binary file for read and write mode.
11 "w+b" It creates a binary file for read and write mode.
12 "a+b" It opens or creates a binary file for append mode.
Functions
1. fputc= Store character into the file.
2. fputs= Store string in to the file.
3. fgetc= fetch character from the file.
4. fgets= fetch string from the file.
5. fwrite= store data (structure) in to the file.
6. fread= fetch data (structure) from the file.
7. fprintf= store data in to file.
8. fscanf= fetch variable from the file.
Store/write data
Syntax:
fprintf(fptr , ”format specifiers” ,variables);
Eg; suppose if we want to store name, disease, age and bed number of a patient then, it is written
as
fprintf(fptr , ”%s %s %d %d”, n, d, a, b);
Where, variable are initialized as:
char n[10], d[10];
int a, b;
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Program example
1) Create a datafile “patient.txt” and store name, disease, age and bed number of a patient.
#include<stdio.h>
void main()
{
char n[10], d[10];
int a, b;
FILE *fptr;
fptr = fopen(“patient.txt”,”w”);
printf("Enter name, disease, age and bed number");
scanf(“%s %s %d %d”, n, d, &a, &b);
fprintf(fptr,"%s %s %d %d\n”, n, d, a, b);
fclose(fptr);
}
[Note: This program will store only single record to store multiple record we have to use loop as following
programs.
2) Create a datafile “student.txt” and store name, class and marks obtained in 3 different subject for few
students/n-students.
#include<stdio.h>
void main()
{
char n[10];
int c, e, ne, m, i, num;
FILE *fptr;
fptr = fopen("student.txt","w");
printf("How many record?");
scanf("%d",&num);
for(i=1;i<=num;i++)
{
printf("Enter name class and 3 marks");
scanf("%s %d %d %d %d",n, &c, &e, &ne, &m);
fprintf(fptr,"%s %d %d %d %d \n",n, c, e, ne, m);
}
fclose(fptr);
}
3) Create a datafile “student.txt” and store name, class and marks obtained in 3 different subject until user
press “y” / as per user requirement.
#include<stdio.h>
int main()
{
char n[10],ch[3];
int c, e, ne, m;
FILE *fptr;
fptr = fopen("student.txt","w");
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
do
{
printf("Enter name class and 3 marks");
scanf("%s %d %d %d %d",n, &c, &e, &ne, &m);
fprintf(fptr,"%s %d %d %d %d\n",n, c, e, ne, m);
printf("Press Y to continue");
scanf("%s",ch);
} while (strcmp(ch,"Y") == 0 || strcmp(ch,"y")==0);
fclose(fptr);
}
Add/Append data
1) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to add 200 more records.
#include<stdio.h>
void main()
{
char n[10];
int c, e, ne, m, i;
FILE *fptr;
fptr = fopen("student.txt","a");
for(i=1;i<=200;i++)
{
printf("Enter name class and 3 marks");
scanf("%s %d %d %d %d", n, &c, &e, &ne, &m);
fprintf(fptr,"%s %d %d %d %d \n",n, c, e, ne, m);
}
fclose(fptr);
}
2) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to add more records until user press “y” / as per user requirement.
#include<stdio.h>
void main()
{
char n[10], ch[3];
int c, e, ne, m;
FILE *fptr;
fptr = fopen("student.txt”,”a”);
do
{
printf("Enter name class and 3 marks");
scanf("%s %d %d %d %d", n, &c, &e, &ne, &m);
fprintf(fptr,"%s %d %d %d %d\n", n, c, e, ne, m);
printf("Press Y to continue");
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
scanf("%s",ch);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1) A d#include <stdio.h>
void main()
{
char n[10];
int c, e, ne, m;
FILE *fptr;
fptr = fopen("student.txt","r");
printf("Name\tPercentage\n");
while(fscanf(fptr,"%s %d %d %d %d",n,&c,&e,&ne,&m) != EOF)
{
printf("%s %d %d %d %d", n, c, e, ne, m);
}
fclose(fptr);
}
2) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to read and display only records whose name is Ram.
#include<stdio.h>
void main()
{
char n[10];
int c, e, ne, m;
FILE *fptr;
fptr = fopen("student.txt","r");
while(fscanf(fptr,"%s %d %d %d %d",n,&c,&e,&ne,&m) != EOF)
{
strlwr(n);
if (strcmp(n,”ram”) == 0)
{
printf("%s %d %d %d %d", n, c, e, ne, m);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
}
}
fclose(fptr);
}
3) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to read and display only records who pass in all subjects.
#include<stdio.h>
void main()
{
char n[10];
int c, e, ne, m;
FILE *fptr;
fptr = fopen("student.txt","r");
while(fscanf(fptr,"%s %d %d %d %d",n,&c,&e,&ne,&m) != EOF)
{
if (e>=40 && ne>=40 && m>=40)
{
printf("%s %d %d %d %d", n, c, e, ne, m);
}
}
fclose(fptr);
}
4) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to read and display only records who fail in any one subject.
#include<stdio.h>
void main()
{
char n[10];
int c, e, ne, m;
FILE *fptr;
fptr = fopen("student.txt","r");
while(fscanf(fptr, "%s %d %d %d %d", n, &c, &e, &ne, &m) != EOF)
{
if (e<40 || ne<40 || m<40)
{
printf("%s %d %d %d %d", n, c, e, ne, m);
}
}
fclose(fptr);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
5) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to read and display only name and percentage of all students
#include<stdio.h>
int main()
{
char n[10];
int c, e, ne, m;
float p;
FILE *fptr;
fptr = fopen("student.txt","r");
while(fscanf(fptr, "%s %d %d %d %d", n, &c, &e, &ne, &m) != EOF)
{
p = (e+ne+m)/3;
printf("%s %f", n, p);
}
fclose(fptr);
}
6) A datafile “student.txt” contain name, class and marks obtained in 3 different subject of few students.
Write a C program to read and display only records of all students who secure distinction.
#include<stdio.h>
int main()
{
char n[10];
int c, e, ne, m;
float p;
FILE *fptr;
fptr = fopen("student.txt","r");
while(fscanf(fptr, "%s %d %d %d %d", n, &c, &e, &ne, &m) != EOF)
{
p = (e+ne+m)/3;
if (p>=80)
{
printf("%s %d %d %d %d", n, c, e, ne, m);
}
}
fclose(fptr);
}
Program: Write a program to read a line and store it in a data file and display the contents.
#include<stdio.h.
#include<conio.h>
void main( )
char I;
FILE *f, *q;
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
f = fopen("store.txt","w");
while((i=getchar())!='\n')
{
fputc(i, f);
}
fclose( f);
q=fopen ("store.txt","r");
while((i=fgetc(q))!=EOF)
{
Printf("%c",i);
}
}
Program: Write a C program to read N students record store them in data file and display the content in
appropriate format by using fprintf and fscanf function.
#include<stdio.h>
void main( )
{
FILE *f;
f= fopen (''ratna.txt","w");
int i, rn, n;
char name[25], add[35];
printf("\n how many records?");
scanf("%d", &n);
printf("Enter %d student roll number, name and address:\n",n);
for (i=o; i<n; i++)
{
scanf("%d %s %s",&rn,name,add);
fprintf( f, "%d\t%s\t%s\n ",rn,name,add);
}
fclose(f);
printf("\n The %d data records",n);
f= fopen ("ratna.txt","r");
while (fscanf( f, "%d %s %s",&rn,name,add)!=EOF)
{
printf("\n %d\t%s\t%s",rn,name,add);
}
fclose(f);
}
Program: Write a program using C language that reads successive records from the new data file and
display each record on the screen in an appropriate format.
#include<stdio.h>
#include<conio.h>
void main( )
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
{
struct student.
{
char name[50];
char add[80];
};
struct student s;
char next='Y' ;
FILE *fp;
fp = fopen ("C:\\student.txt","w");
while(next=='Y' || next=='y')
{
printf("\n Enter the name of the student");
gets(s.name);
printf("\n Enter the address of the student");
gets(s.add);
fwrite(&s, sizeof (s), 1, fp);
printf("\n Do you want to write next record (Y/N)");
}
fclose(fp);
fp=fopen ("C:\\student.txt", "r");
printf("\n Name of student Address");
while (fread (&s, sizeof(s), 1,f(p)==1)
{
printf("\n %s \t\t\t %s",s.name,s.add);
}
fclose (fp);
Program: Write a C program to read sentence until enter key pressed. Put every words in data file by
using fputs( ) fucnction and display the content of file by using fgets( ) function.
#include<stdio.h>
#include<conio.h>
Void main( )
{
Char a[20];
FILE *f;
f= fopen ("senten.doc", "w");
printf("\n Enter sentence");
gets(a)
while (strlen (gets(a))>0)
{
fputs(a,f);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
fclose(f);
f = fopen ("senten.doc", "r");
if (f== NULL)
printf("\n Cannot open the file");
else
{
While (fgets (a,19,f)!=NULL)
{
printf("%s",a);
}
}
fclose(f);
}
Program: Write a C program to read ages of N students, store them in age.txt file and find out the
average age after reading from data file.
#include<stdio.h>
#include<conio.h>
Void main( )
{
int ag,n, i, sum=0;
float avg;
FILE *f;
f= fopen("age.txt", "w");
printf("\n How many student:");
scanf("%d",&n);
for(i=0; i<n; i++)
{
printf("\n Enter %d student ages",i+1);
scanf("%d",&ag);
putw(ag,f);
}
fclose (f);
f= fopen ("age.txt", "r");
printf("\n Calculating average age from file");
for (i=0; i<n; i++)
{
sum=sum+getw(f);
}
avg = (float) sum / n ;
printf("\n Average age of %d student is %f", n, avg);
fclose(f);
}
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Program: Write C program to read already created data file student.txt and display it contents if it opens
otherwise print message "The file ……does not exists".
#include<stdio.h>
#include<conio.h.
Void main( )
{
char i;
FILE *f;
f = fopen ("student.txt", "r");
If (f== NULL)
{
printf("\n The student.txt file does not exists");
}
else
{
while ( ( i=fgetc(f))!=EOF)
{
printf("%c",i);
}
}
fclose(f);
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Web References:
3. https://www.javatpoint.com
4. https://www.w3schools.com
5. https://www.tutorialspoint.com
6. https://www.google.com
7. https://www.wikipedia.org
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
COMPUTER SCIENCE
Grade: XII
REFERENCE NOTE
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
6. What are the differences between Procedure Oriented and Object Oriented
Programming?
Procedure Oriented Object Oriented
2. Programs are divided into multiple modules. 2. Programs are divided into multiple objects.
5. It does not model the real world perfectly. 5. It models the real world perfectly.
8. Examples: FORTRAN, COBOL, Pascal, C, etc. 8. Examples: C++, JAVA, Smalltalk, etc.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
f) Polymorphism
It is a feature of OOP, which refers to the way of operating the same operator in different ways and
different method or purpose. Operator overloading and the operation overloading are the examples or
Polymorphism. For example ‘+’ operator can be used for arithmetic operation and string concatenation
both. This facility or feature is an example of Polymorphism. It reduces the number or keywords or
operators.
Disadvantages
a) Compiler and runtime overhead is high.
b) Software developer should analyze the problem in object oriented way.
c) Requires the mastery in software engineering and programming methodology.
d) Useful only for the large and complex projects.
Application of OOP
1. Expert System
2. Artificial intelligence
3. Management information systems.
4. Decision support system.
5. Computer based training and education
6. Object- oriented database.
7. Computer games.
8. Mobile applications.
9. Internet based applications.
10. Designing user interface for software.
11. Security System.
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
COMPUTER SCIENCE
Grade: XII
REFERENCE NOTE
1. What is SPM? Explain the major activities of Software Development Process in brief.
2. What is Software Development Model? Explain the types of SDM with advantages and disadvantage.
3. Who is the system analyst? Explain the role and characteristic of a system analyst.
4. Explain in detail about waterfall, prototyping and spiral model of software development.
5. What is prototyping? Write down its advantages and disadvantages.
6. Define SDLC. Explain different phases of SDLC in brief.
7. What do you mean by feasibility study? Why is it necessary before designing a system?
8. Define system testing. Different between black box testing and white box testing.
9. What is algorithm and flowchart? Write difference between system and program flowchart.
10. Differentiate between System analyst and System engineer.
11. Define the following terms. A) DFD B) ER diagram C) Case diagram D) UML E) System Flowchart
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Software development process defines a sequence of tasks that must be carried out to build new
software.
It groups the development activities into a sequence of phases.
A phase in sequence can only commence on the previous phase has been completed.
A report is produced at the end of each phase, describing what has been achieved and outlining
the plan for the next phase.
Fundamental activities for the software development process are
1. Software Specification: The functionality or software and constraints on its operations must
defined.
2. Software design and implementation: The software to meet the specifications must produce.
3. re must be validated to ensure that it does what the customerwants.
4. Software evolution: The software must evolve to meet changing customer needs.
Development:
It is the process of step by step changing or growing of any program and system.
Information System:
Information system is a system which processes supplied/collected data and generates information that
can be used for decision making at different levels.
SDLC
SDLC (Software/System Development Life Cycle) is an organized way to develop a software/system.
System Development Phase or System Development Life Cycle or Software Development Life Cycle (SDLC)
is a methodology used to develop, maintain, and replace software/information systems.
It is a systematic process of developing any software. It helps in establishing a system, or software
or project, or plan. It gives an overall list of processes and sub-processes required for developing a
system.
SDLC consists of a set of development activities that have a prescribed order. It is the development
of software in chronological order.
System Development Life Cycle (SDLC), which is also known as Application Development Life Cycle, is a
term used in system that describes the process of planning, creating, testing and deploying an information
system.
Importance and the necessity of SDLC
1. It helps to determine the needs of the user.
2. It supports constant communication between the developer and the user.
3. SDLC helps for easy identification of missing requirements.
4. It ensures that the software meets the needs of its users.
5. It supports proper analysis and design of the software.
6. It ensures proper development and testing.
7. Proper documentation support for future upgrade and maintenance.
8. It provide flexibility for adding features even after the software is developed.
SDLC Phases
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
System Study /
Maintenance & Feasibility Study
Review
System Analysis/
System Requirement
System
Implementation
System
System System Design
Testing Development
1. System study:
A system is intended to meet the needs of an organization. Thus the first step in the design is to
specify these needs or requirements. The top manager of the organization takes the basic decision
to use a computer based (information) system for managing the organization.
During this phase, the development team focuses on completing three tasks:
- Survey the system by collecting the inputs from various sources.
- Analyzing the current system (manual or automated) in depth and developing possible
solutions to the problem.
- Selecting to the best solution and defining its function with a feasibility study.
2. System analysis:
System analysis is the dissection of a system into its component pieces to study how those
component pieces interact and work.
System analysis is a term that collectively describes the early phases of development.
It is defined as those phases and activities that focus on the business problem, independent
of technology.
In this stage, the development team once again goes to the organization and studies very minutely
to collect all the drawbacks and details of information from the users, management and data
processing personnel.
Then the system analyst analyzes the information and proposes the following specifications.
i. Goals and objectives of the proposed system.
ii. Fundamental actions that must take place in the software.
iii. Outputs to be produced.
iv. Inputs to be used.
v. Processes to be performed.
vi. Interfaces to be provided.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Feasibility study:
Feasibility study is the most important activity in the system analysis phase. It analyses the
proposed system from different aspects so that it makes us clear that how practical or beneficial
the system will be to the organization. So it tells us whether the system is feasible to design nor
not.
Need of feasibility study
It determines whether the system meets the goal of the clients or not.
It determines the strength and limitations before starting to develop the system.
It focuses on the boundary of the system's outline.
It suggests new opportunities through the investigations process.
It provide quality information for decision making.
To provide documentation of the investigated system.
System design:
The next step is to develop the logical design of the system. During this phase, the logic of the
system, namely, the information requirement of users, and use this to find the necessary
database.
System design is concerned with the design of new system. It involves designing of various things
such as output design, input design, files design, processing and general program design etc.
Logical Design: Theoretically designing of the system is called logical design. The system could be
designed on the basis of the requirements.
Physical Design: The conversion of logical design into designing tools and techniques is called
physical design. It is more detail and complex jobs describing the solution of the problem. It uses
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
algorithms, flowcharts, pseudo codes, decision table, decision tree, E-R diagram, Data flow
diagram etc.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Theoretically designing of the system is called logical design. The system could be designed on the
basis of the requirements.
The conversion of logical design into designing tools and techniques is called physical design. It is
more detail and complex jobs describing the solution of the problem.
3. System development: after designing a logical diagram of a system then next step is to convert
into program. This process is called system development. Flowchart, algorithm, Pseudo code, etc.
are the outlines the procedures for taking the input data and processing it into usable output.
System Analyst:
System analyst is person who is involved in analyzing, designing, implementing and evaluating computer-
based information systems to support the decision making activities and operations of an organization.
A good system analyst is:
1. Understanding and commitment to the organization
2. People skills
3. Conceptual skills and
4. Technical skills
A system analyst is information specialist. To be a system analyst, one must be knowledgeable
about the technical aspects of analyzing, designing and implementing computer-based systems.
A system analyst is a person who conducts a study, identifies activities and objectives and
determines a procedure to achieve the objectives.
Designing and implementing systems to suit organizational needs are the functions of the systems analyst.
One plays a major role in seeing the business benefits from computer technology.
An analyst is a person with unique skills. One uses these skills to coordinate the efforts of different types
of persons in an organization to achieve business goals.
The characteristics (attributes) of system analyst are as follows:
1. Knowledge of organization.
2. Technical Knowledge.
3. Interpersonal Communication Skill.
4. Character and Ethics.
5. Problem-Solving Skill.
1. Defining the problem
2. Analyzing the problem
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Describes in Details:
1. System study or Preliminary Investigation :
In this stage, the development team studies the present and identifies the drawbacks. They
interact with the users and gathers information from different sources to recognize the problems
of present system.
2. System Analysis:
In this stage, the development team once again goes to the organization and studies very
minutely to collect all the drawbacks and details of information from the users, management
and data processing personnel.
Then the system analyst analyzes the information and proposes the following specifications.
i. Goals and objectives of the proposed system.
ii. Fundamental actions that must take place in the software.
iii. Outputs to be produced.
iv. Inputs to be used.
v. Processes to be performed.
vi. Interfaces to be provided.
vii. Performance requirements to be met.
viii. Organizational and other constraints' to be met.
3. Feasibility study:
Feasibility study is the most important activity in the system analysis phase. It analyses the proposed
system from different aspects so that it makes us clear that how practical or beneficial the system will
be to the organization. So it tells us whether the system is feasible to design nor not. Thus it is
necessary before system design.
The different levels of feasibility study are as:
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
1. Economic feasibility: it concerns with cost effectiveness of the system. The main objective of
economic feasibility is to calculate approximate cost-both the development cost and the operational
cost and the benefits from the system.
2. Technical feasibility: it concerns with the availability of the hardware, software and the support
equipment for the complete development of the system.
3. Operational feasibility: it concerns with smooth operation of the system. It is all about the
problems that may occur during operation of the system after its development.
4. Behavior feasibility: it concerns with behavior of the users and the society towards the new
system. Generally, most of the traditional employees are not easily ready to upgrade them with the
new system.
5. Schedule feasibility: it is the process of splitting project into tasks and estimate time and resources
required to complete each task. It determines the deadline to complete a system and schedule the
task accordingly.
6. Legal feasibility: it concerns with legal issue of the system. If the system is illegal then the system
designing is meaningless. Everything is measured whether it is legal or illegal. It considers copyright
law, foreign law, foreign trade, tax, etc.
4. System Design:
System design is concerned with the design of new system. It involves designing of various things
such as output design, input design, files design, processing and general program design etc. This
state consists of logical design and physical design of the system.
7. Logical Design: Theoretically designing of the system is called logical design. The
system could be designed on the basis of the requirements.
8. Physical Design: The conversion of logical design into designing tools and techniques
is called physical design. It is more detail and complex jobs describing the solution of
the problem. It uses algorithms, flowcharts, pseudo codes, decision table, decision
tree, E-R diagram, Data flow diagram etc.
System Design Tools:
The tools which are used to design the system in known as system design tools. They are used during
system analysis and design phase of the system development.
1. Algorithm: An algorithm is defined as the finite sequences of instructions for solving a problem.
2. Flowchart: A flowchart is the pictorial representation of an algorithm which is classified into two
types’ system flowchart and program flowchart. The different symbols used in system flowchart
are defined below:
I) System flowchart:
System flowchart describes the internal architecture of a system that describes how data are
moved inside the internal components of a system.
II) Program flowchart:
Program flowchart describes to solve the application types of real world problem.
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII Email : acharyaprasiddha6@gmail.com
[ www.prasiddhaacharya.com.np ]
Computer Science Reference Note for Grade-XII
DFD is the logical diagram to describe the flow of data inside the components of system. It is easier
to understand or grasp when being explained and most important to all, it is much more precise
and less ambiguous than a narrative one. The main components are: process, data store, data
flow, external entities.
4. Context Diagram:
It is combination of many other DFD. It is the highest level of DFD. It contains only one process,
representing the entire system, the process is given the symbol circle. The external entities are
denoted by rectangle. The flow of data is described by arrow.
Membership
Applicant Issue
Issue
Membership
Fig.: The Context diagram of library membership
5. ER (Entity Relationship) diagram:
The E-R diagram is an overall logical structure of a database that can be expressed graphically. It
was developed to facilitated database design and the simplicity and pictorial clarity of this
diagramming technique have done great help in the designing part of database. The main
components are attributes, entities and relationship.
The diagrammatic representation of entities attributes and their relationship is described by E-R
diagram.
⚫ The main components of ERD are
⚫ Entity: Customer
⚫ Attributes: CustomerID
⚫ Relationship:
Purchase
⚫ Lines:
Name Address
Cus. Goods Id Name
Cont.No Rate ne
Purchase
Fig: ERD for customer and Goods Quantity
Computer Science Reference Note for Grade-XII
6. Case diagram
Computer aided software engineering tool is automatic computer based program that helps for
software engineering and SDLC process. It is very fast and effective tools for the development of
big scale software. It helps in analysis, design, implementation, testing and maintenance.
7. UML
Unified Modeling Language is a standardized general purpose modeling language in the field of
object-oriented software engineering. The standard is managed, and was created by, the object
management group. UML includes a set of graphic notation techniques to create visual models of
object-oriented software.
8. Decision Table:
A table allows us to identify the exact course of actions for given conditions in tabular form.
Decision table is a tabular representation of the logic of a decision, which specifies the possible
conditions for the decision and the resulting actions.
Parts of Decision Table.
9. Decision Tree:
Decision tree is also a technique to represent condition and actions in a diagrammatic form in
computer. A decision tree allows us to identify the exact course of actions for given conditions in
tree structures.
10. Pseudo Code:
It is a kind algorithm for solving a problem and the instructions of pseudo code are written by
using English phrase and mathematical expressions.
5. System Development:
Programmers begin to develop the program by using a suitable High Level Language. In System
developments following processes are done.
i. Convert logical structure in to programs in programming language.
ii. Database is created.
iii. User operational documents are written.
iv. Users are trained.
v. The internal documentation of a system is prepared.
6. System testing:
It is an investigation conducted to provide stakeholders with information about the quality of the
product or service under test. System testing also provides an objective, independent view of the
software to allow the business to appreciate and understand the risks of software
implementation.
1. White box testing: white box testing of software is predicted on close examination of procedural
details. Logical path through the software and collaborations between components are tested by
providing test case that exercises specific sets of conditions or loops. It is used when the tester
has access it the internal data structures and algorithms including the code that implement these.
2. Black box testing: black box testing treats the software as a black box without any knowledge of
internal implementation. Black box testing methods include: equivalence partitioning, boundary
10
Computer Science Reference Note for Grade-XII
value analysis, specification based testing, etc. it is also called functional testing because it tests
whether a system is functioning or not.
7. Implementation:
Implementation involves testing the installed system, converting from the old system to the new
one and training the users. This phase consists of implementation of the system into a production
environment, and resolution of the problem identified in testing phase.
Types of Implementation:
1. Direct Conversion: All users stop using old system at the same time and then begin using the
new. This option is very fast, less costly but more risky.
2. Parallel conversion: Users continue to use old system while an increasing amount of data is
processed through the new system. Both the systems operate at the same time until the new
system works smoothly. This option is costly but safe approach.
3. Phased conversion: Users start using the new system component by component. This option
works only for systems that can be compartmentalized. This option is safe and conservative
approach.
4. Pilot conversion: Personnel in a single pilot-site use the new system, and then the entire
organization makes the switch. Although this option may take more time, it is very useful in
big organizations where a large number of people make the conversion.
8. Maintenance and review:
It begins after the system is implemented. Like any system, there is an ageing process that requires
periodic maintenance of hardware and software. The content of the review will include objectives
met, cost, performance, standards and recommendation.
Types of Maintenance
1. Corrective Maintenance: it corrects the run time errors during the operation.
2. Adaptive Maintenance: It modifies or adds new features in the system.
3. Perfective Maintenance: It makes the system perfect, up-to-date and improve the life of the
system.
System Development Model:
During software development or system development for organizations, a common process framework
is established, defining a small number of framework activities that are applicable to all software projects,
regardless of their size complexity. For a better paradigm of a software process, several models are
designed and implemented. It is the choice of system analyst which model is used to achieve the goal.
The different models are:
1. Waterfall model:
Waterfall model is a systematic and sequential model to develop software that begins with
requirements analysis to operation and maintenance. It describes a development method that is
liner and sequential. It is an oldest type of model for software engineering. The fundamental
processes of waterfall model are as follows:
Requirements Analysis
System design
Development
Testing
Operation &
Fig:- Waterfall Model Maintenance
11
Computer Science Reference Note for Grade-XII
1. Requirements analysis and definition: it is the first stage of waterfall model. In this stage, the
developer should identify the actual requirements of the given problem.
2. System design: in this stage the systems design process partition the requirements to either
hardware or software systems.
3. System Development: During this stage, the system design is converting into development.
4. Integration and system Testing: The individual program units or programs are integrated and
tested as a complete system to ensure that the software requirements have been met.
5. Operation and maintenance: in this stage, the system is installed to the desire location. The
maintenance involves correcting errors which were not discovered in earlier stages of the life
cycle, improving the implementation of system units and enhancing the system's service as
new requirements are discovered.
Advantages
1. It is simple model suitable for small size project.
2. It is less expensive.
Disadvantages
1. It has no back track mechanism.
2. It is not suitable for large size project.
3. It has lack of proper documentation.
2. Prototyping model:
It is the iterative process of system development which is more appropriate for developing new
system where there is no clear idea of requirements, inputs and outputs. These systems are then
continuously modified until the user is satisfied.
Develop a Prototype
Prototype
acceptable
1. Identify the user needs: the system analyst interviews the user to obtain an idea of what is
required from the system.
2. Develop a prototype: the system analyst, working uses one or more prototyping tools to
develop a prototype.
3. Determine if prototype is acceptable: the analyst educates the user in prototype use and
provides an opportunity from becoming familiar with the system.
4. Use the prototype: the prototype becomes the operational system.
Advantages
1. The users get a better understanding of the system being developed.
2. Errors can be detected much earlier as the system is made side by side.
3. Quicker user feedback is an available leading to better solutions of the system.
Disadvantages
12
Computer Science Reference Note for Grade-XII
3. Spiral system:
In this model, process is represented as a spiral rather than as a sequence of activities with
backtracking. It is a software development process combining the elements of both waterfall and
prototyping model. The spiral model is intended for large, expensive and complicated projects.
This is the most realistic model because it uses multidimensional approach for software
development. The activities in SDLC are organized in a spiral structure that has many cycles which
starts from the center of the spiral and goes out as it program and becomes matured. Each of the
complete spiral segment is divided into four different attributes knows as
Planning
Risk Analysis
Customer
Engineering
Evaluation
1. Planning: the project is reviewed and a decision made whether to continue with a further loop
of the spiral. If it is decided to continue, plans are drawn up for the next phase of the project.
2. Risk analysis: for each of the identified project risks, a detailed analysis is carried out. Steps
are taken to reduce the risk. For example, if there is a risk that the requirements are
inappropriate, a prototype system may be developed.
3. Software development (Engineering): after risk evaluation, a development model for the
system is chosen.
4. User evaluation: specific objectives for the phase of the project are defined by the evaluation
of users. Constraints on the process and the product are identified. And a detailed
management plan is drawn up. Advantages
- It emphasizes quality.
- It is effective for regular updating the system.
- It emphasizes risk reduction techniques.
Disadvantages
- Full scale risk analysis requires training, skill so it may appropriate only for large
projects.
- This model is relatively untested.
13
Computer Science Reference Note for Grade-XII
Documentation:
Documentation is the process of collecting, organizing, storing and maintaining a complete record of
system and other documents used or prepared during the different phases of the life cycle of the system.
It consists of the detail description about software requirements specification, feasibility report, and
software designing report, description about input-output and processing mechanism, source code,
comments, manuals, guides and effective help desk.
Types of Documentation
1. Internal Documentation: It is used by the system analyst and the programmer during
development process. It is very useful for the development period and also useful in future for the
modification and maintenance for the software.
2. External Documentation: It is used by the user during the running time of the software. It includes
the detail description in terms of manuals, guide and help files. It is mainly deals with how to
effective use of software.
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
14
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
COMPUTER SCIENCE
Grade: XII
REFERENCE NOTE
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Components of AI
Different disciplines contributed their ideas, viewpoint, and techniques to plan the
foundation of Al that acts as components of Al. Some of the major contributions of various
disciplines an given below
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Uses/Applications of Al
The potential applications of Artificial Intelligence are abundant (plentiful). They stretch
from the military for autonomous control and target identification, to the entertainment
industry for computer games and robotic pets. Let's also not forget big establishments
dealing with huge amounts of information such as hospitals, banks, industries, and
insurances, which can use Al to predict customer behavior and detect trends.
1. Game playing:
General game playing (GGP) and General video game playing (GVGP) is the concept and
designs for artificial intelligence programs to successfully play plenty of games. For video
games, game rules have to be either learned over multiple repetitions by artificial players
or are predefined manually in a domain-specific language and sent in advance to artificial
players. For instance, the GGP of chess, computers are programmed to play these games
using a specially designed algorithm. It was considered a necessary landmark on the way
to Artificial General Intelligence. The first commercial practice of general game-playing
technology was Zillions of Games in 1998.
2. Speech recognition:
In speech recognition, the input is given to the computer in the form of vibrations
produced by the sound. This is done with the help of an analog to digital converter that
converts the vibrations produced by the sound into digital format.
Then, a set of complex algorithms runs on that data to recognize the speech and return a
text as a result. Depending upon the goal, the end result may vary to some extent. For
example, Google Voice typing converts spoken words into suitable text format while
personal assistants like Siri and Google Assistant take the sound as input and convert it
into both voice and text format, giving output as per the user's requirement.
3. Understanding natural language:
Natural language understanding is a branch of artificial intelligence that uses computer
software to take the input in the form of sentences using text or speech. It simply reduces
the gap between humans and computers allowing them to interact easily with each other.
4. Computer vision:
Computer vision is a field of artificial intelligence (AI), which enables the computer and its
systems to get input in the form of digital images and videos and take action based on the
provided input.
5. Expert systems:
An expert system is a computer system that mimics or even surpasses the decision-making
ability of a human expert. It is generally designed to solve complex problems by surfing
through bodies of knowledge. It is further divided into two subsystems; the knowledge
base (which represents facts and rules) and inference engine (which applies the rules to
the known facts to deduce new facts).
6. Robotics:
Artificial intelligence (AI) in robotics is the ability of the computer or the robot to perform
multiple tasks performed by humans, which require human intelligence and discernment.
It gives robots a computer vision to navigate, sense, and calculate their reaction
accordingly For example: Robotic packaging uses various forms of Al for quicker and
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
accurate packaging at a lower price. Likewise, Sophia which is also marked as a "social
robot" is successfully able to mimic social behavior and induce feelings of love in humans.
7. Theorem proving:
Proving theorems requires high intelligence as many of the practical problems can be cast
in terms of theorems. If knowledge is expressed by logic, proving theorem is reasoning. It
uses various AI techniques such as heuristic search.
8. Symbolic mathematics:
Symbolic mathematics refers to the manipulation of formulas, rather than doing
arithmetic on numeric values. It is often used in conjunction with ordinary scientific
computation as a generator of programs, used to actually do the calculations.
Robotics
Robotics is the branch of technology that deals with the design, construction, operation,
and application of robots. It is a discipline overlapping artificial intelligence and mechanical
engineering. It is concerned with building robot programmable devices consisting of
mechanical actuators and sensory organs that are linked to a computer. The mechanical
structure might involve manipulators, as in industrial robotics, might concern the
movement of the robot as a vehicle, as in mobile - robotics. Robotics research is used in
artificial intelligence as a framework for exploring key problems and techniques through a
well-defined application.
1. Robotics is the branch of technology that deals with the design, construction,
operation, and application of robots.
2. It is a discipline overlapping artificial intelligence and mechanical engineering.
3. It is concerned with building robots programmable devices consisting of mechanical
actuators and sensory organs that are linked to a computer.
4. Robots are being used in applications like: Industry, scientific research, Military
applications, Intelligent home applications, Health Services.
Cloud Computing
Cloud computing is the use of various services, such as software development platforms,
servers, storage, and software, over the Internet, often referred to as the "cloud". It is
defined as a type of computing that relies on sharing computing resources rather than
having handle applications.
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Types of Clouds
Clouds can be classified as public, private, and hybrid. Public cloud is made available to
the general public or a large industry group. Private cloud computing environment resides
within the boundaries of an organization and is used exclusively for the organizational
benefits Hybrid cloud is the combination of both public and private cloud. Sensitive With
this cloud organizations might run non-core applications in a public cloud, while
maintaining core applications and data in a private cloud.
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Big Data
Big Data refers to complex and large data sets that have to be processed and analyzed to
uncover valuable information that can benefit businesses and organizations.
It has features like:
1. It refers to a massive amount of data that keeps on growing exponentially with time.
2. It is so voluminous that it cannot be processed or analyzed using conventional data
processing techniques.
3. It includes data mining, data storage, data analysis, data sharing, and data
visualization.
4. The term is an all-comprehensive one including data, data frameworks, along the
tools and techniques used to process and analyze the data.
According to Gartner, the definition of Big Data- "Big data is high-volume, velocity, and
information assets that demand cost-effective, innovative forms of information processing
for enhanced insight and decision making."
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
has not been classified under a particular repository (database), yet contains vital
information or tags that segregate individual elements within the data.
Virtual Reality
Virtual reality (VR) is a term that expresses
computer-based simulated environments.
Which can perceive as in the real world, as
well as in unreal worlds.
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
e-Commerce
Electronic commerce (e-Commerce) is a process of buying and selling or exchanging
products, services, and information using electronic media. There are many definitions for
electronic commerce that include elements of electronic transactions and the buying and
selling of goods and services online.
Classification of e-Commerce
1. B2B (Business to Business) Sells products or services to other businesses. e.g.
www.freemarkets.com
2. B2C (Business to Consumer) Sells products or services directly to consumers. eg..
www.amazon.com, www.yahoo.com.
3. C2B (Consumer to Business) Consumer fixes a price on their own, which businesses
accept or decline, e.g., www.priceline.com
4. C2C (Consumer to Consumer) Consumer sells directly to other consumer. e.g.
www.ebay.com
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Advantage of e-Commerce
Some of the advantages of e-commerce are:
1. It enables more individuals to work at home, and to do less traveling for shopping,
resulting in less traffic on the roads, and lower air pollution.
2. It allows some merchandise to be sold at lower prices, benefiting less affluent
people.
3. It enables people in Third World countries and rural areas to enjoy products and
services which otherwise are not available to them.
4. Facilitates delivery of public services at a reduced cost, increases effectiveness,
and/or improves quality.
5. It enables consumers to shop or do other transactions 24 hours a day, all year round
from almost any location.
6. It provides consumers with more selections or choices.
7. It provides consumers with less expensive products and services by allowing them
to shop in many places and conduct quick comparisons.
8. It allows quick delivery of products and services, especially with digitized products.
9. Consumers can receive relevant and detailed information in seconds, rather than in
days or weeks walk-around to search a product.
10. It makes it possible to participate in virtual auctions. It allows consumers to interact
with other consumers in electronic communities and exchange ideas as well as
compare price-tag.
11. It facilitates competition, as a result of substantial discounts.
12. It expands the marketplace to national and international markets. It decreases the
cost of creating processing, distributing, storing, and retrieving paper based
information.
Disadvantage of e-Commerce
1. Businesses often calculate return on investment numbers before committing to any
new technology. Costs, which are a function of technology, can change dramatically
during even short-lived e-commerce implementation projects.
2. Many companies have had trouble recruiting and retaining employees with the
technological, design, and business process skills needed to create an effective e-
commerce presence.
3. The difficulty of integrating existing databases and transaction-processing software
designed for traditional commerce into the software that enables e-commerce.
4. Many businesses face cultural and legal impediment (barrier) to e-commerce. Some
consumers are still fearful (afraid) of sending their credit card numbers over the
Internet.
5. Consumers are simply resistant to change and are uncomfortable viewing
merchandise on a computer screen rather than in person.
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
e-Medicine
e-Medicine is an online clinical medical knowledge database, which is an approach to
providing health care service to a large number of people spread in different locations.
It is mainly beneficial for the people of rural areas with limited or no medical facilities. e-
Medicine is targeted to provide high-quality healthcare service. It minimizes the time and
cost required for treatment.
e-Medicine usually contains up-to-date, searchable, peer-reviewed medical journals,
online physician reference textbooks, and a complete article database on medical
specialties. This Internet medical library and clinical knowledge base are available to
physicians, medical students, nurses, other health professionals, and patients.
With the use of e-Medicine, doctors and patients who are physically apart can connect so
that patients can share his/her problem with the doctor, and the doctor can suggest
treatment or any test required.
e-Governance
e-Governance is the use of information and communication technology (ICT) to enhance
the access and delivery of government services to benefit citizens, business partners, and
employees. It transforms the traditional government using ICT to make it clear, effective,
and accountable. However, it doesn't mean that putting more computers on the desks of
government officials is e governance.
Governance is more than just
a government website on the
Internet. Political, social,
economic, and technological
aspects determine e-
governance. It establishes a
relationship between
government officials and
citizens, providing greater
access to government
information and services by
making the government
accessible online, promoting
citizen participation by
enabling citizens to interact more conveniently with government officials, such as by
requesting government service and filing required documents through the website,
increasing government accountability by making its operations more transparent, thereby
reducing the opportunities for corruption, and supporting development goals by providing
business, rural and traditionally underserved communities with information,
opportunities, and communications capabilities. For example,
For example,
https://www.nepal.gov.np/, https://www.moe.gov.np/, https://www.moha.gov.np/
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Objectives of e-Governance
Some of the objectives of e-Governance are:
E-Governance refers to the provision of online public services to citizens and
businesses.
Services for citizens include the registration to government services such as health
care, education, or employment benefits.
For businesses, E-Governance services can take the form of online alerts for public
procurements or funding opportunities as well as information and support on
applicable legislation in a given sector.
E-Governance helps to cut down their administrative costs, speed up procedures
and therefore increase efficiency and reactivity.
It could improve and accelerate administrative efficiency.
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Many types of mobile computers have been introduced since the 1990s, including a
wearable computer, PDA, enterprise digital assistant, smartphone, UMPC (Ultra-mobile
PC), Tablet PC
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
The Internet of Things (IoT) is a system of interrelated computing devices, mechanical and
digital machines, objects, animals, or people that are provided with unique identifiers
(UIDs) and the ability to transfer data over a network without requiring human-to-human
or human to-computer interaction.
By combining these connected devices with automated systems, it is possible to "gather
information, analyse it and create an action" to help someone with a particular task or
learn from a process. A thing in the internet of things can be a person with a heart monitor
implant, an animal with a biochip transponder, an automobile that has built-in sensors to
alert the driver when tire pressure is low, or any other natural or man-made object that
can be assigned an Internet Protocol (IP) address and can transfer data over a network.
Advantages of IoT
It automates tasks and helps to improve the quality of a business's services and
reduces.
It helps to operate the business operations more efficiently, better understand
customers to deliver enhanced customer service.
It supports to improve decision-making and increases the value of the business.
It has the ability to access information from anywhere at any time on any device.
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Disadvantages of IoT
As the number of connected devices increases and more information is shared
between devices, the chances of the system being attacked also increases.
Organizations may eventually have to deal with massive numbers (maybe even
millions) of loT devices, and collecting and managing the data from all those devices
will be challenging.
If there's a bug in the system, every connected device will likely become corrupted.
Since there's no international standard of compatibility for loT, it's difficult for
devices from different manufacturers to communicate with each other.
7.8 e-Learning
e-Learning applies to a learning/teaching or understanding about a topic with the help of
Information and Communication Technology. e-Learning allows us to learn anywhere and
usually at any time, as long as we have a properly configured computer, networks, devices,
etc. e-Learning can be CD ROM-based, Network-based, Intranet-based, or Internet-based.
It can include text, video, audio, animation, and virtual environments. It can be a very rich
learning experience that can even go beyond the lecture-based crowded classroom. It's a
self paced, hands-on learning experience. The quality of the electronic-based training, as
in every form of training, is in its content and its delivery. However, e-learning can suffer
from many of the same pitfalls (drawbacks) as classroom training, such as boring slides,
monotonous speech, and little opportunity for interaction. The beauty of e-learning is that
new software that allows the creation of very effective learning environments that can
overcome the classic material being used in traditional learning. For example,
http://www.howstuffworks.com/
The concept of e-learning has become more popular throughout the globe because of the
Covid 19 pandemic. The tools like Zoom, Microsoft Teams, Cisco Webex Meetings, Google
Meet are also used for learning purposes.
7.9 m-Commerce
m-C ommerce (mobile commerce) is the buying and selling of goods and services through
wireless technology i.e., handheld devices such as cellular telephones and personal digital
assistants (PDAs).
[ www.prasiddhaacharya.com.np ]
Computer Science Note for Grade-XII Email : acharyaprasiddha6@gmail.com
Web References:
https://www.javatpoint.com
https://www.w3schools.com
https://www.tutorialspoint.com
https://www.google.com
https://www.wikipedia.org
[ www.prasiddhaacharya.com.np ]