Cos 101 Introduction To Computer Science
Cos 101 Introduction To Computer Science
Objectives
The specific objectives of this course are to:
1. Understand the history, classification and impact of computers.
2. Know the concept of computer hardware and software.
3. Understand features of a good program.
4. Understand the concept of Algorithms and flowcharting.
5. Understand the principles of designing algorithms for common programming problem.
6. Understand the concept of debugging and maintaining program.
Learning Outcomes
At the end of the course, students should be able to:
1. explain basic components of computers and other computing devices;
2. describe the various applications of computers;
3. explain information processing and its roles in the society;
4. describe the Internet, its various applications and its impact;
5. explain the different areas of the computing discipline and its specializations; and
6. demonstrate practical skills on using computers and the internet.
Text Book(s):
1. Goel, A. (2010). Computer fundamentals. Pearson Education India.
CHARACTERISTICS OF A COMPUTER
The characteristics of the computer system are as follows –
LESSON 2
COMPONENTS OF COMPUTER SYSTEM
Computer systems consist of three components as shown in below image: Central Processing
Unit, Input devices and Output devices. Input devices provide data input to processor, which
processes data and generates useful information that’s displayed to the user through output
devices. This is stored in computer’s memory.
Central Processing Unit
The Central Processing Unit (CPU) is called “the brain of computer” as it controls operation
of all parts of computer. It consists of two components: Arithmetic Logic Unit (ALU), and
Control Unit.
KEYBOARD
Keyboard is the most common and very popular input device which helps to input data to the
computer. The layout of the keyboard is like that of traditional typewriter, although there are
some additional keys provided for performing additional functions.
Keyboards are of two sizes 84 keys or 101/102 keys, but now keyboards with 104 keys or 108
keys are also available for Windows and Internet.
The keys on the keyboard are as follows:
S/N Keys Description
These keys include the letter keys (A-Z) and digit keys (0-
1 Typing Keys 9) which generally give the same layout as that of
typewriters.
It is used to enter the numeric data or cursor movement.
Generally, it consists of a set of 17 keys that are laid out
2 Numeric Keypad
in the same configuration used by most adding machines
and calculators.
The twelve function keys are present on the keyboard
which are arranged in a row at the top of the keyboard.
3 Function Keys
Each function key has a unique meaning and is used for
some specific purpose.
These keys provide cursor and screen control. It includes
four directional arrow keys. Control keys also include
4 Control keys
Home, End, Insert, Delete, Page Up, Page Down,
Control(Ctrl), Alternate(Alt), Escape(Esc).
Keyboard also contains some special purpose keys such as
Special Purpose
5 Enter, Shift, Caps Lock, Num Lock, Space bar, Tab, and
Keys
Print Screen.
Output Devices
Output device Characteristic
Monitor • A monitor is most common type of output device.
• It is also called as “Visual Display Unit”.
• The inputs given by keyboard or any other input devices will
get displayed on monitor.
• Cathode Ray Tube (CRT) and Flat panel display monitors are
commonly used monitors.
Printers • Printers are most common type of output devices which are
used to take a hard copy of any digital document.
• The two types of printers are impact and non-impact printers.
• Non-impact printers such as laser and inkjet printers are less
noisy, more reliable and faster and also offer high quality
compared to impact printers.
Sound Systems • Sound systems are output devices which are used to get
multimedia content such as voice, music, etc., as output. Some
of examples of sound systems are speakers, headphones, and
microphones.
PRINTERS
Printer is an output device, which is used to print information on paper.
There are two types of printers:
• Impact Printers
• Non-Impact Printers
IMPACT PRINTERS
Impact printers print the characters by striking them on the ribbon, which is then pressed on
the paper.
Characteristics of Impact Printers are the following:
• Very low consumable costs
• Very noisy
• Useful for bulk printing due to low cost
• There is physical contact with the paper to produce an image
These printers are of two types -
1. Character printers
2. Line printers
Character Printers
Character printers are the printers which print one character at a time.
These are further divided into two types:
• Dot Matrix Printer (DMP)
• Daisy Wheel
Line Printers
Line printers are the printers which print one line at a time.
These are of two types -
• Drum Printer
• Chain Printer
Drum Printer
This printer is like a drum in shape hence it is called drum printer. The surface of the drum is
divided into a number of tracks. Total tracks are equal to the size of the paper, i.e., for a paper
width of 132 characters, drum will have 132 tracks. A character set is embossed on the track.
Different character sets available in the market are 48-character set, 64 and 96 characters set.
One rotation of drum prints one line. Drum printers are fast in speed and can print 300 to 2000
lines per minute.
Advantages
• Very high speed
Disadvantages
• Very expensive
• Characters fonts cannot be changed
Chain Printer
In this printer, a chain of character sets is used, hence it is called Chain Printer. A standard
character set may have 48, 64, or 96 characters.
Advantages
• Character fonts can easily be changed.
• Different languages can be used with the same printer.
Disadvantages
• Noisy
NON-IMPACT PRINTERS
Non-impact printers print the characters without using the ribbon. These printers print a
complete page at a time; thus, they are also called as Page Printers.
These printers are of two types -
• Laser Printers
• Inkjet Printers
Characteristics of Non-impact Printers
• Faster than impact printers
• They are not noisy
• High quality
• Supports many fonts and different character size
Laser Printers
These are non-impact page printers. They use laser lights to produce the dots needed to form
the characters to be printed on a page.
Advantages
• Very high speed
• Very high-quality output
• Good graphics quality
• Supports many fonts and different character size
Disadvantages
• Expensive
• Cannot be used to produce multiple copies of a document in a single printing
Inkjet Printers
Inkjet printers are non-impact character printers based on a relatively new technology. They
print characters by spraying small drops of ink onto paper. Inkjet printers produce high quality
output with presentable features.
They make less noise because no hammering is done and these have many styles of printing
modes available. Colour printing is also possible. Some models of Inkjet printers can produce
multiple copies of printing also.
Advantages
• High quality printing
• More reliable
Disadvantages
• Expensive as the cost per page is high
• Slow as compared to laser printer
COMPUTER MEMORY
Computer memory refers to storage area where data is stored. It is of two types:
• Primary Memory
• Secondary Memory
Primary Memory
Primary memory is the main memory of computer present in motherboard. Primary memory is
of two types as shown in the image below.
Random Access Memory
RAM is referred as temporary memory, in which, information stored is lost once computer is
turned off. It is a volatile memory. Instructions written in this memory can be modified; hence
it is also known as programmable memory. The two types of RAM are Static RAM (faster and
costlier) and Dynamic RAM.
Functions of RAM
• It stores data till it gets processed.
• It stores instructions for data processing.
• It acts as a working space where data processing takes place and intermediate results
are stored.
• It stores processed data/results before it is sent to output devices.
Secondary Memory
Sometimes when data to be processed is large, it cannot fit in primary memory as it is limited,
in such cases, we use supplement memory or secondary memory. Secondary memory helps to
store information permanently and is non-volatile. Examples of secondary storage memory are
compact disk, floppy disk, pen drive, external hard drive, etc.
SOFTWARE
A set of instructions that drives computer to do stipulated tasks is called a program. Software
instructions are programmed in a computer language, translated into machine language, and
executed by computer. Software can be categorized into two types:
• System software
• Application software
System Software
System software operates directly on hardware devices of computer. It provides a platform to
run an application. It provides and supports user functionality. Examples of system software
include operating systems such as Windows, Linux, Unix, etc.
Application Software
An application software is designed for benefit of users to perform one or more tasks. Examples
of application software include Microsoft Word, Excel, PowerPoint, Oracle, etc.
Computer users
Computer users are the different categories of personnel that operates the computer. We have
expert users and casual users. The expert users could be further categorized into computer
engineers, computer programmers and computer operators.
The computing environment
The computing environment ranges from the building housing the other elements of the
computing system namely the computer and the users, the furniture, auxiliary devices such as
the voltage stabilizer, the Uninterruptible Power Supply System (UPS), the fans, the air
conditioners etc. The schematic diagram of the computing system is presented in Figure 9a to
Figure 9e.
Categories of Computers
Although there are no industry standards, computers are generally classified in the following
ways:
Classification based on signal type
• Digital computer
• Analogue computer
• Hybrid computer
Classification by purpose
• Special purpose
• General purpose
Classification by capacity
• Mainframe
• Mini computers
• Micro computers
CLASSIFICATION BY PURPOSE
Depending on their flexibility in operation, computers are classified as either special purpose
or general purpose.
Special Purpose Computers
A special purpose computer is one that is designed to solve a restricted class of problems. Such
computers may even be designed and built to handle only one job. In such machines, the steps
or operations that the computer follows may be built into the hardware. Most of the computers
used for military purposes fall into this class. Other example of special purpose computers
include:
• Computers designed specifically to solve navigational problems.
• Computers designed for tracking airplane or missiles.
• Computers used for process control applications in industries such as oil refinery,
chemical manufacture, steel processing and power generation.
• Computers used as robots in factories like vehicles assembly plants and glass industries.
Attributes of Special Purpose Computers
1. Special purpose computer are usually very efficient for the tasks for which they are
specially designed.
2. They are very much less complex than the General-Purpose Computers. The simplicity
of the circuiting stems from the fact that provision is made only for limited facilities.
3. They are very much cheaper than the General-Purpose type since they involve less
components and are less complex.
General-Purpose Computers
General-Purpose computers are computers designed to handle wide range of problems.
Theoretically, a general-purpose computer can be adequate by means of some easily alterable
instructions to handle any problems that can be solved by computation. In practice however,
there are limitations imposed by memory size, speed and the type of input/output devices.
Examples of areas where the general purpose are employed include the following:
• Payroll
• Banking
• Billing
• Sales analysis
• Cost accounting
• Manufacturing scheduling
• Inventory control
LESSON 4
INTRODUCTION TO PROBLEM SOLVING TECHNIQUES
Learning Objectives
• To understand the concept of Problem solving
• To understand steps involved in algorithm development
• To understand the concept of Algorithm
• Develop Algorithm for simple problem
• To understand the concept of Flowchart development
• Draw the symbols used in Flowcharts
INTRODUCTION
A computer is a very powerful and versatile machine capable of performing a multitude of
different tasks, yet it has no intelligence or thinking power. The intelligence of a computer
depends on the human intelligence.
In order to instruct a computer correctly, the user must have clear understanding of the problem
to be solved. A part from this he should be able to develop a method, in the form of series of
sequential steps, to solve it. Once the problem is well-defined and a method of solving it is
developed, then instructing the computer to solve the problem becomes relatively easier task.
Thus, before attempt to write a computer program to solve a given problem. It is necessary to
formulate or define the problem in a precise manner. Once the problem is defined, the steps
required to solve it, must be stated clearly in the required order.
PROCEDURE (STEPS INVOLVED IN PROBLEM SOLVING)
A computer cannot solve a problem on its own. One has to provide step by step solutions of
the problem to the computer. In fact, the task of problem solving is not that of the computer. It
is the programmer who has to write down the solution to the problem in terms of simple
operations which the computer can understand and execute.
In order to solve a problem by the computer, one has to pass though certain stages or steps.
They are:
1. Understanding the problem
2. Analyzing the problem
3. Developing the solution
4. Coding and implementation.
1. Understanding the problem: Here we try to understand the problem to be solved totally.
Before with the next stage or step, we should be absolutely sure about the objectives of the
given problem.
2. Analyzing the problem: After understanding thoroughly the problem to be solved, we look
at different ways of solving the problem and evaluate each of these methods. The idea here is
to search an appropriate solution to the problem under consideration. The end result of this
stage is a broad overview of the sequence of operations that are to be carried out to solve the
given problem.
3. Developing the solution: Here the overview of the sequence of operations that was the result
of analysis stage is expanded to form a detailed step by step solution to the problem under
consideration.
4. Coding and implementation: The last stage of the problem solving is the conversion of the
detailed sequence of operations into a language that the computer can understand. Here each
step is converted to its equivalent instruction or instructions in the computer language that has
been chosen for the implementation.
ALGORITHM
Definition
A set of sequential steps usually written in Ordinary Language to solve a given problem is
called Algorithm.
It may be possible to solve to problem in more than one ways, resulting in more than one
algorithm. The choice of various algorithms depends on the factors like reliability, accuracy
and easy to modify. The most important factor in the choice of algorithm is the time
requirement to execute it, after writing code in High-level language with the help of a computer.
The algorithm which will need the least time when executed is considered the best.
Steps involved in algorithm development
An algorithm can be defined as “a complete, unambiguous, finite number of logical steps for
solving a specific problem “.
Step1. Identification of input: For an algorithm, there are quantities to be supplied called input
and these are fed externally. The input is to be identified first for any specified problem.
Step2: Identification of output: From an algorithm, at least one quantity is produced, called for
any specified problem.
Step3 : Identification the processing operations : All the calculations to be performed in order
to lead to output from the input are to be identified in an orderly manner.
Step4 : Processing Definiteness : The instructions composing the algorithm must be clear and
there should not be any ambiguity in them.
Step5 : Processing Finiteness : If we go through the algorithm, then for all cases, the algorithm
should terminate after a finite number of steps.
Step6 : Possessing Effectiveness : The instructions in the algorithm must be sufficiently basic
and in practice they can be carries out easily.
An algorithm must possess the following properties
1. Finiteness: An algorithm must terminate in a finite number of steps
2. Definiteness: Each step of the algorithm must be precisely and unambiguously stated
3. Effectiveness: Each step must be effective, in the sense that it should be primitive easily
convert able into program statement) can be performed exactly in a finite amount of time.
4. Generality: The algorithm must be complete in itself so that it can be used to solve problems
of a specific type for any input data.
5. Input/output: Each algorithm must take zero, one or more quantities as input data produce
one or more output values. An algorithm can be written in English like sentences or in any
standard representation sometimes, algorithm written in English like languages are called
Pseudo Code.
Example
1. Suppose we want to find the average of three numbers, the algorithm is as follows
Step 1 Read the numbers a, b, c
Step 2 Compute the sum of a, b and c
Step 3 Divide the sum by 3
Step 4 Store the result in variable d
Step 5 Print the value of d
Step 6 End of the program
2. Write an algorithm to calculate the simple interest using the formula. Simple interest = P*N*
R/100.
Where P is principle Amount, N is the number of years and R is the rate of interest.
Step 1: Read the three input quantities’ P, N and R.
Step 2 : Calculate simple interest as
Simple interest = P* N* R/100
Step 3: Print simple interest.
Step 4: Stop.
3. Area of Triangle: Write an algorithm to find the area of the triangle.
Let b, c be the sides of the triangle ABC and A the included angle between the given sides.
Step 1: Input the given elements of the triangle namely sides b, c and angle between the sides
A.
Step 2: Area = (1/2) *b*C* sin A
Step 3: Output the Area
Step 4: Stop.
4. Write an algorithm to find the largest of three numbers X, Y,Z.
Step 1: Read the numbers X,Y,Z.
Step 2: if (X > Y)
Big = X
else BIG = Y
Step 3 : if (BIG < Z)
Step 4: Big = Z
Step 5: Print the largest number i.e. Big
Step 6: Stop.
FLOW CHART
A flow chart is a step-by-step diagrammatic representation of the logic paths to solve a given
problem. Or A flowchart is visual or graphical representation of an algorithm.
The flowcharts are pictorial representation of the methods to be used to solve a given problem
and help a great deal to analyze the problem and plan its solution in a systematic and orderly
manner. A flowchart when translated in to a proper computer language, results in a complete
program.
Advantages of Flowcharts
1. The flowchart shows the logic of a problem displayed in pictorial fashion which felicitates
easier checking of an algorithm.
2. The Flowchart is good means of communication to other users. It is also a compact means
of recording an algorithm solution to a problem.
3. The flowchart allows the problem solver to break the problem into parts. These parts can be
connected to make master chart.
4. The flowchart is a permanent record of the solution which can be consulted at a later time.
Differences between Algorithm and Flowchart
Algorithm Flowchart
1. A method of representing the step-by-step 1. Flowchart is diagrammatic representation
logical procedure for solving a problem of an algorithm. It is constructed using
different types of boxes and symbols.
2. It contains step-by-step English 2. The flowchart employs a series of blocks
descriptions, each step representing a and arrows, each of which represents a
particular operation leading to solution of particular step in an algorithm
problem
3. These are particularly useful for small 3. These are useful for detailed
problems representations of complicated programs
4. For complex programs, algorithms prove 4. For complex programs, Flowcharts prove
to be Inadequate to be adequate
b. Input and output indicators: Parallelograms are used to represent input and output operations.
Statements like INPUT, READ and PRINT are represented in these Parallelograms.
c. Process Indicators: - Rectangle is used to indicate any set of processing operation such as for
storing arithmetic operations.
d. Decision Makers: The diamond is used for indicating the step of decision making and
therefore known as decision box. Decision boxes are used to test the conditions or ask questions
and depending upon the answers, the appropriate actions are taken by the computer. The
decision box symbol is
e. Flow Lines: Flow lines indicate the direction being followed in the flowchart. In a Flowchart,
every line must have an arrow on it to indicate the direction. The arrows may be in any direction
f. On- Page connectors: Circles are used to join the different parts of a flowchart and these
circles are called on-page connectors. The uses of these connectors give a neat shape to the
flowcharts. Ina complicated problems, a flowchart may run in to several pages. The parts of
the flowchart on different pages are to be joined with each other. The parts to be joined are
indicated by the circle.
SIMPLE PROBLEMS USING FLOW CHART
Draw the Flowchart for the following
1. Draw a flowchart to find out the biggest of the three unequal positive numbers.
2. Draw a flowchart for adding the integers from 1 to 100 and to print the sum.
PSEUDO CODE
The Pseudo code is neither an algorithm nor a program. It is an abstract form of a program. It
consists of English like statements which perform the specific operations. It is defined for an
algorithm. It does not use any graphical representation. In pseudo code, the program is
represented in terms of words and phrases, but the syntax of program is not strictly followed.
Advantages: * Easy to read, * Easy to understand, * Easy to modify.
Example: Write a pseudo code to perform the basic arithmetic operations.
Read n1, n2
Sum = n1 + n2
Diff = n1 – n2
Mult = n1 * n2
Quot = n1/n2
Print sum, diff, mult, quot
End.
LESSON 5
INFORMATION AND COMMUNICATION TECHNOLOGY
Introduction
ICT stands for Information and Communication Technology, which is a technology that allows
us to search for information and to communicate with each other. In the past few decades, ICT
offers society with a huge array of new communication capabilities, such as home and domestic
activities, employment, education, health, commerce, banking, and social networking websites.
We are now actually in the digital age so the numbers of ICT gadgets such as computers,
laptops, internet, mobile phones, tablets, etc., are available into our lives. People catch ups the
most recent trends and move up in life with the use of ICT. In the last few decades, ICT has
become the necessity rather than the exception.
What is ICT?
Information and communications technology (ICT) is often used as an extended synonym for
information technology (IT), but is a more specific term that stresses the role of unified
communications. ICT provides access to information through telecommunications. It is similar
to Information Technology (IT), but concentrates mostly on communication technologies such
as the Internet, wireless networks, cell phones, and other communication mediums. ICT
includes any communication device or application, encompassing: radio, television, cell
phones, computer, laptops, tablets, and network hardware and software, etc. ICT also provides
the various services online and applications associated with them.
Effects of ICT in our Everyday Life
ICT has affected lives by improving timely distribution of information through the media and
improved communications in homes and work places through social networks, emails, etc. ICT
has extremely enhanced the quality of human life. For examples, writing a letter could take few
days to arrive to the receiver but by writing an e-mail reach in just a minute. ICT affects various
fields of daily life some of them are discussed below:
As Home and Domestic Activities
We can connect and controls domestic equipment (such as washing machine, refrigerator, cell-
phones, laptops etc.). Carry out net banking, online shopping, read newspapers online, watch
TV programs, learn online and connects ourselves to our family, friends, or relatives while we
are at long distance by using the e-mail, messenger, call-conference, or video-conference.
As Social Networking
There are many social networking sites that are available like FACEBOOK, TWITTER, and
LINKEDIN which allows users to communicate and stay connected with each other across the
globe regularly. All these sites have helped to narrow the physical distances between people.
Social Networking provides facilities such as faster communication speed, effective sharing of
information, paperless environment, etc.
As Education/E-Learning
E-Learning is an electronic learning, in which the learner uses a computer to learn a task, skill,
or process at a given time online. Students can learn by watching videos, e-books, discussion
groups, bulletin boards, blogs and e-learning in a collaborate environment. Students can also
ask question to their teacher using emails. Educational institutes uses projector to teach
students.
As Health
When we get sick, we don't like to go outside even to visit the doctors. Today, people can get
online solution to health issues through the use of ICT gadgets or connect to their doctor online
to describe their problems. It is helpful to medical students to learn about disease, medicines,
and surgeries. Doctors can demonstrate major surgical operations to medical students by the
use of ICT. Doctors can operate critical patient in guidance of many specialist surgeons through
video-conferencing.
As Shopping/Commerce
Online shopping involves E-commerce. It draws on such technologies as electronic funds
transfer, online transaction processing, Inventory management system and automated data
collection systems. It makes buying and selling activities easier, more efficient and faster by
using computers, internet and shared software. We can pay for the items on the internet with a
safe internet payment option. Product advertising is also possible through ICT.
As Banking
Banking helped us to buy things using E-commerce. It carries out electronic transactions
through Debit/Credit cards, net banking and Air/Rail tickets booking at any place at any time
with the use of the same banking account. We can save our time, access accounts for loan
applications, transactions and update our cash flow at any time. Banking is facilitated with
virtual money so it introduces an Eco-friendly world.
As Employment/Jobs
ICT increases the number of employments in our society. People can work as Web developer,
IT network administrator, etc. who have skills in ICT. It gives new job opportunities for many
people to become successful self-employer to work from their home.
Advantages of ICT
Daily routine Management
We can store and manage our daily schedule information using ICT gadgets. We can also
integrate ICT with domestic equipment for use and control. We can also use net banking, online
payments and online trading for purchasing daily needed items. It will save our time to go to
the market and purchase things.
Social Relationship
ICT provides the facility to make contacts and maintain relationships with people around the
world in our daily routine. With the use of Internet and communication channel, we can connect
people via e-mail, social networking websites and cell phones. It saves time and it is less
expensive.
Information Sharing
Now information is just right on our fingertips. We can access any information anywhere and
anytime. Information, news, views, etc. can be shared by people all around the globe with the
use of e-mail, discussion groups on the Internet such as Google Groups, Yahoo! Groups etc.
By the sharing of information, it develops global awareness such as cultures, religions,
ideologies and lifestyles. These create an environment of openness and increases mutual
respect.
Communication
We can communicate each other without boundaries. It becomes quicker because we can send
an instant message in a fraction of time which saves costs and man power for delivery. For that
E-mail, teleconferencing, and video-conferencing are available. By the use of video
conferencing technique, we can get the feeling of communicating with someone face to face.
Entertainment
ICT can be used as access to entertainment. We can play games, launch of digital TV, Chatting,
watch videos on NETFLIX, listen to songs, watch or listen to the news, and many more.
Education
New ways of learning are possible through ICT such as e-learning, distance learning, on-line
materials, virtual learning and interactive multi-media. Students can be part of these various
learning and teaching from all over the world. For the impossible experiments, we can use
simulations and virtual reality.
Self-Employment
We can create our own business shops without the heavy overheads of place, purchase of items
and make use of social media for advertising our business. This has increased sales and
encourages the small businesses.
Paperless Environment
ICT can be used to store and retrieve information instead of paper. Use of ICT involved less
papers, thus it saves the trees and makes our environment healthy.
Developing Health Literacy
With the immediate feedback from doctors, we become well sooner. Health literacy deals with
the need for people to access and use high quality information about disease and medicines
through internet health care services available in ICT gadgets.
Disadvantages of ICT
Reduced face-to-face interaction
Nowadays, people like online communication rather than real conversations; so, people tend
to become more individualistic and introvert. Other limitation is that we are not able to express
our feeling or what we actually want to say by the use of e-mail or social networking sites.
Thus, we required face to face communication with them to express our real feeling.
Social Disconnect
Although the internet has reduced physical distances between people, but that doesn’t mean
they brought everyone closer together. Emotional distance has increased in some aspects.
People are always busy with their own virtual world and thus forget the real world with family
and friends. Children too are spending more time in virtual world and they adopt wrong
thoughts thus leading to cybercrimes and extra marital affairs with the use of ICT gadgets.
Reduced physical activity/Health Problems
Users may accept a more sitting lifestyle by the use of ICT gadgets. This can lead to health
problems such as headache, fatness, heart disease, diabetes, repetitive strain injury or eyestrain,
wrong posture/position, neck pain, physical and mental stress, etc. because of continuous use
of the computer. In this kind of lifestyle there is lack of physical exercise, and thus increases
health risk.
Cost
Many ICT gadgets are expensive. Poor students cannot get the benefits of e-learning due to the
educational to the expensive nature of some ICT gadgets.
Job loss
Job losses may occur because of manual operations being replaced by automation.
Security/loss of privacy
Each ICT gadgets are integrated to use Internet connections. The connections must be secured
from virus attacks to secure personal data. Use of social networking website can lead to risk of
loss of personal data. When we use Net banking, online payment then there is a risk of losing
our money to fraud. They can transfer our money to their account.
LESSON 6
INTRODUCTION TO INTERNET
The concept of the Internet
The Internet is a worldwide, publicly accessible series of interconnected computer networks
that transmit data by packet switching using the standard Internet Protocol (IP).
It is a "network of networks" that consists of millions of smaller domestic, academic, business,
and government networks, which together carry various information and services, such as
electronic mail, online chat, file transfer, and the interlinked web pages and other resources of
the World Wide Web (WWW).
It is a global network connecting millions of computers. More than 1000 countries are linked
into exchanges of data, news and opinions. Unlike online services, which are centrally
controlled, the Internet is decentralized by design. Each Internet computer, called a host, is
independent. Its operators can choose which Internet services to use and local services to make
available to the global Internet community.
History of Internet
The United States started the Advanced Research Projects Agency, known as ARPA in
February 1958 to regain a technological lead and as a way for government researchers to share
information.
In 1969, ARPA, a part of the Department of Defence (DOD), awarded a contract to construct
a computer network. The network was used to link researchers at universities with defense
contractors, researchers, scientists and military contractors so that they can share information
and resources. This network was called the ARPANET. It was a communications network
which allowed computers at distant locations to "talk" with each other in order to exchange
military and national security data.
In 1973, ARPA was changed to the Defense Advanced Research Agency (DARPA) and the
resulting network to DARPANET. An important task for this newly named agency was to begin
a project called “the interneting project”, which would start the process of linking different
networks together.
Between 1969 and 1983, minicomputers, mainframes and super computers made up the
networks. This network had file transfer capabilities, electronic mail and mailing list services.
ARPANET ultimately evolved into what we now know as the Internet.
Advantages of Intranets
• Workforce productivity: Intranets can help users to locate and view information faster
and use applications relevant to their roles and responsibilities. With the help of a web
browser interface, users can access data held in any database the organization wants to
make available, anytime and - subject to security provisions - from anywhere within
the company workstations, increasing employees' ability to perform their jobs faster,
more accurately, and with confidence that they have the right information. It also helps
to improve the services provided to the users.
• Time: With intranets, organizations can make more information available to employees
on a "pull" basis (i.e., employees can link to relevant information at a time which suits
them) rather than being deluged indiscriminately by emails.
• Communication: Intranets can serve as powerful tools for communication within an
organization, vertically and horizontally.
• Web publishing allows 'cumbersome' corporate knowledge to be maintained and easily
accessed throughout the company using hypermedia and Web technologies. Examples
include: employee manuals, benefits documents, company policies, business standards,
news feeds, and even training, can be accessed using common Internet standards
(Acrobat files, Flash files, CGI applications). Because each business unit can update
the online copy of a document, the most recent version is always available to employees
using the intranet.
• Cost-effective: Users can view information and data via web-browser rather than
maintaining physical documents such as procedure manuals, internal phone list and
requisition forms.
• Promote common corporate culture: Every user is viewing the same information within
the Intranet.
• Enhance Collaboration: With information easily accessible by all authorized users,
teamwork is enabled.
• Cross-platform Capability: Standards-compliant web browsers are available for
Windows, Mac, and UNIX.
Extranet
• Intranets differ from "Extranets" in that the former are generally restricted to employees
of the organization while extranets can generally be accessed by customers, suppliers,
or other approved parties.
• An extranet is a private network that uses Internet protocols, network connectivity, and
possibly the public telecommunication system to securely share part of an
organization's information or operations with suppliers, vendors, partners, customers or
other businesses.
• An extranet can be viewed as part of a company's Intranet that is extended to users
outside the company (e.g.: normally over the Internet).
• It has also been described as a "state of mind" in which the Internet is perceived as a
way to do business with a pre-approved set of other companies’ business-to-business
(B2B), in isolation from all other Internet users. In contrast, business-to-consumer
(B2C) involves known server(s) of one or more companies, communicating with
previously unknown consumer users.
• An extranet requires security and privacy. These can include firewalls, server
management, the issuance and use of digital certificates or similar means of user
authentication, encryption of messages, and the use of virtual private networks (VPNs)
that tunnel through the public network.
Advantages of Extranet
• Exchange large volumes of data using Electronic Data Interchange (EDI).
• Share product catalogs exclusively with wholesalers or those "in the trade".
• Collaborate with other companies on joint development efforts.
• Jointly develop and use training programs with other companies.
• Provide or access services provided by one company to a group of other companies,
such as an online banking application managed by one company on behalf of affiliated
banks.
• Share news of common interest exclusively.
Disadvantages of Extranet
• Extranets can be expensive to implement and maintain within an organization (e.g.:
hardware, software, employee training costs) — if hosted internally instead of via an
ASP.
• Security of extranets can be a big concern when dealing with valuable information.
System access needs to be carefully controlled to avoid sensitive information falling
into the wrong hands.
• Extranets can reduce personal contact (face-to-face meetings) with customers and
business partners. This could cause a lack of connections made between people and a
company, which hurts the business when it comes to loyalty of its business partners and
customers.
Differences between Internet, Intranet and Extranet
Criteria Internet Intranet Extranet
A private network that shares
Publicly A private network that is part of an organization's
Accessibility Accessible contained within an information or operations with
World-Wide enterprise. suppliers, vendors, partners,
customers or other businesses.
Privacy Limited Privacy No privacy Provides privacy.
Requires only a network Complex requiring
Simplicity Very Complex
cable Servers/Routers/Switches
Ease of Set-up Not Applicable Very easy to setup Difficult to set up
Cost Not Applicable Inexpensive-Cheap Expensive
Security Limited Minimal security Security maintained
Require a staff to ensure
Maintenance Not Applicable Easy to Maintain
efficient operation.
Size Global Small in scope Larger in scope
INTERNET SERVICES
The various Internet services include:
• E-commerce
Electronic commerce, commonly known as e-commerce or eCommerce, consists of the buying
and selling of products or services over electronic systems such as the Internet and other
computer networks.
• WWW (World Wide Web)
The Internet consists of many services. What most people hear about however is the World
Wide Web (WWW). This is a graphical environment that allows text and pictures to be
displayed on your screen, via software called Web browsers (such as Microsoft Internet
Explorer, Google Chrome, Mozilla etc.). In addition, sound and movies are also supported on
the WWW.
• E-mail (Electronic Mail)
Email is available over the Internet enabling you to send and receive messages on a global
basis. Even better, you can communicate globally for the cost of a local phone call. The reason
for this is that you connect to the Internet via your ISP (Internet Service Provider) by dialling
a local number. Once connected to the Internet, you can send and receive emails with someone
in the same room or on the other side of the world - It makes no difference to your phone bill.
In the same way you can browse Web pages globally, also at local call rates.
• Newsgroups
Newsgroups are included in the Internet. They can be accessed via your Web browser and
enable you to take part in discussions of interest to you with like-minded people from around
the world. Typically, a newsgroup is focused on a particular topic. Some newsgroups allow the
posting of messages on a wide variety of themes, regarding anything a member chooses to
discuss as on-topic, while others keep more strictly to their particular subject, frowning on off-
topic postings.
• File Transfer Protocol (FTP)
FTP (File Transfer Protocol) is simply a way of transferring files to and from the Internet. Often
this is done using your browser, or you may obtain specialist FTP software programs. FTP sites
are typically used for uploading and downloading files to a central server computer, for the
sake of file distribution.
• Bulletin Board services
A Bulletin Board System, or BBS, is a computer system running software that allows users to
connect and login to the system using a terminal program.
Originally BBS were accessed only over a phone line using a modem, but by the early 1990s
some BBS allowed access via a Telnet or packet radio connection.
Once a user logged in, they could perform functions such as downloading or uploading
software and data, reading news, and exchanging messages with other users. Many BBS also
offered on-line games, in which users could compete with each other, and BBS with multiple
phone lines often offered chat rooms, allowing users to meet each other.
Today, Internet forums occupy much of the same social and technological space as BBS did.
Today the term BBS is often used to refer to any online forum or message board.
• Audio Video Communication
Voice over Internet Protocol (VoIP) is a general term for a family of transmission technologies
for delivery of voice communications over the Internet or other packet-switched networks.
• Digital Library
A digital library is a library in which collections are stored in digital formats (as opposed to
print, microform, or other media) and accessible by computers. The digital content may be
stored locally, or accessed remotely via computer networks. A digital library is a type of
information retrieval system.
• Telnet
Telnet (Telecommunication network) is a network protocol used on the Internet or local area
network (LAN) connections.
LESSON 7
DATA COMMUNICATION AND NETWORK
Data communication
Data communications simply refers to a set of computer system that uses telecommunications
for the exchange of data or information.
Data communications are the exchange of data between two devices via some form of
transmission medium such as a wire cable. For data communications to occur, the
communicating devices must be part of a communication system made up of a combination of
hardware (physical equipment) and software (programs).
It is clear from the above that data communication involves an interconnectivity of various
computer hardware in a special way which can be describes as (topology), coupled with some
laid down set of rules and regulation which guides the initiation of data transmission
(protocols). The data transmission process is a function of the medium (communication
channels), speed, direction and mode which is called transmission characteristics.
The data communication architecture is made up of both hardware and software components.
The hardware components include the following: keyboard, modem, Network Interface Card
(NIC), routers, bridges, and intelligent PC while the software component comprises of the
following: network protocols and operating systems which guides the conversion of digital
codes to electronic signals and vice versa.
Communication channels
Communications channels unite data communication hardware and provide a physical pathway
for the exchange of data. This physical medium is the most critical link in the data
communication system. If the link is broken, the message dies.
Communication channels are built on four basic principles: physical medium, transmission
characteristics, protocol and topology.
Transmission characteristics
The transmission characteristics of the communication channels determine the system’s
performance. These computers can be divided into three functional groups: transmission speed,
transmission direction and transmission mode.
Transmission speed
The transmission speed of a communication channel determines how much data can be
transmitted over the physical medium in a given period of time. This rate is usually measured
in bits per second or bps.
Transmission direction
The transmission direction of a communication channel refers to the ability of the media to
handle simultaneous transmission.
Simplex
In simplex mode, the communication is unidirectional, as on a one-way street. Only one of the
two devices on a link can transmit; the other can only receive. Keyboards and traditional
monitors are examples of simplex devices. The keyboard can only introduce input; the monitor
can only accept output. The simplex mode can use the entire capacity of the channel to send
data in one direction.
Figure 10a. Simplex
Half-Duplex
In half-duplex mode, each station can both transmit and receive, but not at the same time. When
one device is sending, the other can only receive, and vice versa.
The half-duplex mode is like a one-lane road with traffic allowed in both directions. When cars
are traveling in one direction, cars going the other way must wait. In a half-duplex transmission,
the entire capacity of a channel is taken over by whichever of the two devices is transmitting
at the time. Walkie-talkies and CB (citizens band) radios are both half-duplex systems.
The half-duplex mode is used in cases where there is no need for communication in both
directions at the same time; the entire capacity of the channel can be utilized for each direction.
Full-Duplex
In full-duplex (also called duplex), both stations can transmit and receive simultaneously. One
common example of full-duplex communication is the telephone network. When two people
are communicating by a telephone line, both can talk and listen at the same time.
The full-duplex mode is used when communication in both directions is required all the time.
The capacity of the channel, however, must be divided between the two directions.
Components
A data communications system has five components.
Types of networks
There are 3 main types of networks
1. Local Area Network (LAN): A LAN is usually privately owned and links the devices
in a single office, building, or campus.
2. Wide Area Network. A wide area network (WAN) provides long-distance transmission
of data, image, audio, and video information over large geographic areas that may
comprise a country, a continent, or even the whole world.
3. Metropolitan Area Networks. A metropolitan area network (MAN) is a network with a
size between a LAN and a WAN. It normally covers the area inside a town or a city. It
is designed for customers who need a high-speed connectivity, normally to the Internet,
and have endpoints spread over a city or part of city. A good example of a MAN is the
part of the telephone company network that can provide a high-speed DSL line to the
customer. Another example is the cable TV network that originally was designed for
cable TV, but today can also be used for high-speed data connection to the Internet.
Interconnecting devices
LANs, WANs, and MANs each speak their own language; the process of connecting multiple
dissimilar systems requires very flexible advanced interconnecting devices, these devices
include:
a. Repeater: Repeaters are simple interconnecting devices that connect two identical
cabling segments of a LAN. A repeater accepts weak signals and electrically
regenerates them and then sends the messages back on their way.
b. Bridges: Bridges are more intelligent than repeaters, they go beyond simply
regenerating weak signals. Bridges process network signals and ensure smooth passage
from LAN to LAN and from LAN to WAN.
c. Routers: Routers contain advanced algorithms that allow them to make intelligent
decisions about where a message should go and what path to use for greater efficiency.
d. Gateways: Gateways approach interconnectivity from a completely different angle.
These devices use more of software translation than hardware routing. They are
required when network messages travel between two entirely different systems.
Protocols
In computer networks, communication occurs between entities in different systems. An entity
is anything capable of sending or receiving information. However, two entities cannot simply
send bit streams to each other and expect to be understood. For communication to occur, the
entities must agree on a protocol. A protocol is a set of rules that govern data communications.
A protocol defines what is communicated, how it is communicated, and when it is
communicated.
The sole purpose of protocol is to provide guidance to the communication channels and to
promote harmonious connectivity between the many network components. Protocols work on
the electronic level. They are initiated and controlled by advanced subroutines built into each
NIC.
LANs commonly use one of three communications protocols: CSMA, polling and token
passing.
CSMA
CSMA stands for Carrier Sense Multiple Access. CSMA relies on a share trunk of cabling; the
trunk is a single run of cabling that extends throughout the topology of the LAN. Here is how
the protocol works:
1. Workstation A has a message for workstation B. Workstation A listens to the trunk and
waits until all is clear (Carrier Sensing).
2. When A detects that the trunk is clear, the workstation marks the message with a
destination address and sends it over the trunk. All other workstations continually
monitor the trunk for a message with their address (multiple access).
3. Workstation B finds a match, accepts the message and returns an acknowledgement of
receipt.
Polling
Polling refers on a central controlling node (workstation or file server). The central node polls
each station to determine whether there is a message to be sent. When a sending workstation is
ready, the central node reserves the network channel and the message is sent. Polling is
typically used in a centralized system because this type of protocol relies exclusively on the
intelligence and dexterity of the central controlling node.
Token passing
In the token-passing method, the stations in a network are organized in a logical ring. In other
words, for each station, there is a predecessor and a successor. The predecessor is the station
which is logically before the station in the ring; the successor is the station which is after the
station in the ring. The current station is the one that is accessing the channel now. The right to
this access has been passed from the predecessor to the current station. The right will be passed
to the successor when the current station has no more data to send.
But how is the right to access the channel passed from one station to another? In this method,
a special packet called a token circulates through the ring. The possession of the token gives
the station the right to access the channel and send its data. When a station has some data to
send, it waits until it receives the token from its predecessor. It then holds the token and sends
its data. When the station has no more data to send, it releases the token, passing it to the next
logical station in the ring. The station cannot send data until it receives the token again in the
next round. In this process, when a station receives the token and has no data to send, it just
passes the data to the next station.
TYPES OF TOPOLOGIES
Type of Connection
A network is two or more devices connected through links. A link is a communications
pathway that transfers data from one device to another.
Point-to-Point
A point-to-point connection provides a dedicated link between two devices. The entire capacity
of the link is reserved for transmission between those two devices.
Mesh
In a mesh topology, every device has a dedicated point-to-point link to every other device. The
term dedicated means that the link carries traffic only between the two devices it connects. To
find the number of physical links in a fully connected mesh network with n nodes, we first
consider that each node must be connected to every other node.
Advantages
• First, the use of dedicated links guarantees that each connection can carry its own data
load, thus eliminating the traffic problems that can occur when links must be shared by
multiple devices.
• Second, a mesh topology is robust. If one link becomes unusable, it does not
incapacitate the entire system.
• Third, there is the advantage of privacy or security. When every message travels along
a dedicated line, only the intended recipient sees it.
• Finally, point-to-point links make fault identification and fault isolation easy.
Disadvantages
The main disadvantages of a mesh are related to the amount of cabling and the number of I/O
ports required.
• First, because every device must be connected to every other device, installation and
reconnection are difficult.
• Second, the sheer bulk of the wiring can be greater than the available space (in walls,
ceilings, or floors) can accommodate.
• Finally, the hardware required to connect each link (I/O ports and cable) can be
prohibitively expensive.
One practical example of a mesh topology is the connection of telephone regional offices in
which each regional office needs to be connected to every other regional office.
Ring Topology
In a ring topology, each device has a dedicated point-to-point connection with only the two
devices on either side of it. A signal is passed along the ring in one direction, from device to
device, until it reaches its destination. Each device in the ring incorporates a repeater. When a
device receives a signal intended for another device, its repeater regenerates the bits and passes
them along.
Figure 17. Ring
Advantages
• Relatively easy to install and reconfigure.
• Fault isolation is simplified. Generally, in a ring, a signal is circulating at all times. If
one device does not receive a signal within a specified period, it can issue an alarm.
The alarm alerts the network operator to the problem and its location.
Disadvantages
• Unidirectional traffic.
• In a simple ring, a break in the ring (such as a disabled station) can disable the entire
network. This weakness can be solved by using a dual ring or a switch capable of
closing off the break.
Hybrid Topology
A network can be hybrid. For example, we can have a main star topology with each branch
connecting several stations in a bus topology.
HANDS-ON
The students should be introduced to practical in MS Excel such as Formulas, SUM,
Percentage, IF, Nested IF, AND, OR functions etc.
Creating a Document
When a new document is created it has to be formatted to look attractive and presentable. This
determines how the document will look like when finished and printed. The author of the
document could decide to format the document before or after typing.
Steps to Create a blank document
1. Open Word. Or, if Word is already open, select File > New.
2. Select Blank document.
Exercise 1: Type the following passage
New rules to Rationale management;
Foremost: Rationale is the justification of decisions. Rationale models represents the
reasoning that leads to the decisions, including its functionality- and its implementation.
Rationale is critical in two areas: It supports the decisions making and it supports the capture
of knowledge. Rationale includes:
• The issues that were addressed
• The alternatives that were considered
• The decisions that were made to resolve the issues
• The criteria that were used to guide decisions
In the context of decision making the rationale improves the quality of decisions by making
decision elements, such as criteria, priorities, and arguments, explicit. In the context of
knowledge capture, the rationale is the most important information in the development process.
Saving a Document
It is good to cultivate the habit of saving one’s work periodically while typing to avoid loss of
information in case of an interrupted power supply.
To save, follow the steps below:
1. Select File from the Menu
2. Select Save As. A dialogue box appears as shown below:
A
drop cap (dropped capital) is a large capital letter used as a decorative element at the
beginning of a paragraph or section. The size of a drop cap is usually two or more
lines.
Add a drop cap
1. Select the first character of a paragraph.
2. Go to INSERT > Drop Cap.
3. Select the drop cap option you want.
• To create a drop cap that fits within your paragraph, select Dropped.
• To create a drop cap that is in the margin, outside of your paragraph, select In
margin.
Remove a drop cap
1. Highlight the large drop cap letter.
2. Go to INSERT > Drop Cap, and select None.
MAIL MERGE
Mail merge is an MS word feature that lets you create letters for a number of people without
typing the original letter more than once. The letter is saved in a separate file called form file.
A letter form file contains all the formatting information, text, and graphics you want to be
common to each other. Next you create the data file that contains all the names and addresses
that should go with the letter. Finally, in order to create the complete letters, you merge the
form file with the data file.
Steps to create Mail Merge
1. In a blank Microsoft Word document, click on the Mailings tab, and in the Start Mail
Merge group, click Start Mail Merge.
2. Click Step-by-Step Mail Merge Wizard
3. Select your document type. In this demo we will select Letters. Click Next: Starting
document.
4. Select the starting document. In this demo we will use the current (blank) document.
Select Use the current document and then click Next: Select recipients.
5. Select recipients. In this demo we will create a new list, so select Type a new list and
then click Create.
• Create a list by adding data in the New Address List dialog box and clicking
OK.
• Save the list.
• Note that now that a list has been created, the Mail Merge Wizard reverts to Use
an existing list and you have the option to edit the recipient list.
• Selecting Edit recipient list opens up the Mail Merge Recipients dialog box,
where you can edit the list and select or unselect records. Click OK to accept
the list as is.
• Click Next: Write your letter.
6. Write the letter and add custom fields.
• Click Address block to add the recipients' addresses at the top of the document.
• In the Insert Address Block dialog box, check or uncheck boxes and select
options on the left until the address appears the way you want it to.
• Note that you can use Match Fields to correct any problems. Clicking Match
Fields opens up the Match Fields dialog box, in which you can associate the
fields from your list with the fields required by the wizard.
7. Press Enter on your keyboard and click Greeting line to enter a greeting.
8. In the Insert Greeting Line dialog box, choose the greeting line format by clicking the
drop-down arrows and selecting the options of your choice, and then click OK.
9. Note that the address block and greeting line are surrounded by chevrons (« »). Write a
short letter and click Next: Preview your letters.
LABORATORY EXERCISE
1. The tutor should guide the students in the computer Laboratory on how to generate and
insert automatic table of contents in MS word.
LESSON 9
INTRODUCTION TO FORTRAN
FORTRAN is the programming language that gave birth to many scientific computer languages
available today. The name FORTRAN means FORmula TRANslation. The language was
developed by a team led by John Backus in 1954. The language is one of the earliest high-level
languages. The language was released officially in April 1957 and by 1958, more than 50% of
all IBM 704 computer programs were written in FORTRAN. There are a lot of problems with
the initial FORTRAN such as no subroutines, limited number of statement types. These
problems were addressed in FORTRAN II and it was released towards the end of 1958.
In 1962 FORTRAN IV was released which is a major improvement to FORTRAN II.
FORTRAN IV was used for almost 15 years before the release of FORTRAN 77 IN 1977. The
next major update after FORTRAN 77 was FORTRAN 90 which was followed by FORTRAN
95, FORTRAN 2003 and FORTRAN 2008, respectively.
For this course, FORTRAN 95 and FORTRAN 2003 will be the focus in COS 101 and two
language variants will be referred to as FORTRAN 95/2003.
INSTALL FTN95 PERSONAL EDITION
• Search for Silverfrost FTN5 personal edition or click this link
http://www.silverfrost.com/32/ftn95/ftn95_personal_edition.aspx.
• Download and install the software accepting all the defaults.
Basics
The basic character set of FORTRAN contains:
• the letters A ... Z and a ... z
• the digits 0 ... 9
• the underscore (_) character
• the special characters = : + blank - * / ( ) [ ] , . $ ' ! " % & ; < > ?
Tokens are made of characters in the basic character set. A token could be a keyword, an
identifier, a constant, a string literal, or a symbol.
Program statements are made of tokens.
Identifier
An identifier is a name used to identify a variable, procedure, or any other user-defined item.
A name in FORTRAN must follow the following rules:
• It cannot be longer than 31 characters.
• It must be composed of alphanumeric characters (all the letters of the alphabet, and the
digits 0 to 9) and underscores (_).
• First character of a name must be a letter.
• Names are case-insensitive-
Keywords
Keywords are special words, reserved for the language. These reserved words cannot be used
as identifiers or names.
The following table, lists the FORTRAN keywords:
Non-I/O keywords
allocatable allocate assign assignment block data
call case character common complex
contains continue cycle data deallocate
double
default do else else if
precision
end block end
elsewhere end do end if
data function
end end
end interface end module end select
program subroutine
end type end where entry equivalence exit
external function go to if implicit
in inout integer intent interface
intrinsic kind len logical module
namelist nullify only operator optional
out parameter pause pointer private
program public real recursive result
return save select case stop subroutine
target then type type() use
Where While
Integer Type
The integer types can hold only integer values. The following example extracts the
largest value that can be held in a usual four-byte integer:
program testingInt
implicit none
integer :: largeval
print *, huge(largeval)
end program testingInt
When you compile and execute the above program it produces the following result:
2147483647
Note that the huge() function gives the largest number that can be held by the specific integer
data type. You can also specify the number of bytes using the kind specifier. The following
example demonstrates this:
program testingInt
implicit none
!two byte integer
integer(kind=2) :: shortval
!four byte integer
integer(kind=4) :: longval
!eight byte integer
integer(kind=8) :: verylongval
!sixteen byte integer
integer(kind=16) :: veryverylongval
!default integer
integer :: defval
print *, huge(shortval)
print *, huge(longval)
print *, huge(verylongval)
print *, huge(veryverylongval)
print *, huge(defval)
end program testingInt
When you compile and execute the above program, it produces the following result:
32767
2147483647
9223372036854775807
170141183460469231731687303715884105727
2147483647
Real Type
It stores the floating point numbers, such as 2.0, 3.1415, -100.876, etc.
The following example shows the use of real data type:
program division
implicit none
! Define real variables
real :: p, q, realRes
! Define integer variables
integer :: i, j, intRes
! Assigning values
p = 2.0
q = 3.0
i=2
j=3
! floating point division
realRes = p/q
intRes = i/j
print *, realRes
print *, intRes
end program division
When you compile and execute the above program it produces the following result:
0.666666687
Complex Type
This is used for storing complex numbers. A complex number has two parts, the real part and
the imaginary part. Two consecutive numeric storage units store these two parts.
For example, the complex number (3.0, -5.0) is equal to 3.0 – 5.0i
Logical Type
There are only two logical values: .true. and .false.
Character Type
The character type stores characters and strings. The length of the string can be specified by
len specifier. If no length is specified, it is 1.
For example,
character (len=40) :: name
name = “Zara Ali”
The expression, name(1:4) would give the substring “Zara”.
Implicit Typing
Older versions of FORTRAN allowed a feature called implicit typing, i.e., you do not have to
declare the variables before use. If a variable is not declared, then the first letter of its name
will determine its type.
Variable names starting with i, j, k, l, m, or n, are considered to be for integer variable and
others are real variables. However, you must declare all the variables as it is good programming
practice. For that you start your program with the statement:
implicit none
This statement turns off implicit typing.
FORTRAN ─ VARIABLES
A variable is nothing but a name given to a storage area that our programs can manipulate.
Each variable should have a specific type, which determines the size and layout of the variable's
memory; the range of values that can be stored within that memory; and the set of operations
that can be applied to the variable.
The name of a variable can be composed of letters, digits, and the underscore character.
A name in FORTRAN must follow the following rules:
• It cannot be longer than 31 characters.
• It must be composed of alphanumeric characters (all the letters of the alphabet, and the
digits 0 to 9) and underscores (_).
• First character of a name must be a letter.
• Names are case-insensitive.
Variable Declaration
Variables are declared at the beginning of a program (or subprogram) in a type declaration
statement.
Syntax for variable declaration is as follows:
type-specifier :: variable_name
The following example demonstrates variable declaration, assignment and display on screen:
program variableTesting
implicit none
! declaring variables
integer :: total
real :: average
complex :: cx
logical :: done
character(len=80) :: message ! a string of 80 characters
!assigning values
total = 20000
average = 1666.67
done = .true.
message = "A big Hello from Tutorials Point"
cx = (3.0, 5.0) ! cx = 3.0 + 5.0i
Print *, total
Print *, average
Print *, cx
Print *, done
Print *, message
end program variableTesting
When the above code is compiled and executed, it produces the following result:
20000
1666.67004
(3.00000000, 5.00000000 )
T
A big Hello from Tutorials Point
FORTRAN ─ CONSTANTS
The constants refer to the fixed values that the program cannot alter during its execution. These
fixed values are also called literals.
Constants can be of any of the basic data types like an integer constant, a floating constant, a
character constant, a complex constant, or a string literal. There are only two logical constants
: .true. and .false.
The constants are treated just like regular variables, except that their values cannot be modified
after their definition.
There are two types of constants:
• Literal constants
• Named constants
A literal constant have a value, but no name.
A named constant has a value as well as a name.
Named constants should be declared at the beginning of a program or procedure, just like a
variable type declaration, indicating its name and type. Named constants are declared with the
parameter attribute. For example,
real, parameter :: pi = 3.1415927
Example
The following program calculates the displacement due to vertical motion under gravity.
program gravitationalDisp
! this program calculates vertical motion under gravity
implicit none
! gravitational acceleration
real, parameter :: g = 9.81
! variable declaration
real :: s ! displacement
real :: t ! time
real :: u ! initial speed
! assigning values
t = 5.0
u = 50
! displacement
s = u * t - g * (t**2) / 2
! output
print *, "Time = ", t
print *, 'Displacement = ',s
end program gravitationalDisp
When the above code is compiled and executed, it produces the following result:
Time = 5.00000000
Displacement = 127.374992
FORTRAN ─ OPERATORS
An operator is a symbol that tells the compiler to perform specific mathematical or logical
manipulations. FORTRAN provides the following types of operators:
• Arithmetic Operators
• Relational Operators
• Logical Operators
Let us look at all these types of operators one by one.
Arithmetic Operators
Following table shows all the arithmetic operators supported by FORTRAN. Assume variable
A holds 5 and variable B holds 3 then:
Example
Try the following example to understand all the arithmetic operators available in Fortran:
program arithmeticOp
! this program performs arithmetic calculation
implicit none
! variable declaration
integer :: a, b, c
! assigning values
a=5
b=3
! Exponentiation
c = a ** b
! output
print *, "c = ", c
! Multiplication
c=a*b
! output
print *, "c = ", c
! Division
c=a/b
! output
print *, "c = ", c
! Addition
c=a+b
! output
print *, "c = ", c
! Subtraction
c=a-b
! output
print *, "c = ", c
end program arithmeticOp
When you compile and execute the above program, it produces the following result:
c = 125
c = 15
c=1
c=8
c=2
Relational Operators
Following table shows all the relational operators supported by FORTRAN. Assume variable
A holds 10 and variable B holds 20, then:
Example
Try the following example to understand all the logical operators available in Fortran:
program logicalOp
! this program checks logical operators
implicit none
! variable declaration
logical :: a, b
! assigning values
a = .true.
b = .false.
if (a .and. b) then
print *, "Line 1 - Condition is true"
else
print *, "Line 1 - Condition is false"
end if
if (a .or. b) then
print *, "Line 2 - Condition is true"
else
print *, "Line 2 - Condition is false"
end if
! changing values
a = .false.
b = .true.
if (.not.(a .and. b)) then
print *, "Line 3 - Condition is true"
else
print *, "Line 3 - Condition is false"
end if
if (b .neqv. a) then
print *, "Line 4 - Condition is true"
else
print *, "Line 4 - Condition is false"
end if
if (b .eqv. a) then
print *, "Line 5 - Condition is true"
else
print *, "Line 5 - Condition is false"
end if
end program logicalOp
When you compile and execute the above program it produces the following result:
Line 1 - Condition is false
Line 2 - Condition is true
Line 3 - Condition is true
Line 4 - Condition is true
Line 5 - Condition is false
Logical Operators
Logical operators in FORTRAN work only on logical values .true. and .false.
The following table shows all the logical operators supported by FORTRAN. Assume variable
A holds .true. and variable B holds .false. , then:
Example
Try the following example to understand all the logical operators available in Fortran:
program logicalOp
! this program checks logical operators
implicit none
! variable declaration
logical :: a, b
! assigning values
a = .true.
b = .false.
if (a .and. b) then
print *, "Line 1 - Condition is true"
else
print *, "Line 1 - Condition is false"
end if
if (a .or. b) then
print *, "Line 2 - Condition is true"
else
print *, "Line 2 - Condition is false"
end if
! changing values
a = .false.
b = .true.
if (.not.(a .and. b)) then
print *, "Line 3 - Condition is true"
else
print *, "Line 3 - Condition is false"
end if
if (b .neqv. a) then
print *, "Line 4 - Condition is true"
else
print *, "Line 4 - Condition is false"
end if
if (b .eqv. a) then
print *, "Line 5 - Condition is true"
else
print *, "Line 5 - Condition is false"
end if
end program logicalOp
When you compile and execute the above program it produces the following result:
Line 1 - Condition is false
Line 2 - Condition is true
Line 3 - Condition is true
Line 4 - Condition is true
Line 5 - Condition is false
If the logical expression evaluates to true, then the block of code inside the if…then statement
will be executed. If logical expression evaluates to false, then the first set of code after the end
if statement will be executed.
Example 1
program ifProg
implicit none
! local variable declaration
integer :: a = 10
! check the logical condition using if statement
if (a < 20 ) then
Flow Diagram
Example 2
program ifElseProg
implicit none
! local variable declaration
integer :: a = 100
! check the logical condition using if statement
if (a < 20 ) then
Syntax
The syntax for the select case construct is as follows:
[name:] select case (expression)
case (selector1)
! some statements
... case (selector2)
! other statements
...
case default
! more statements
...
end select [name]
Example
program selectCaseProg
implicit none
! local variable declaration
character :: grade = 'B'
select case (grade)
case ('A')
print*, "Excellent!"
case ('B')
case ('C')
print*, "Well done"
case ('D')
print*, "You passed"
case ('F')
print*, "Better try again"
case default
print*, "Invalid grade"
end select
print*, "Your grade is ", grade
end program selectCaseProg
Example
This program calculates the factorials of numbers 1 to 10:
program factorial
implicit none
! define variables
integer :: nfact = 1
integer :: n
! compute factorials
do n = 1, 10
nfact = nfact * n
! print values
print*, n, " ", nfact
end do
end program factorial
do while loop:
Example
program factorial
implicit none
! define variables
integer :: nfact = 1
integer :: n = 1
! compute factorials
do while (n <= 10)
nfact = nfact * n
n=n+1
print*, n, " ", nfact
end do
end program factorial