Sie sind auf Seite 1von 28

1| Page

INTRODUCTION A language is a medium through which we communicate with each other. While communicating 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 of each other. Communicating to a computer is not taking like the person to person. It means giving a set of instructions to a computer and the computer follows the instructions given 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 as computer 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 a programming 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 instruct the computer. The instructions written in the binary number system is known as machine language. Machine language is directly understood by the computer. In the early time, Charles Babbage had used machine language to write instructions for his Differential and Analytical engines. However, writing programs in machine language is very difficult. Therefore, many other artificial languages have been developed for instructing computers. Expect machine language, a computer does not directly understand any other computer languages so the instructions written in other computer languages must be translate into machine language. This translating task 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. A person who writes a program for computers is known as a programmer. The process of writing set of instructions in a computer language is called programming. Types of computer languages

2| Page

The computer languages are divided into two categories. They are a. Low-level language b. High-level Language a. Low-level language Low-level language is machine dependent language. The program written for one computer in low level language cannot be used in another computer. This makes it difficult to learn and use, as the programmer must have the in-depth knowledge of different computers to write programs in a low level language. There are two types of low level languages. They are i. Machine Level Language (MLL) ii. Assembly Language (AL) i. Machine Level Language Machine level language is the first generating language. Machine level language is the 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. machine dependent. The program written in one computer cannot be run in another computer. 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.

3| Page

ii. Assembly Language This is second generation language. Assembly language was developed by the programmers to overcome the drawbacks of the machine level language. Assembly language uses letter, words and symbols instead of binary digits. These letter, words and symbol are called mnemonics. Assembly language is little bit easier than machine language. Since Assembly language is also machine dependent language 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 mathematical symbols 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 the computer on which they are writing programs. The programs written in a high level language in one computer can be run in any other computer. The programs written in HLL need to translate into machine language. This translation is done by either Compiler or an Interpreter. BASIC, COBOL, FORTRAN, PASCAL, C, C++, JAVA etc., are some examples of 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.

4| Page

ELEMENTS OF QBASIC Every programming language consists of some basic elements which are required to make a program. The element required to construct a QBASIC program consists of 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 QBASIC Character Set. The QBASIC Character Set consists of alphabets (both small and capital), numbers (0 to 9) and special characters. These special characters have their own meaning and function. The table below shows the special characters used in QBASIC.

QBASIC keywords and variables are formed by using the characters defined in the QBASIC Character Set. 2. KEYWORD Keywords are those words which have special meanings in QBASIC. Keywords are formed by using characters of QBASIC Characters Set. Keywords are

5| Page

statements, commands, functions (built in functions) and names of operators. The keywords 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 stores the 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 from appearing 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 enter something. 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. You can 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 is one). You must remember is that a string input requires a string variable a number input requires a variable that can store a number.

6| Page

You know that a string will have a "$" on the end of the variable name, and a value variable will just have the standard name and nothing else. Example Uses of the INPUT: Program Screen Output CLS INPUT "Your Name:"; name$ Your Name:?Ralph INPUT "Your Age:"; age Your Age:?17 PRINT "Hello ";name$;" Your Age is Hello Ralph Your age is 17 ";age THE PRINT STATEMENT The PRINT statement allows you to print something on the screen. You must use quotation 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 quotations in the proper place when you are using the PRINT statement, your program will fail to run correctly (unless you are printing the value found in a variable). Here is an example: PRINT "Hello there. How are you doing" PRINT PRINT "See ya later" If you you wish to PRINT some information stored in the computer out to the screen, 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 how you want to space out the objects when they print on the screen. You can use the comma (,) 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 the next object will be printed exactly right beside the last object that was printed on the screen.

7| Page

the Code PRINT "Hello" ; "There" PRINT PRINT "Hello" , "There"

the Output to the screen HelloThere Hello There

3. CONSTANTS Constants are the data or the values in a program that cannot be changed during the program execution. The data may be a letter, words, numbers, or special characters. A constant can be stored in a variable when it is required to use in more than one statement or expression. In QBASIC, these data/constants are grouped into two main categories. They are: a. Sting Constant b. Numeric Constant a. String Constant: Sting Constant is a letter, words, numbers, combination of letters with numbers or special 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 a numeric constant. Thousand separators are not allowed to use in numeric constant. Numeric data should not be enclosed in double quotes. Mathematical operations and 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 double precision.
1. 2. 3.

Integer: Integer is whole number between -32768 to 32767. Long Integer: Long Integer is a large range of whole number. Single Precision: Single Precision is seven digit or less than seven digit positive or negative number that contains decimal point. Single Precision can be in the exponential form using E or with a trailing exclamation point.

8| Page

4.

(!). 564, 78.65, 1.2 E-06 and 12345.678! are some examples of Single Precision Constants. Double Precision: Double Precision is 17 digit or less than 17 digit positive or 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 produce information. A program can use data only when data are stored in the computer memory (RAM). In a computer memory, there may be many data. So, you need to tell the computer to use only those data which you want to use in a program. This is possible if you assign a name to the place where you have stored a data. In QBASIC, 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 can say, a variable is an entity that stores data needed to be used in a program. You can also 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 value of a variable can be change during the execution of the program. There are mainly two types of variables. They are: i. String Variable ii. Numeric Variable A string variable stores sting data. Its types declaration sign is dollar ($). A numeric variable stores numeric data. A numeric variable can be Integer, Long Integer, Single Precision or Double Precision variables.

An Integer variable can store only an integer number. Its type declaration sign is percentage (%). A Long integer variable can store a large range of whole number. Its type declaration 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 also use it without declaration sign. It is the default numeric variable. A Double Precision variable also stores a whole number as well as number with decimal point. Its type declaration sign is hash (#).

RULES FOR NAMING A VARIABLE a. Variable names can have maximum of 40 characters.

9| Page

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 Sting Varibales. Salary!, Age%, Mark, Number1, Number2, FirstNum, RollNumber, etc., are examples of Numeric Variables. 5. OPERATOR Operators are symbols that indicate the type of operation QBASIC has to perform on 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 -------------------------- 13 ii. Subtraction ----------- - ---------------------- 8-6 --------------------------- 2 iii. Multiplication -------- * ---------------------- 5*4 --------------------------- 20 iv. Division ---------------- / ------------------------ 8/2 -------------------------- 4 v. Integer Division -------- \ ----------------------- 9\2 --------------------------- 4 vi. Exponential ----------- ^ ----------------------- 4^3 ------------------------- 64 vii. Modular Division --- Mod --------------------- 7 mod 3 ------------------------ 1 b. Relational Operators

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 of sting data is done on the basis of ASCII value. The result of comparison is either true (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>RAT iii. < ------------------- 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 Operators Logical Operators combine two or more relational expressions to evaluate a single value as True (Non Zero) or False (Zero). The result of evaluation is used to make decisions about the program flow. The commonly used logical operators in QBASIC are AND, OR and NOT. i. AND Operator: AND operator returns True when all the results returned from individual relational 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 ----------------------------------- F T ------------------------------- F ----------------------------------- F F ------------------------------- F ----------------------------------- F T ------------------------------- 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. If all the relational expressions returns False then only the combined result returned by OR operator will be False.

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 ---------------------------------- T T ------------------------------------------- T ---------------------------------- T F -------------------------------------------- F ---------------------------------- F iii. NOT Operator: NOT Operator operates on one operand and returns True if the logical operation returns 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 as the String operator. The act of combining two stings is called concatenation. The following 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 is evaluated to get a result. The result of the expression is either string data, numeric data or logical value (true or false) and can be stored in a variable. For example, the following are expressions in QBASIC. (A + B) > C A>=B+C u* t + *a*t^2 An arithmetic expression may contain more than one operator. While evaluating such expressions, a hierarchy is followed. The hierarchy in arithmetic operations is listed as given below:

12 | P a g e

a. Exponentiation (^) b. Negation (-) c. Multiplication and division d. Integer division e. Modular division f. Addition and Subtraction The hierarchy in relational operations are =, >, <, <>, < =, and > = respectively. The hierarchy in logical operations are NOT, AND and OR. NOTE:

When parenthesis is used, it changes the order of hierarchy. The operators inside the parenthesis are evaluated first. So, you can say QBASIC expression follows rule of PEDMAS where P, E, D, M, A and S stand for parenthesis, Exponentiation, Division, Multiplication, Addition, and Subtraction respectively. Algebraic expression cannot be used directly in programming. It must be converted 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. A completed 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).

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 can perform. 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.

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 examples would 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.

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 they threatened 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).

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 of diagram that represents an algorithm or process, showing the 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 or programs. Like other types of diagram, they help visualize what is going on and thereby help the viewer to understand a process, and perhaps also find flaws, bottlenecks, and other less-obvious features within it. There are many different types of flowcharts, and each type has its own repertoire of boxes and notational conventions. The two most common types of boxes in a flowchart are:

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. A symbol appearing in a particular "lane" is within the control of that organizational unit. This technique allows the author to locate the responsibility for performing an action or making a decision correctly, showing the responsibility of each organizational unit for different parts of a single process. Flowcharts depict certain aspects of processes and they are usually complemented by other types of diagram. For instance, Kaoru Ishikawa defined the flowchart as one 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 software development, the activity diagram, which is a type of flowchart, is just one of many different diagram types. Nassi-Shneiderman diagrams are an alternative notation for process flow. Common alternate names include: flowchart, process flow chart, functional flow chart, 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 people can read your flow chart diagram, and you can read other peoples diagrams. Program instructions are described through the flowchart with instructions grouped into different symbols, and the flow or sequence of instructions being used directed through the use of connecting arrows.

18 | P a g e

Terminator. The terminator symbol marks the beginning, or ending of a sequence of instructions. This is often used when marking the beginning and ending of the program. Process. Marks instructions that are processed such as calculations and declarations. For our purpose, if you cannot figure out which symbol to use, then use this symbol as a placeholder until you can be more certain which is the better flowchart symbol to use. We will use it for when we make mathematical calculations and declaring variables. Input/Output. Marks instructions to perform data input (bring data into the program from outside) or output (send data out from the program). We will use this when we ask the user for keyboard input and when we display information to the screen or printer. Decision. Marks instructions where the program makes a decision. Decisions are the only symbols allowed to have more than one flow out of the symbol. Decisions should have an outside flow of yes and no. We will use this symbol when comparing different data items. Predefined Process. Marks a group of instructions. A predefined process can be used to specify that the specifics of these instructions are already known, or are shown 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 take up too much space. Connector. Joins different parts of the chart together. This is used when the chart gets big and the number of lines may become confusing. The connector circle is labelled with the label that will identify the ingoing connector. Page Connector. Joins different pages of a chart. Use the page connector at the bottom of the page, using the number of the page where the flow chart will continue as the label. On the top of the connected page, place a page connector symbol at the top of the flow-chart Direction Arrows. These arrows connect the different symbols, identifying in which direction the instructions will be processed.

As an example, the following flowchart for computing the factorial of N written N! and equal to 1 2 3 ... N.

19 | P a g e

CONTROL STRUCTURES A control structure is a primary concept languages. In its simplest sense, it is a block structures are blocks of code that dictate the control structure is a container for a series statements.

in most high-level programming of code. More specifically, control flow of control. In other words, a of function calls, instructions and

A simple example of a control structure is, if a then b else c. These statements will be included or excluded based on the condition of a. This simple notion of if then comprises 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 a predetermined order. The sequence can contain any number of actions, but no

20 | P a g e

actions can be skipped in the sequence. The program, when run, must perform each action in order with no possibility of skipping an action or branching off to another action. 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 and over 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 b o 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

21 | P a g e

Another example: to write out numbers 1 to 10


FOR count = 1 to 10 o Write out count Write out finished

NOTE: a FOR loop is used when it is known exactly how many times to go round the 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, after which 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 week o Friday: write out last working day of the week o Saturday: write out the first day of the weekend o Sunday: write out the second day of the weekend ENDCASE

22 | P a g e

Sometimes there is confusion between the Repetition and Selection statements, as both use a condition. A condition is a test, resulting in true or false. One way of describing the difference is that when making a selection, the condition is only ever 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 programming will find coding in new languages easier and developing computer programs requires an understanding of the three basic control structures outlined above. There are many other types of control structures than the if then structure. In broad terms, these include the jump or unconditional branch, the conditional branch, the loop, 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 names deviate between languages but for the most part these concepts are universal across all imperative programming languages. The concept of the conditional branch, or if then 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 control structures easily. Formatting them in a structured way allows them to be identifiable and distinct from each other. The coding standard structures them by combining a series of style rules. In most standards, these rules center on indentation 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 accepted coding 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

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) to quickly 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 and solution 4. Development - Coding and testing of the program 5. Implementation - Installing the program and training the user

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 dependency there 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 approached suggested 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.

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 or more 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.

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 input the 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 programming language. 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.

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 your programs 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.

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 project manager 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.

Das könnte Ihnen auch gefallen