COM 301 Handout
Transcript of COM 301 Handout
-
7/31/2019 COM 301 Handout
1/28
1 | P a g e
INTRODUCTION
A language is a medium through which we communicate with each other. Whilecommunicating we use such a language that is understood by both. Sometimes we
take the help of interpreter to communicate when we both dont know languages ofeach other.
Communicating to a computer is not taking like the person to person. It meansgiving a set of instructions to a computer and the computer follows the instructionsgiven by us. We cannot give instructions to a computer in human language like
Nepali, English, etc. To interact with the computers, we need a computer language.An artificial language used for writing instructions or programs is known ascomputer language. A computer language is known as programming language. A
programming language provides a way of giving instructions to the computer. We
dont use programming language in our everyday conversions. We can use aprogramming language to instruct a computer when we need.
The set of commands that are used to give instruction and The manner in which these commands are put together.
Since a computer understands binary digits, we can use binary number to instructthe computer. The instructions written in the binary number system is known asmachine language. Machine language is directly understood by the computer. Inthe early time, Charles Babbage had used machine language to write instructionsfor his Differential and Analytical engines. However, writing programs in machinelanguage is very difficult. Therefore, many other artificial languages have beendeveloped for instructing computers. Expect machine language, a computer doesnot directly understand any other computer languages so the instructions written inother computer languages must be translate into machine language. This translatingtask is carried out by Translator i.e. Language Processor.
Computer program
A program is set of an instruction which tells the computer what to do. A program
directs the computer to perform a particular task and produce the desired result. Aperson who writes a program for computers is known as a programmer. Theprocess of writing set of instructions in a computer language is calledprogramming.
Types of computer languages
-
7/31/2019 COM 301 Handout
2/28
2 | P a g e
The computer languages are divided into two categories. They area. Low-level language
b. High-level Language
a. Low-level languageLow-level language is machine dependent language. The program written for onecomputer in low level language cannot be used in another computer. This makes itdifficult to learn and use, as the programmer must have the in-depth knowledge ofdifferent computers to write programs in a low level language.
There are two types of low level languages. They arei. Machine Level Language (MLL)ii. Assembly Language (AL)
i. Machine Level LanguageMachine level language is the first generating language. Machine level language isthe only language that a computer understands directly without any translator
program. Machine level language was used in the earliest machines and computers.Machine level language is difficult to write programs in a machine level language.
Nowadays nobody writes programs in machine Level Language.
Advantages of machine level language
No language processor is required. Programs written in machine level language run very fast.
Disadvantages of machine level language
Machine level language is machine oriented language i.e. machinedependent. The program written in one computer cannot be run in anothercomputer.
To write program using this language, a programmer has to know the details
of computer hardware of the computer. A programmer has to remember a lot of codes to write a program which may
cause error in the program. A program becomes lengthy and difficulty of debugging.
-
7/31/2019 COM 301 Handout
3/28
3 | P a g e
ii. Assembly Language
This is second generation language. Assembly language was developed by theprogrammers to overcome the drawbacks of the machine level language. Assemblylanguage uses letter, words and symbols instead of binary digits. These letter,
words and symbol are called mnemonics. Assembly language is little bit easierthan machine language. Since Assembly language is also machine dependentlanguage the programmers need to know many mnemonics for each computer. The
programs written in this language need to convert into machine language.
Advantages of assembly language
The programming in assembly language is easier than machine language. Debugging and modifying programs are easier than machine language.
Disadvantage of assembly language
Assembly language is also machine dependent. Programmers have to remember a lot of mnemonics codes for different types
of machine.
b. High level language
High level language is a simple languages that uses English and mathematicalsymbols for its program construction. High level language is considered as Third
Generation Language. High level languages are machine independent languages.Hence, programmers do not need to worry about the hardware used in thecomputer on which they are writing programs. The programs written in a highlevel language in one computer can be run in any other computer. The programswritten in HLL need to translate into machine language. This translation is done byeither Compiler or an Interpreter.BASIC, COBOL, FORTRAN, PASCAL, C, C++, JAVA etc., are some examplesof HLLs.
Advantages of high level language
High level language is machine independent and program oriented language. High level language is easy to learn and use. Writing the program in a HLL in easy. Debugging is easy in HLL.
-
7/31/2019 COM 301 Handout
4/28
4 | P a g e
ELEMENTS OF QBASIC
Every programming language consists of some basic elements which are requiredto make a program. The element required to construct a QBASIC program consistsof a set of characters, keywords, constants, variables, operators and expressions.
1. CHARACTER SET
A set of characters that are allowed to use in QBASIC is known as the QBASICCharacter Set. The QBASIC Character Set consists of alphabets (both small andcapital), numbers (0 to 9) and special characters. These special characters havetheir own meaning and function. The table below shows the special characters usedin QBASIC.
QBASIC keywords and variables are formed by using the characters defined in theQBASIC Character Set.
2. KEYWORD
Keywords are those words which have special meanings in QBASIC. Keywordsare formed by using characters of QBASIC Characters Set. Keywords are
-
7/31/2019 COM 301 Handout
5/28
5 | P a g e
statements, commands, functions (built in functions) and names of operators. Thekeywords are also called Reserved Words. Some reserved words are CLS, REM,INPUT, LET, PRINT, FOR, DO, SELECT, MID$, ASC, SQR, LEN, LEFT$,TIME$ and INT.
We will take a look at some of these keywords
THE INPUT STATEMENT
The INPUT statement allows you to read characters from the keyboard and storesthe information in a variable.
Here is what an INPUT statement looks like
INPUT "The Question you want to ask:"; answer
Or
INPUT "The Question you want to ask:", answer
Notice that when you use the "," instead of a ";" then this will stop a "?" sign fromappearing at the end of the input statement once the program is running.
You do not need to even include a message for the user:
INPUT name$
The above example will not prompt you for anything and wait for the user to entersomething. Once return is pressed it will store the information in the "name$"variable. If you try the above example notice how there is a "?" on the screen. Youcan clear this by doing the following:
INPUT , answer
This will display nothing on the screen and just wait for a input from the keyboard.Once the return button is pressed it will move onto the next statement (if there isone).
You must remember is that a string input requires a string variable a number inputrequires a variable that can store a number.
-
7/31/2019 COM 301 Handout
6/28
6 | P a g e
You know that a string will have a "$" on the end of the variable name, and a valuevariable will just have the standard name and nothing else.Example Uses of the INPUT:
Program Screen Output
CLSINPUT "Your Name:"; name$INPUT "Your Age:"; agePRINT "Hello ";name$;" Your Age is";age
Your Name:?RalphYour Age:?17Hello Ralph Your age is 17
THE PRINT STATEMENT
The PRINT statement allows you to print something on the screen. You must usequotation marks on both side's of the information you would like to display (unless
you are printing the value found in a variable). If you do not place these quotationsin the proper place when you are using the PRINT statement, your program willfail to run correctly (unless you are printing the value found in a variable).
Here is an example:PRINT "Hello there. How are you doing"PRINTPRINT "See ya later"
If you you wish to PRINT some information stored in the computer out to thescreen, you can print the contents of a variable to the screen.
SPACING (using the , and the ; )
If you you wish to PRINT more than one think at a time, you need to consider howyou want to space out the objects when they print on the screen. You can use thecomma (,) or the semi-colon(;) to space out the objects.
using the ,
The comma (,) is used much like a tab is used in word processing. Each use of a
comma tabs the screen position over a set number of characters.
using the ;
The semi-colon(;) is used to hold the cursor position at the current spot so that thenext object will be printed exactly right beside the last object that was printed onthe screen.
-
7/31/2019 COM 301 Handout
7/28
7 | P a g e
the Code the Output to the screen
PRINT "Hello" ; "There"PRINTPRINT "Hello" , "There"
HelloThere
Hello There
3. CONSTANTS
Constants are the data or the values in a program that cannot be changed during theprogram execution. The data may be a letter, words, numbers, or specialcharacters. A constant can be stored in a variable when it is required to use in morethan one statement or expression. In QBASIC, these data/constants are groupedinto two main categories. They are:
a. Sting Constantb. Numeric Constant
a. String Constant:
Sting Constant is a letter, words, numbers, combination of letters with numbers orspecial characters enclosed in double quotes. Mathematical operations cannot be
performed on String Constants. B, APPLE, SYMBOL NO:10205, !!!Welcome to QBASIC World !!!, etc. are some examples of Sting Constants.
b. Numeric Constant:
Numeric Constant refers to a number. A number with or without decimal point is anumeric constant. Thousand separators are not allowed to use in numeric constant.
Numeric data should not be enclosed in double quotes. Mathematical operationsand logical operations can be performed on the numeric constants. 101, 105.50,720, 45603, etc. are some examples of numeric constants.
Numeric Constants may be integer, long integer, single precision or doubleprecision.
1. Integer: Integer is whole number between -32768 to 32767.2. Long Integer: Long Integer is a large range of whole number.3. Single Precision: Single Precision is seven digit or less than seven digit
positive or negative number that contains decimal point. Single Precisioncan be in the exponential form using E or with a trailing exclamation point.
-
7/31/2019 COM 301 Handout
8/28
8 | P a g e
(!). 564, 78.65, 1.2 E-06 and 12345.678! are some examples of SinglePrecision Constants.
4. Double Precision: Double Precision is 17 digit or less than 17 digit positiveor negative numbers that contains decimal point. Double Precision can be in
the exponential form using D or with trailing hash sing (#). 9999.99D-12,2345.786# and 3456.78 are some examples of Double Precision Constants.
4. VARIABLE
A program is written to perform certain tasks. A program needs data to produceinformation. A program can use data only when data are stored in the computermemory (RAM). In a computer memory, there may be many data. So, you need totell the computer to use only those data which you want to use in a program. Thisis possible if you assign a name to the place where you have stored a data. InQBASIC, you can perform this task by using a variable. A variable is a place in the
computer memory which has a name and stores data temporarily. Simply, you cansay, a variable is an entity that stores data needed to be used in a program. You canalso say, it is an identifier whose value may or may not remain the same during
program execution. Each program defines different number of variables. A valueof a variable can be change during the execution of the program.
There are mainly two types of variables. They are:i. String Variableii. Numeric Variable
A string variable stores sting data. Its types declaration sign is dollar ($). Anumeric variable stores numeric data. A numeric variable can be Integer, LongInteger, Single Precision or Double Precision variables.
An Integer variable can store only an integer number. Its type declarationsign is percentage (%).
A Long integer variable can store a large range of whole number. Its typedeclaration sign is ampersand (&0).
A Single Precision variable can store a whole number as well as number
with decimal. Its type declaration sign is exclamation sign (!). You can alsouse it without declaration sign. It is the default numeric variable.
A Double Precision variable also stores a whole number as well as numberwith decimal point. Its type declaration sign is hash (#).
RULES FOR NAMING A VARIABLE
a. Variable names can have maximum of 40 characters.
-
7/31/2019 COM 301 Handout
9/28
9 | P a g e
b. Variable names can have alphabets, numbers and decimal point.c. A Variable name must begin with a letter.d. A Variable name cannot begin with fn or FN alphabets. For example, fnames$,fnumetc.
e. Variable names cannot be reserved words.f. Variable names may be ended with type declaration characters like $, %, &, !,and #.
Naam$, Address$, Bookname$, GameName$, etc., are examples of StingVaribales.Salary!, Age%, Mark, Number1, Number2, FirstNum, RollNumber, etc., areexamples of Numeric Variables.
5. OPERATOR
Operators are symbols that indicate the type of operation QBASIC has to performon the data or on the values of variables.
There are four types of operators in QBASIC. They are Arithmetic Operators,Relational Operators, Logical Operators and Sting Operator.
a. Arithmetic Operators
Arithmetic Operators are used to perform mathematical calculations like addition,subtraction, division, multiplication and exponential. The following table shows
arithmetic operators used in QBASIC.
Operation ------------ Operator ---------------- Example ------------------ Result
i. Addition ----------------- + ----------------------- 5+8 -------------------------- 13ii. Subtraction ----------- - ---------------------- 8-6 --------------------------- 2iii. Multiplication -------- * ---------------------- 5*4 --------------------------- 20
iv. Division ---------------- / ------------------------ 8/2 -------------------------- 4v. Integer Division -------- \ ----------------------- 9\2 --------------------------- 4vi. Exponential ----------- ^ ----------------------- 4^3 ------------------------- 64vii. Modular Division --- Mod --------------------- 7 mod 3 ------------------------ 1
b. Relational Operators
-
7/31/2019 COM 301 Handout
10/28
10 | P a g e
Relational Operators are use to perform comparisons on two values of same type.A comparison of sting data with numeric data cannot be done. The comparison ofsting data is done on the basis of ASCII value. The result of comparison is eithertrue (non zero) or false (zero).
The following table shows the relational operators used in QBASIC.Operator ------------- Relation ------------------------------- Example
i. = --------------------- Equal to --------------------------- A = B, A$ = B$ii. > -------------------- Greater than --------------------------- A > B, CAT>RATiii. < ------------------- Less than ------------------------------- A < B, "cat" < "cat"iv. > = ---------------- Greater than or equal to ---------------- A > = B, X$ > = Y$v. < = ----------------- Less than or equal to ------------------- A < = B, X$ < = Y$vi. < > ---------------- Not equal ------------------------------ A$ < > B$, X Y.
c. Logical OperatorsLogical Operators combine two or more relational expressions to evaluate a singlevalue as True (Non Zero) or False (Zero). The result of evaluation is used to makedecisions about the program flow. The commonly used logical operators inQBASIC are AND, OR and NOT.
i. AND Operator:
AND operator returns True when all the results returned from individualrelational expressions are True otherwise it returns False.
The AND Truth Table is given shown below.
Condition1 (P) ------------- Condition2 (Q) -------------- Result (P AND Q)
F ------------------------------- T ----------------------------------- FT ------------------------------- F ----------------------------------- FF ------------------------------- F ----------------------------------- FT ------------------------------- T ----------------------------------- T
Note: A T indicates a true value and a F indicates a false value.
ii. OR Operator:
OR Operator return True if any one of the relational expressions returns True. Ifall the relational expressions returns False then only the combined result returned
by OR operator will be False.
-
7/31/2019 COM 301 Handout
11/28
11 | P a g e
The OR Truth table is as given below.Condition 1 (A) ------------------ Condition2 (Q) --------------- Result (A or B)
F ------------------------------------------- T ---------------------------------- T
T ------------------------------------------- F ---------------------------------- TT ------------------------------------------- T ---------------------------------- TF -------------------------------------------- F ---------------------------------- F
iii. NOT Operator:
NOT Operator operates on one operand and returns True if the logical operationreturns False. The NOT truth table is as given below.
Condition1 (A) --------------------------- Result (NOT A)
F ----------------------------------------------- T
T ----------------------------------------------- F
d. String Operator
String Operator joins two or more than two sting data. The plus sign (+) is used asthe String operator. The act of combining two stings is called concatenation. Thefollowing table shows the use of Sting Operator.
String Data (A$) -------------------- Sting data (B$) ----------------- A$ + B$
Ram ---------------------------------- Thapa ------------------------ Ram Thapa
50 ------------------------------------- 45 ----------------------------- 5045
6. EXPRESSIONS
An expression is the combination of operators, constants and variables that isevaluated to get a result. The result of the expression is either string data, numericdata or logical value (true or false) and can be stored in a variable. For example,the following are expressions in QBASIC.
(A + B) > CA > = B + Cu* t + *a*t^2
An arithmetic expression may contain more than one operator. While evaluatingsuch expressions, a hierarchy is followed. The hierarchy in arithmetic operations islisted as given below:
-
7/31/2019 COM 301 Handout
12/28
12 | P a g e
a. Exponentiation (^)b. Negation (-)c. Multiplication and divisiond. Integer division
e. Modular divisionf. Addition and Subtraction
The hierarchy in relational operations are =, >, = respectively.The hierarchy in logical operations are NOT, AND and OR.
NOTE:
When parenthesis is used, it changes the order of hierarchy. The operatorsinside the parenthesis are evaluated first. So, you can say QBASIC
expression follows rule of PEDMAS where P, E, D, M, A and S stand forparenthesis, Exponentiation, Division, Multiplication, Addition, andSubtraction respectively.
Algebraic expression cannot be used directly in programming. It must beconverted into QBASIC expression.
Algebraic Expression --------------------------------- BASIC Expression
A = L B ------------------------------------------------- A = L * B
P = 2(L + B) ---------------------------------------------- P = 2*(L + B)I = (P T R)/100 --------------------------------------- I = (P * T * R)/100
V = 4/3 pi R^3 ------------------------------------------- V = 4/3 * PI * R^3
THE PROCESS OF PROGRAMMING
Programming is a process and made up of several activities. The program process
starts with the modeling of logic. This is also where we will focus much of our
instruction. It is often is the neglected piece of the programming processes but
critical for new programmers. Once the logic is complete programming starts. Acompleted program must finally be tested before put into production. This manual
was designed to provide instruction on programming for a variety of programming
languages (language independent). The process of programming is the same no
matter what programming language is used (i.e. Visual Basic.Net, C++, C# or
Java).
-
7/31/2019 COM 301 Handout
13/28
13 | P a g e
Key Concept: A program is the implementation of your program logic with
programming language statements. Program logic and programming come together
like a pilot and his airplane. Each by themselves offers little but together, they can
provide much more. In short, programming logic is your plan for solving a
problem and the program is the implementation of our program logic with
programming language statements.
Program Language Statements - Program language statements are English like
statements that when executed in the correct sequence can instruct the computer to
perform a series of tasks. There are many computer programming languages each
having differences and similarities. The differences allow some programming
languages to work with some computer applications better than others (i.e. the
COBOL computer language has long been a favorite of business programmers.
A First Look: Understanding Programming Process
We must start our understanding of programming by dispelling a few computer
myths. Many of us have grown up with a Hollywood view of computers. That
view has presented the computer as some sort of super brain. A device that we
need only ask questions of and it will return to us knowledge we dont possess. A
machine that can reason, learn or acquire intelligence on its own.
This could not be any farther from the truth. One of the difficulties in learning how
to implement programming logic is the constraints the computer places on us in
solving business problems. The human brain is far more complex and the brains
ability to reason and learn far exceeds that of a computer. Computers are only as
smart as the persons programming them and you must condition yourself into
providing an instruction (logic) for everything a computer program needs to do.
Planning or modeling program logic before we create programming statements is
one way for the programmer to condition the solution into one the computer canperform. Without a logic model it is easy for the new programmer to assume the
computer can perform more than it is able. We will learn more about logic
structures in later chapters but first we will give you a first look.
-
7/31/2019 COM 301 Handout
14/28
14 | P a g e
I often use the example of making a peanut butter sandwich to illustrate the
intelligence (or lack of) of the computer. Making a peanut butter sandwich is a task
that any three years old could handle. Lets see what we would have to tell the
computer in the form of logic instructions to make a peanut butter sandwich. I will
accomplish this by documenting the logic necessary with a programming modeling
language called pseudo code to build the necessary instructions.
Pseudo Code: Pseudo code is a nonstandard English-like programming language
used by programmers to model logic and instructions. Pseudo code is called a
programming language even through it can not be excluded by a computer. It is
designed for planning purposes only. By nonstandard, if you open five books on
programming, all would have pseudo code examples but all of those exampleswould look somewhat different. Most computer languages have required standards
that must be followed when creating programs. Pseudo code provides us with a
way to concentrate on just logic structures without be constrained by the syntax
rules of a particular programming language.
In Practice: Pseudo code for Creating Programming Logic - Pseudo code has long
been used as a mechanism for modeling logic before the logic is implemented as
source code statements in a program. We will formally introduce pseudo code later
in the wiki. We use pseudo code because it is an excellent way to just concentrate
on programming logic without being constrained by the rules of a specific
programming language. The beauty of pseudo code is that since it is a list of
English instructions, you can easily document the process steps and validate the
steps with others. Even persons with no formal understanding of programming
logic or programming, can participate in the creation of pseudo code. Pseudo code
is not like a formal programming language and if you can read you can follow
logic documented in pseudo code.
One of the difficulties in teaching logic with pseudo code has been its nonstandard
nature and the fact that since it is not a true programming language, the logic
statements can not be executed on a computer. By not being able to execute the
logic, it is not possible to validate the program logic to make sure that it was
constructed correctly and arrives at the correct solution.
-
7/31/2019 COM 301 Handout
15/28
15 | P a g e
Logic Tip: Most students will initially have a problem with program logic because
they are not familiar to the very unnatural process of breaking down instructions to
the computer at that low a level. We will be the chance to learn more about logic in
later chapters.
Related Subject: Blame it on the computer The computer did it!: Have any of
you ever experienced this? An organization you do business with has made a
mistake concerning your account (i.e. they forgot to credit a returned item to your
monthly statement). Their response to the error is, the computer did it. It is not
our fault!
I can fondly remember one day receiving a rather threatening notice from a local
department store because my payment had mistakenly been processed $2.00 short
of the monthly invoice amount. Needless to say, I wasnt happy when theythreatened to turn me into a credit agency for two dollars. I called the customer
service department to communicate my dissatisfaction. The person on the other
end of the phone, although apologetic, could only say that my problem was the
result of the computer causing an error. No person there was certainly at fault.
You know these computers, they are always making errors. The computer was
cause of my problems. The computer was the one I should direct my displeasure
to. I asked if I could talk to the computer. The phone went silent.
Program Logic and an Application Computer Program:
In this wiki, you will see repeated references to program logic and application
computer programs. We are focusing on program logic in this manual but it is
important that we also refer to programs since the two subjects are so closely tied
to one another. We will do a more formal introduction on programming in the next
section but look at the relationship between program logic and a computer program
in the following diagram (see Figure 1). Note how programming languages also
use English like statements to represent instructions to the computer. Computers do
not speak English (although I talk to mine all of the time).
-
7/31/2019 COM 301 Handout
16/28
16 | P a g e
Figure 2: The graphic represents the relationship between program logic and a
computer program. Pseudo code statements from Box A are converted by the
program to program language statements (PYTHON) shown in Box B
An Example: Program Logic to Add to Numbers Together
We will use four approaches to model program logic. The simplest approach is
pseudo code. As we get deeper into the eBookand begin our learning on structured
programming, we will introduce flow charting. Flowcharting is the most graphical
of the three approaches we will cover and we will introduce flow charting in a later
chapter.
FLOWCHART
A flowchart is a type ofdiagram that represents an algorithm orprocess, showingthe steps as boxes of various kinds, and their order by connecting these with
arrows. This diagrammatic representation can give a step-by-step solution to a
given problem. Process operations are represented in these boxes, and arrows
connecting them represent flow of control. Data flows are not typically represented
in a flowchart, in contrast with data flow diagrams; rather, they are implied by the
sequencing of operations. Flowcharts are used in analyzing, designing,
documenting or managing a process or program in various fields
Flowcharts are used in designing and documenting complex processes orprograms. Like other types of diagram, they help visualize what is going on andthereby help the viewer to understand a process, and perhaps also find flaws,
bottlenecks, and other less-obvious features within it. There are many differenttypes of flowcharts, and each type has its own repertoire of boxes and notationalconventions. The two most common types of boxes in a flowchart are:
http://en.wikipedia.org/wiki/Diagramhttp://en.wikipedia.org/wiki/Algorithmhttp://en.wikipedia.org/wiki/Process_(science)http://en.wikipedia.org/wiki/Knowledge_representation_and_reasoninghttp://en.wikipedia.org/wiki/Problem_solvinghttp://en.wikipedia.org/wiki/Datahttp://en.wikipedia.org/wiki/Data_flow_diagramhttp://en.wikipedia.org/wiki/Diagramhttp://en.wikipedia.org/wiki/Algorithmhttp://en.wikipedia.org/wiki/Process_(science)http://en.wikipedia.org/wiki/Knowledge_representation_and_reasoninghttp://en.wikipedia.org/wiki/Problem_solvinghttp://en.wikipedia.org/wiki/Datahttp://en.wikipedia.org/wiki/Data_flow_diagram -
7/31/2019 COM 301 Handout
17/28
17 | P a g e
a processing step, usually called activity, and denoted as a rectangular box a decision, usually denoted as a diamond.
A flowchart is described as "cross-functional" when the page is divided into
different swimlanes describing the control of different organizational units. Asymbol appearing in a particular "lane" is within the control of that organizationalunit. This technique allows the author to locate the responsibility for performing anaction or making a decision correctly, showing the responsibility of eachorganizational unit for different parts of a single process.
Flowcharts depict certain aspects of processes and they are usually complementedby other types of diagram. For instance, Kaoru Ishikawa defined the flowchart asone of the seven basic tools of quality control, next to the histogram, Pareto chart,check sheet, control chart, cause-and-effect diagram, and the scatter diagram.
Similarly, in UML, a standard concept-modeling notation used in softwaredevelopment, the activity diagram, which is a type of flowchart, is just one ofmany different diagram types.
Nassi-Shneiderman diagrams are an alternative notation for process flow.
Common alternate names include: flowchart, process flow chart, functional flowchart, process map, process chart, functional process chart, business process model,
process model, process flow diagram, work flow diagram, business flow diagram.
The notes make extensive use of flow-chart symbols to describe, explain the flow,or sequence of program instructions. Standard symbols are used, so other peoplecan read your flow chart diagram, and you can read other peoples diagrams.Program instructions are described through the flowchart with instructions groupedinto different symbols, and the flow or sequence of instructions being useddirected through the use of connecting arrows.
http://en.wikipedia.org/wiki/Swimlanehttp://en.wikipedia.org/wiki/Kaoru_Ishikawahttp://en.wikipedia.org/wiki/Histogramhttp://en.wikipedia.org/wiki/Pareto_charthttp://en.wikipedia.org/wiki/Check_sheethttp://en.wikipedia.org/wiki/Control_charthttp://en.wikipedia.org/wiki/Ishikawa_diagramhttp://en.wikipedia.org/wiki/Scatter_diagramhttp://en.wikipedia.org/wiki/Unified_Modeling_Languagehttp://en.wikipedia.org/wiki/Activity_diagramhttp://en.wikipedia.org/wiki/Nassi-Shneiderman_diagramhttp://en.wikipedia.org/wiki/Swimlanehttp://en.wikipedia.org/wiki/Kaoru_Ishikawahttp://en.wikipedia.org/wiki/Histogramhttp://en.wikipedia.org/wiki/Pareto_charthttp://en.wikipedia.org/wiki/Check_sheethttp://en.wikipedia.org/wiki/Control_charthttp://en.wikipedia.org/wiki/Ishikawa_diagramhttp://en.wikipedia.org/wiki/Scatter_diagramhttp://en.wikipedia.org/wiki/Unified_Modeling_Languagehttp://en.wikipedia.org/wiki/Activity_diagramhttp://en.wikipedia.org/wiki/Nassi-Shneiderman_diagram -
7/31/2019 COM 301 Handout
18/28
18 | P a g e
As an example, the following flowchart for computing the factorial of N writtenN! and equal to 1 2 3 ... N.
Terminator. The terminator symbol marks the beginning, or ending of a sequenceof instructions. This is often used when marking the beginning and ending of theprogram.
Process. Marks instructions that are processed such as calculations and
declarations. For our purpose, if you cannot figure out which symbol to use, then usethis symbol as a placeholder until you can be more certain which is the better flow-chart symbol to use. We will use it for when we make mathematical calculations anddeclaring variables.
Input/Output. Marks instructions to perform data input (bring data into theprogram from outside) or output (send data out from the program). We will use thiswhen we ask the user for keyboard input and when we display information to thescreen or printer.
Decision. Marks instructions where the program makes a decision. Decisions arethe only symbols allowed to have more than one flow out of the symbol. Decisionsshould have an outside flow ofyes and no. We will use this symbol when comparingdifferent data items.
Predefined Process. Marks a group of instructions. A predefined process can beused to specify that the specifics of these instructions are already known, or areshown in some other place. We will use this symbol to simplify larger programs,where we already know what is to be done and do not want the flow-diagram to takeup too much space.
Connector. Joins different parts of the chart together. This is used when the chartgets big and the number of lines may become confusing. The connector circle islabelled with the label that will identify the ingoing connector.
Page Connector. Joins different pages of a chart. Use the page connector at thebottom of the page, using the number of the page where the flow chart will continueas the label. On the top of the connected page, place a page connector symbol at thetop of the flow-chart
Direction Arrows. These arrows connect the different symbols, identifying inwhich direction the instructions will be processed.
-
7/31/2019 COM 301 Handout
19/28
19 | P a g e
CONTROL STRUCTURES
A control structure is a primary concept in most high-level programminglanguages. In its simplest sense, it is a block of code. More specifically, control
structures are blocks of code that dictate the flow of control. In other words, acontrol structure is a container for a series of function calls, instructions andstatements.
A simple example of a control structure is, if a then b else c. These statements willbe included or excluded based on the condition of a. This simple notion of if thencomprises the bulk of even the most sophisticated software applications.
For programmers it is essential to understand the three control structures, sequence,
repetition and selection which are the elementary building blocks for all programs.All programmers must learn what they are and how they can be used. These three
basic structures can be used to develop any kind of program and they are explained
below.
Sequence Structure: an action, or event, leads to the next ordered action in apredetermined order. The sequence can contain any number of actions, but no
-
7/31/2019 COM 301 Handout
20/28
20 | P a g e
actions can be skipped in the sequence. The program, when run, must perform eachaction in order with no possibility of skipping an action or branching off to anotheraction.
For example:
do the first thing do the next thing do another thing
In pseudocode:
Declare a variable called count Set count to 1 Write out the value of count
Repetition/Looping in Programming
Repetition is also called iteration and is used when something is repeated over andover again, so anything where the program goes round in a loop. Typically
programmed using code such as WHILE, REPEAT and FOR statements.
For example:
Do the first thing While (some condition is TRUE)
o Do bo Do c
Do the next thing
In pseudocode:
Set count to 0 WHILE (there are items in a pile)
o Increase count by 1 Write out the number of items
-
7/31/2019 COM 301 Handout
21/28
21 | P a g e
Another example: to write out numbers 1 to 10
FOR count = 1 to 10o Write out count
Write out finished
NOTE: a FOR loop is used when it is known exactly how many times to go roundthe loop
The Decision / Selection Structure: In a selection structure, a question is asked,and depending on the answer, the program takes one of two courses of action, afterwhich the program moves on to the next event.
Selection is used to make a decision to go down one path or another, often
programmed using code such as an IF statement, or a CASE statement.
For example: To Pack my bag for work)
Pack my PC Pack my money If it's raining
o Pack my coat
In pseudocode:
Work out total cost If (total cost > 10) THEN
o Write out no delivery charge ELSE
o Write out 5 delivery charge Write out thankyou
Another example using a CASE:
Write out the day CASE (day)
o Monday: write out first working day of the weeko Friday: write out last working day of the weeko Saturday: write out the first day of the weekendo Sunday: write out the second day of the weekend
ENDCASE
-
7/31/2019 COM 301 Handout
22/28
22 | P a g e
Sometimes there is confusion between the Repetition and Selection statements, asboth use a condition. A condition is a test, resulting in true or false. One way ofdescribing the difference is that when making a selection, the condition is onlyever tested once. When used in repetition, the condition is tested a number of
times, every time the program decides whether to loop.
Beginners who take the time to learn the basic building blocks of programmingwill find coding in new languages easier and developing computer programsrequires an understanding of the three basic control structures outlined above.
There are many other types of control structures than the if then structure. In broadterms, these include the jump or unconditional branch, the conditional branch, theloop, which is essentially a conditional branch, subroutines, co-routines,continuations, and the conditional halt. There are also lower level flow controls,
such as interrupts and signals.
The most common specific forms of those control structures are gotos, subroutines,for loops, do while loops, if then, try catch finally, so on and so forth. The namesdeviate between languages but for the most part these concepts are universal acrossall imperative programming languages. The concept of the conditional branch, or ifthen else, exists in C++ as it does in Visual Basic.NET as it does in Ruby.
Programmers reading or maintaining code need to be able to identify these controlstructures easily. Formatting them in a structured way allows them to beidentifiable and distinct from each other. The coding standard structures them bycombining a series of style rules. In most standards, these rules center onindentation and line breaks.
Let us consider the C-style condition if (a == 5) { b = 1 } else { b = 0 };This is a perfectly acceptable C-style condition. However, the widely acceptedcoding standard would have us write it as such:if ( a == 5 ) {
b = 1 }
else {b = 0};
WORKING LIKE A PROGRAMMER: THE PROCESS OF CREATING
PROGRAMS
-
7/31/2019 COM 301 Handout
23/28
23 | P a g e
In Practice: SDLC System Development Life Cycle in Detail: SDLC stands for
system development life cycle. It is a methodology/process used by people who
work in information technology to solve problems to providing effective and
efficient solutions. It remains as the foundation for planning and implementing
most systems projects (i.e. application programming). If not for programming,
SDLC can also be used for hardware and networking projects. It represents a
common tool that you will frequently encounter in working with computer
systems.
System Development Life Cycle: I tell students that using SDLC is an exercise in
common sense. Do not let the term intimidate you. It sounds very complicated but
in fact is a very logical way of approaching and solving a complex problem. In
short, SDLC is a rifle approach (versus and unorganized shot-gun approach) toquickly and successfully solve a problem. It includes four common sense process
steps to solve any type of problem (1) define the problem and assign it a priority
(2) analyze the problem particulars and identify possible solutions, (3) design a
solution and (4) implement your solution. This process is not just for computer
programming. It should work on everything from fixing a flat tire to building an
operating system. It works because it documents a plan of attack that logically
focuses on a problem and identifies alternatives.
SDLC contains the following phases:
1. Planning - Defining the problem and prioritizing against other programming
projects
2. Requirement Analysis - Fact Finding problem specifics through observation,
questionnaires and interviews.
3. Design - Develop problem alternatives. and models to represent problem andsolution
4. Development - Coding and testing of the program
5. Implementation - Installing the program and training the user
-
7/31/2019 COM 301 Handout
24/28
24 | P a g e
6. Maintenance - On-going changes to the program (maintenance)
SDLC contains a series of steps that must be completed as phases. For example,
the first phase needs to be started before the second phase and the third phase is to
be started before the fourth face and so on. Even though there is this dependencythere is also no reason why there cannot some be parallel activity. By this I mean
one phase can start before the preceding face is completely finished. SDLC has
been called a waterfall approach because one phase flows into the next phase.
Key Concept: SDLC can loosely be defined as exercising common sense. Most
problems, computer or non-computer, can be solved by using a logical common
sense approach to solving the problem. After all, arent most problems solved by
getting the facts, designing a solution and implementing the solution? It could be a
math problem, a science problem or a problem with your car, the approachedsuggested in SDLC could work for them all.
Program Development Process
To become a successful programmer, you need to begin to work like a
programmer. To work like a programmer, you have to start using the program
development process. Even though the process name sounds rather imposing, the
program development process (PDP) is actually very straightforward and very
much common sense. PDP is a sub-process of SDLC that becomes part of several
of the steps of SDLC.
Program Development Process (PDP) - you can think of the program
development process as standardized set of steps used to provide a logical,
common sense approach (or process) to solving a difficult problem with a
computer application. PDP is a checklist that ensures that the steps of building a
program are followed so that no important step is omitted or taken out of order.This process has long been used by programmers as a professional standard
because of it simplicity, effectiveness and consistency.
-
7/31/2019 COM 301 Handout
25/28
25 | P a g e
Figure 4: Program Development Process is outlined as a five step sequential
approach. Maintenance is reflected as a separate process that can occur one ormore times after the original program is implemented.
Key Point: SDLC and the PDP are not industry standardized processes. In other
words, you may find different various versions of each depending on the
development process you are using. The PDP, in particular, is a process created
specifically for the eBookas a composite of other similar program development
processes used in the industry. If your SDLC and PDP phases look different that in
other textbooks, look at the activities in each phase and you will see that even if the
phase name is different, the spirit of each phase is the same.
An Example: Using the SDLC and the Program Development Process
Problem: Program Logic is needed to develop a program that wills Average
Class Grades.
Program Development Process Phases
Planning
Start with a problem statement: I need a program that will calculate the test scores
for a class of 15 students and tell me the average test score.
-
7/31/2019 COM 301 Handout
26/28
26 | P a g e
Requirements Analysis
*Fact finding or requirements analysis (done by interviewing the end user): Do you
have an example of how you want the average number displayed? Do all of the test
scores need to be displayed or just the final average? How would you like to inputthe scores? One at a time or all at once? What if there are less than 15 scores?
Design
Conceptual design: Conceptual design usually takes the form of a logic
model that lays out the ideal logic structures to provide a solution. In
conceptual design, we will program the expressions needed to calculate the
average along with the logic necessary to accept the inputted values.
Detail design: We are ready to code our solution using a programminglanguage. We take the conceptual design as a starting point and using the
syntax options of the programming language, code the logic structures into
programming language structures.
Testing: We will perform unit tests as we go. Unit testing is used to test
sections of the entire program. A system test will be performed at the end of
the process to make sure our scores are calculating correctly and that any
errors are flagged for the end user.
Implementation
Implementation: During implementation, we move into production the test
average calculator program on to the PC of the person using it. The program
is complete and ready to use.
Maintenance
Maintenance: No program is written once and not revisited without some
changes. No sooner than the user started to use this program then did they
decide that it would be useful in their other classes. The other classes have
different numbers of students so that a program that score 15 tests needs to
be changed to a program that scores however many tests the user has to
grade. We now start back up at the problem statement and move through the
phases once more for this program maintenance.
-
7/31/2019 COM 301 Handout
27/28
27 | P a g e
Other Program Development Process Concerns
The following processes and activities are not defined specifically to one program
development phase but in fact can be a part of several or all of the PDP phases.
Deployment:
Deployment concerns the techniques that will be used to deliver your program to
your users. Deployment is affected by options available for the distribution of
software (i.e. some users computers will have to be updated by CD-ROM or
updated via the Intranet/Internet) and the type of program (Internet or Desktop).Youll also want to consider if automatic configuration is required by your
program. This might include placement of an icon on the users desktop or
placement of the program in the programs start menu (in the case of Microsoft
Windows).
Internet applications have different deployment concerns and require planning
throughout the PDP process. Programs do exist for the programmer to assist in
deployment. Understanding the features and functions of these products early in
the detail design process can make deployment much easier when the project
reaches implementation.
Training/Documentation:
It is very easy to forget about training and documentation until the project is
complete. Many times training and documentation is either ignored or given no
consideration at all. You need a look this task as one of the ways to ensure yourprograms success. If users cannot understand how the program works, they will
both reject the program out of frustration or turnaround and request a number of
modifications which will only lengthen the amount of time and cost needed to
complete the software.
-
7/31/2019 COM 301 Handout
28/28
28 | P a g e
Programming Tip: Many programming languages support special
documentation tags (these tags are similar to HTML tags, if you are familiar with
web page formatting) which can be added during the coding process so that
documentation can be created automatically when the program is complete.
Training is sometimes the responsibility of the programmer and is sometimes the
responsibility of education and training staff. Even if its the responsibility of
another group, as the programmer, youll certainly have to be actively involved in
describing how the program operates and what prerequisite skills will be necessary
for full use of the programs features.
Project Management:
Not all programs are contained in a single file and programmed by one
programmer. Depending on the size of the application project, you may be part of a
team who is developing a new system. This team may be developing 20 are 30
programs independently of one another but programs which will need to function
in concert with one another at the projects conclusion. To facilitate an effort of
this magnitude, typically a project manager is assigned to the project. The projectmanager will likely use project management software. Project management
software packages are designed to improve the productivity of the entire team by
keeping track of whos doing what and in what sequence. It helps ensure that
programs are developed on schedule and that one programmer is not held up
waiting for the work of another programmer to be completed.