0% found this document useful (0 votes)
238 views

CFP Notes

Computer programs are sequences of instructions that perform tasks on a computer. They are written using programming languages and can be used for a wide range of applications. The three key components of a computer system are hardware, software, and computer programs. Hardware includes input, processing, output, and memory devices. Software includes operating systems, utilities, and application programs. Computer programmers write computer programs to solve problems by listing the steps as algorithms.

Uploaded by

Pacumio Clarette
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
238 views

CFP Notes

Computer programs are sequences of instructions that perform tasks on a computer. They are written using programming languages and can be used for a wide range of applications. The three key components of a computer system are hardware, software, and computer programs. Hardware includes input, processing, output, and memory devices. Software includes operating systems, utilities, and application programs. Computer programmers write computer programs to solve problems by listing the steps as algorithms.

Uploaded by

Pacumio Clarette
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Fundamentals and Programming

Lesson 1 without creating any error. If millions of


PROGRAMMING CONCEPTS calculations are to be performed, a computer
will perform every calculation with the same
UNIT 1: MAJOR COMPONENTS OF COMP. SYST. accuracy. Due to this capability, it overpowers
Compute – means to calculate. Man explored with human being in routine type of work.
the idea to develop a machine which can perform Versatility
this type of arithmetic calculation faster and with It means the capacity to perform completely
full accuracy. This gave birth to a device or machine different type of work.
called ‘computer’. Power of Remembering
BASIC CONCEPTS Computer has the power of storing any amount
of information or data. Any information can be
WHAT IS A COMPUTER? stored and recalled as long as you require it, for
Computer is an electronic device. It can do any numbers of years. It depends entirely upon
arithmetic calculations faster. For a common man you how much data you want to store in a
computer is simply a calculator, which works computer and when to lose or retrieve these
automatic and quite fast. For a person who knows data.
much about it, computer is a machine capable of No IQ
solving problems and manipulating data. It accepts Computer is a dumb machine and it cannot do
data, processes the data by doing some any work without instruction from the user. It
mathematical and logical operations and gives us performs the instructions at tremendous speed
the desired output. and with accuracy. It is you to decide what you
want to do and in what sequence. So, a
Computer is a device that transforms data. Data computer cannot take its own decision as you
can be anything like marks obtained by you in can.
various subjects. It can also be name, age, sex, No Feeling
weight, height, etc. of all the students in your class It does not have feelings or emotion, taste,
or income, savings, investments, etc., of a country. knowledge and experience. Thus, it does not get
 Computer can be defined in terms of its tired even after long hours of work. It does not
functions. accept data distinguish between users.
 store data, Storage Capability
 process data as desired The computer has an in-built memory where it
 retrieve the stored data as and when can store a large amount of data. You can also
required print the result in desired format. store data in secondary storage devices such as
floppies, which can be kept outside your
CHARACTERISTICS OF COMPUTER computer and can be carried to other
Speed computers.
Computer can work very fast. It takes only few
seconds for calculations that we take hours to INTRODUCTION TO COMPUTER PROGRAM
complete. A computer program is a sequence of instructions
Computer can perform millions (1,000,000) of written using a Computer Programming Language
instructions and even more per second. to perform a specified task by the computer.
Therefore, we determine the speed of computer
in terms of microsecond (10-6 part of a second) The two important terms that we have used in the
or nano-second (10-9 part of a second). above definition are:
Accuracy o Sequence of instructions
The computer should have accuracy or o Computer Programming Language
correctness in computing.
The degree of accuracy of computer is very high A computer program is also called a computer
and every calculation is performed with the software, which can range from two lines to
same accuracy. The accuracy level is determined millions of lines of instructions.
on the basis of design of computer. The errors in Computer program instructions are also called
computer are due to human and inaccurate program source code and computer programming
data. is also called program coding.
Diligence A computer without a computer program is just a
A computer is free from tiredness, lack of dump box; it is programs that make computers
concentration, fatigue, etc. It can work for hours active.

1|P a g e
INTRODUCTION TO COMPUTER PROGRAMMING 3. Triple ware
Computer Programming - the act of writing 4. Procedure
computer programs.
There are hundreds of programming languages, ALGORITHM
which can be used to write computer programs Algorithm is a step-by-step procedure to resolve
and following are a few of them: any problem. An algorithm is an effective method
▪ Java expressed as a finite set of well-defined
▪ C instructions.
▪ C++
▪ Python A computer programmer lists down all the steps
▪ PHP required to resolve a problem before writing the
▪ Perl actual code. Following is a simple example of an
▪ Ruby algorithm to find out the largest number from a
USES OF COMPUTER PROGRAMS given list of numbers:
Computer programs are being used in almost 1. Get a list of numbers L1, L2, L3....LN
every field, household, agriculture, medical, 2. Assume L1 is the largest, Largest = L1
entertainment, defense, communication, etc. 3. Take next number Li from the list and do the
following
Listed below are a few applications of computer 4. If Largest is less than Li
Programs: 5. Largest = Li
• MS Word, MS Excel, Adobe Photoshop, Internet 6. If Li is last number from the list, then
Explorer, Chrome, etc., are examples of computer 7. Print value stored in Largest and come out
programs. 8. Else repeat same process starting from step 3
• Computer programs are being used to develop
graphics and special effects in movie making. COMPUTER PROGRAMMING - BASICS
• Computer programs are being used to perform English Language, which is a well-known Human
Ultrasounds, X-Rays, and other medical Interface Language. English has a predefined
examinations. grammar, which needs to be followed to write
• Computer programs are being used in our mobile English statements in a correct way. Likewise, most
phones for SMS, Chat, and voice communication. of the Human Interface Languages (Hindi, English,
Spanish, French, etc.) are made of several
COMPUTER PROGRAMMER elements like verbs, nouns, adjectives, adverbs,
Computer Programmer - someone who can write propositions, and conjunctions, etc.
computer programs or in other words, someone
who can do computer programming. Computer Programming Languages are also made
of several elements.
Based on computer programming language These basic elements include:
expertise, we can name a computer programmer • Programming Environment
as follows: • Basic Syntax
▪ C Programmer • Data Types
▪ C++ Programmer • Variables
▪ Java Programmer • Keywords
▪ Python Programmer • Basic Operators
▪ PHP Programmer • Decision Making
▪ Perl Programmer • Loops
▪ Ruby Programmer • Numbers
• Characters
Four Elements of Computer System • Arrays
1. Hardware – It consists of Input Devices, • Strings
Processing Devices, Output Devices and • Functions
Memory Devices. • File I/O
2. Software – It consists of Application Software,
System Software and Programming Software. COMPUTER PROGRAMMING - ENVIRONMENT
Environment Setup is not an element of any
Types of System Software – It consists of Programming Language, it is the first step to be
Operating System, Utility Software and followed before setting on to write a program.
Communication Software.
Environment Setup, it simply implies a base on top So, if you are going to write your program in any
of which we can do our programming. Thus, we such language, which needs compilation like C,
need to have the required software setup, i.e., C++, Java and Pascal, etc., then you will need to
installation on our PC which will be used to write install their compilers before you start
computer programs, compile, and execute them. programming.
For example, if you need to browse Internet, then
you need the following setup on your machine − Interpreter
 A working Internet connection to connect Compilers are required in case you are going to
to the Internet write your program in a programming language
 A Web browser such as Internet Explorer, that needs to be compiled into binary format
Chrome, Safari, etc. before its execution.
There are other programming languages such as
Similarly, you will need the following setup to start Python, PHP, and Perl, which do not need any
with programming using any programming compilation into binary format, rather an
language. interpreter can be used to read such programs line
 A text editor to create computer programs. by line and execute them directly without any
 A compiler to compile the programs into further conversion.
binary format.
 An interpreter to execute the programs
directly.

Text Editor
A text editor is a software that is used to write
computer programs.
Your Windows machine must have a Notepad,
which can be used to type programs. You can
launch it by following these steps:
Start Icon → All Programs → Accessories →
Notepad → Mouse Click on Notepad

Compiler
You write your computer program using your Online Compilation
favorite programming language and save it in a If you are not able to set up any editor, compiler,
text file called the program file. or interpreter on your machine, then
Actually, the computer cannot understand your tutorialspoint.com provides a facility to compile
program directly given in the text format, so we and run almost all the programs online with an
need to convert this program in a binary format, ease of a single click.
which can be understood by the computer.
The conversion from text program to binary file is UNIT 2: FLOWCHARTING
done by another software called Compiler and this Flowchart is a means of visually presenting the
process of conversion from text formatted flow of data through an information processing
program to binary format file is called program system, the operations performed within the
compilation. system and the sequence in which they are
performed.
The following flow diagram gives an illustration of Program flowchart - describes what operations
the process: (and in what sequence) are required to solve a
given problem. The program flowchart can be
likened to the blueprint of a building.

A programmer prefers to draw a flowchart prior to


writing a computer program. As in the case of the
drawing of a blueprint, the flowchart is drawn
according to defined rules and using standard
flowchart symbols prescribed by the American
National Standard Institute, Inc.
MEANING OF FLOWCHART
A flowchart is a diagrammatic representation that e) Only one flow line should enter a decision
illustrates the sequence of operations to be symbol, but two or three flow lines, one for
performed to get the solution of a problem. each possible answer, should leave the
Flowcharts are generally drawn in the early stages decision symbol.
of formulating computer solutions. Flowcharts
facilitate communication between programmers
and business people. These flowcharts play a vital
role in the programming of a problem and are quite
helpful in understanding the logic of complicated
and lengthy problems. f) Only one flow line is used in conjunction with
terminal symbol.
GUIDELINES FOR DRAWING A FLOWCHART
Flowcharts are usually drawn using some standard
symbols; however, some special symbols can also
be developed when required.
Some standard symbols, which are frequently g) Write within standard symbols briefly. As
required for flowcharting many computer necessary, you can use the annotation symbol
programs are shown in Figure below: to describe data or computational steps more
clearly.

h) If the flowchart becomes complex, it is better


to use connector symbols to reduce the
number of flow lines. Avoid the intersection of
flow lines if you want to make it more effective
and better way of communication.
i) Ensure that the flowchart has a logical start
and finish.
j) It is useful to test the validity of the flowchart
by passing through it with a simple test data.

ADVANTAGES OF USING FLOWCHARTS


1. Communication: Flowcharts are better way of
communicating the logic of a system to
concerned.
2. Effective analysis: With the help of flowchart,
problem is analyzed in more effective way.
Figure Flowchart Symbols 3. Proper documentation: Program flowcharts
serve as a good program documentation,
The following are some guidelines in which is needed for various purposes.
flowcharting: 4. Efficient Coding: The flowcharts act as a guide
a) In drawing a proper flowchart, all necessary or blueprint during the systems analysis and
requirements should be listed out in logical program development phase.
order. 5. Proper Debugging: The flowchart helps in
b) The flowchart should be clear, neat and easy to debugging process.
follow. There should not be any room for 6. Efficient Program Maintenance: The
ambiguity in understanding the flowchart. maintenance of operating program becomes
c) The usual direction of the flow of a procedure easy with the help of flowchart. It helps the
or system is from left to right or top to bottom. programmer to put efforts more efficiently on
d) Only one flow line should come out from a that part
process symbol.
LIMITATIONS OF USING FLOWCHARTS
1. Complex logic: Sometimes, the program logic
is quite complicated. In that case, flowchart
becomes complex and clumsy.
2. Alterations and Modifications: If alterations Example 4: A company’s salesmen are selling
are required the flowchart may require re- toothpaste and tooth power. The company having
drawing completely. 50 salesmen gives 10% commission on the sale of
3. Reproduction: As the flowchart symbols toothpaste and 20% commission on tooth powder.
cannot be typed, reproduction of flowchart Draw a flowchart to compute and print the total
becomes a problem. sale and the total commission for each salesman.
4. The essentials of what is done can easily be lost
in the technical details of how it is done. Note:
S = Salesman number
EXAMPLES ON FLOWCHARTING P1 = Amount of sales of paste
Example 1: Draw a flowchart to find the sum of first P2 = Amount of sales of powder
50 natural numbers. K = Counter for the number of salesman

Example 2: Draw a flowchart to find the largest of


three numbers A,B, and C.

Example 5: Modify the flowchart in Example 4 to


print the following heading.
Salesman No Total Sale Total commission
Under these heading, write the values of these
variables for the 50 salesmen. At the end, the totals
of the entire sale and the entire commission should
Example 3 also be printed out.
Draw a flowchart for computing factorial N (N!) Note:
Where N! = 1 × 2 × 3 × ...... N . TS = Total sales
TC = Total commission
Lesson 2 HISTORY OF BASIC
BASIC PROGRAM STRUCTURE Conceived by John Kemeny and Thomas Kurtz,
BASIC was born at Dartmouth College, USA in
UNIT 1: ELEMENT OF BASIC STRUCTURE 1964.
COBOL, in fact, was already established as the
BASIC - programming language. It is the most major data processing language.
popular conversational programming language. FORTRAN on the other hand, became the principal
This language is quite simple to understand and programming language for scientific applications.
has been adopted by most of the microcomputers. BASIC gained immediate popularity. It became a
It is suitable for both mathematical and business widely used language for small commercial and
problems. It has been specially designed for use in scientific applications. BASIC had the same impact
`time-sharing' environment but can also be used as on the world of programming languages as the PC
a standard language in a `batch-processing' had on the larger computer systems. BASIC's
environment. popularity and acceptance by the user community
compelled all the major computer manufacturers
BASIC AS A PROGRAMMING LANGUAGE to come out with their individual version of BASIC.
Basic is quite simple language and easy to Even your MS-DOS operating system comes with a
understand. It is becoming more popular as an BASIC interpreter called BASICA. (MS-DOS 3.2
interactive language. Now we shall discuss various onwards, a more enhanced BASIC version, i.e.,
features of this language. GWBASIC forms the part of the operating system.)
American National Standards Institute (ANSI) in
Why BASIC? 1978 came out with a standardized version of
BASIC language. Most of the versions of the
B – Beginners currently available BASIC include the features of
It is meant for those who are about to start the ANSI standard.
learning programming. To qualify as a beginner's
language, it has to be simple, easy and readily STRUCTURE OF BASIC
available. BASIC has all the qualities. Although, it is The following small program prints the words
the beginner's language, its use by no means is WELCOME TO NATIONAL OPEN SCHOOL on the
restricted to basic computer education or screen:
elementary applications. 10 REM: This is my first program
20 PRINT "WELCOME TO NATIONAL OPEN
A – All-purpose SCHOOL"
It means BASIC can be used for a variety of 30 END
applications involving business, science,
mathematics and graphics. In fact, with new Keeping this program in view, let us go over the
enhancements, BASIC has some of the powers of rules on the structure of the language.
more advanced languages. The all purposeness is
also derived from the fact that very large segments These are:
of games and computer courseware are written in + Each statement of instruction must appear on
BASIC. a separate line.
+ A statement cannot exceed 80 characters i.e.
SIC – Symbolic Instruction Code one line on the terminal.
Means the instructions may not be exactly in + A statement must start with a statement
English but expressed in symbols. number. It is a positive integer.
+ No two statements can have the same
ADVANTAGES OF BASIC numbers.
BASIC is easy to learn and fun to practice. It may + The statement must be in the ascending order.
be called a `People's language'.
+ Each statement number is followed by a BASIC
It is available almost in every computer from
command or keyword.
micro to mainframe. Therefore, a program
developed in a micro can run on bigger system + You may use blank space to increase the
with minor modifications. readability of the program.
Program development cycle is quick, debugging
is simple The Microsoft BASIC i.e. BASICA or GWBASIC,
however, has provision for more than one
Modification of programs is quite easy.
statement in the same line and the use of
keywords also need not follow a line number. But CONSTANTS AND VARIABLES
if you strictly follow the rules of standard BASIC, A quantity in a computer program which does not
the program will still remain valid in Microsoft or change its value during the execution of the
any other BASIC. program is called a constant and the quantity
which may change its values during the execution
ELEMENTARY BASIC STATEMENTS of the program is called a variable.
REM, PRINT, and END - important BASIC
commands or keywords. BASIC allows the following constants:
• Numeric constant
REM • String constant
The REM is the short form for REMARKS. At the
time of execution, when the interpreter comes Numeric constant is one that is formed by a
across the first three alphabets, as the keyword, it sequence of digits 0,1,2, ---, 9 and may include a
knows that the content of the line following REM is decimal point. A numeric constant known as
not meant for execution and is to be ignored. number may be as integer or a real number. 383, +
57, 0, - 6.2 and 6.15E4 are valid numeric constants.
REM is used purely to enhance the documentation The number 6.15E4, in fact, represent 6.15 × 104.
aspect of a program. It is meant for the reader of The notation E is used to represent exponential
the program to understand the contents, purpose, form. The number after E is the exponent which
logic and other such aspects. can be positive or negative. However, its length
cannot exceed two digits.
There is no limit on the number of REM statements
in a program. In fact, it is recommended that you It is also important to keep in mind that:
get used to judicious and copious use of REM + BASIC does not distinguish between an
statements. integer and a fraction.
+ Commands are not allowed in a numeric
If we want to insert a blank line after the REM constant
statement of the program, we may write the
+ The limit on the number of digits that can be
program as:
used varies from computer to computer.
Normally, a numeric constant can have up to
10 REM : This is my first program
a maximum of eight digits.
20 PRINT
30 PRINT "WELCOME TO NATIONAL OPEN
A string constant consists of a sequence of
SCHOOL"
characters. It must be enclosed by a quotation
40 END
mark. This may contain blank space as a character
but it should not include the quotation mark. String
END
constants are used to represent non-numeric
The END statement was mandatory in the older
quantities such as names, addresses, etc.
BASIC version to indicate the end of a program. In
For example, "PANKAJ GOEL", "SUM = Rs 75",
other BASIC like Microsoft BASIC, it is not
"162" are a few valid string constants.
compulsory.
Whenever END is used, it must be the last line. Any
In BASIC, variables are also of two types. They are
statement after the END is irrelevant to the
• Numeric variable
interpreter.
• String variable
THE CHARACTER SET
Numeric variable can assume numeric value and is
BASIC has the character set consisting of the
represented by an alphabet or an alphabet
following elements:
followed by another alphabet or a digit.
(a) Alphabets: A, B, C, ----. Z
For example A, C, A2, ABC, A6 etc, represent
(b) Digits: 0,1,2, ----, 9 and
numeric variables.
(c) Special characters: + - * / ( ) . , $ ; : = > < " ^
String variable is represented by an alphabet
The symbol ^ (caret) is used to denote
followed by dollar ($) sign. It should be kept in
exponentiation operator, the symbol * (asterisk) is
mind that while constructing the string variable,
used to denote multiplication and the other
dollar ($) should be the last character.
symbols have their usual meanings. In addition
For example, A1$, PKG$, BOOK1$, etc., are valid
these, blank space denoted by the symbol b is also
string variables.
regarded as a character.
UNIT 2: OPERATORS EXPRESSIONS Expressions written to compare two quantities
using certain relational operators are known as
An operator in a programming language is a relational expressions.
symbol that tells the compiler or interpreter to These expressions take only one of the two values,
perform specific mathematical, relational or logical namely, TRUE or FALSE.
operation and produce final result.
LOGICAL OPERATORS
ARITHMETIC EXPRESSIONS Logical expressions are used in IF---THEN
A BASIC system can handle arithmetic expressions Statements to determine the course of action of a
involving the five arithmetic operators. running program.
Logical operators are used to connect two or more
SYMBOL OPERATORS relations and return a TRUE or FALSE value to be
+ Addition used in a decision.
- Subtraction The common logical operators are:
* Multiplication • AND - Conjunction
/ Division • OR - Disjunction
^ Exponentiation • NOT - Logical Negation
% Remainder • NAND
All exponentiation operations are performed first, • NOR
then multiplication/division and the • XOR
addition/subtraction operations are the last to be • XNOR
carried out.

In addition to this hierarchy of operations, the


following rules must be kept in mind in arithmetic
expression:
» Two operations must not appear together. For
example, C+-D, A/-C, etc are not permitted.
» String constants and string variables should
not be used in arithmetic expressions. For
example, P+P$ is wrong.
» When brackets are used, they must be used in
pairs, i.e., every left bracket must be matched
with a right bracket.
» Denominator of an expression should not be
zero.
» Within a given pair of parentheses, the natural
hierarchy of operations will apply. A B C
0 0 0
Let us take an example where we give BASIC 0 0 1
equivalents of a few algebraic expressions: 0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
0 0 0

A A A A A A A
RELATIONAL OR LOGICAL EXPRESSIONS A B AND OR NAND NOR XOR XNOR
B B B B B B
A relational expression is formed by using any of
the following relational operators: 0 0 0 0 1 1 1 0 1
1 0 0 1 0 1 0 1 0
0 1 0 1 1 1 0 1 0
1 1 1 1 0 0 0 0 1
LIBRARY FUNCTIONS IN BASIC
The word `library' stands for collection. In the
context of computer languages, a library is
essentially a collection of useful programs. These
programs are used by the programmers to simplify
their task of program development. These
programs are often referred as subroutines.

For example, suppose you want to calculate the


square root of a numeric variable A. In simple
mathematics, square root of A, i.e., can be written
as A1⁄2. Thus, in BASIC it can be written as:
10 LET B = A^0.5
The value of B will be the square root of A. Using a
library function the operation can be performed as:
10 LET B = SQR(A)

To find the logarithm of Χ by using LOG function


you write:
LET Y = LOG (X),
The variable Y will store the LOG value of X.

From this example, we may deduce the rules,


governing the use of a function.
a) Each function is assessed by the function
name (LOG, SQR, etc.) followed by the
function argument placed within the
parenthesis.
b) The function argument is the information you
supply to the function to act upon it. For
mathematical factions, it has to be a numeric
constant or variable.

Some examples of mathematical functions in


BASIC.

c) The function name is to be written exactly as


given. No deviation is permitted.
d) You cannot have a blank space between
function name (SIN, LOG etc.) and the
beginning of the opening parenthesis
enclosing the argument.

It should be noted that a library function program


would produce the result faster than a BASIC
program that has been written to perform the
same task.

You might also like