CHAPTER 1 Introduction to Computer Program ¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾ ¾
Introduction to Computer. Basic operations in a computer system. Computer Programs. Generation of Programming Languages. Language Translators. The importance of programming. Programming Process Structured Programming vs. Object Oriented Programming. Principles of Structured Programming
Introduction to Computer ¾ Computer = an electronic device that input, stores, processes data (input, output, storage and processing devices) and generate the useful information.
¾ Basic components of a computer systems :9 Hardware Equipment that processes data to create information includes input, output, storage and processing devices.
9 Software Step-by-step instructions that tell the computer how to do its work. It is also called a program. It’s purpose to convert data to useful information.
Basic Operations in a Computer System STORAGE INPUT •Whatever data that is put into a computer using an input devices •E.g. Mouse, keyboard
PROCESSING •Convert input data into information. •E.g. U
•Store the data or information for future use (permanently or temporarily) •E.g. Hard disk, memory
OUTPUT •Generate the useful information using output devices •E.g. Monitor, printer
Computer Software SOFTWARE
SYSTEM SOFTWARE • provides an environment for to execute the application software. •Enables the application software to interact with computer hardware. •Eg. Operating System
APPLICATION SOFTWARE • end software. •A program that performs a common task to the . •Eg. Word, Excel.
Computer Programs ¾ Program = a set of instructions that the computer needs to follow to process the data into information.
¾ Computer Program = a sequence of instructions that the computer carries out to fulfill the task.
¾ Computer Programmer = a person who writes a computer program.
¾ Computer Programming = the act of deg and implementing computer programs using the programming languages.
¾ Programming Language = provides a way to program a computer using instructions that can be understood by computers and human. It has its own vocabulary and rules of usage.
Generation of Programming Languages 9
1st generation (low-level language) z
9
2nd generation z
9
z
High-level language resembles some human language (English) – eg. COBOL, FORTRAN, BASIC. Procedural languages.
4th generation z
9
Assembly language (low-level language) that allows a computer to write a program using simple word instead of numbers.
3rd generation z
9
Machine Language is the basic language of the computer, representing data as 1’s and 0’s.
Very high-level language, much more -oriented and allow s to develop programs with fewer commands compared with procedural languages – eg. SQL, NOMAD
5th generation z
Natural Language uses human language to give people a more natural connection with computers.
Language Translator ¾ Language Translator = a program that accepts a humanreadable source statements and produces machine-readable instructions. There are Assembler, Compiler, Interpreter.
SOURCE CODE
ASSEMBLER • a program that translates the assembly language program into machine language.
• a program is a plain text written using any text editor
COMPILER • a program that translates high-level language into machine language. •Translate the source code once and saves to be reused. •Requires less memory and runs faster. •Eg. PASCAL, C++, COBOL
INTERPRETER • a program that translates source code of high-level language into machine language. •Each instruction is interpreted into machine language. •Program is easier to develop. •Eg. BASIC.
The Importance of Programming 9 9 9 9
Easy to express tasks from a particular problem domain. Allow to instruct computer to do a specific task in a certain instances. A skill required for a computer scientist and software engineering. A skill required to create a successful computer program.
The Importance of Good Programs ¾
Spacing ¾
¾
Indent ¾
¾
Each instruction has indention depends on its structure.
Comment ¾
¾
Each instruction begins with new line.
Help a human reader to understand the program.
Variable name ¾ ¾
Use descriptive name Rules of naming the variable :9 Other than reserved word. 9 Alphanumeric A-Z, a-z, 0-9, _ (underscore). 9 Length recommended 3 – 8 characters long.
Programming Process ¾ Define
the problem ¾ Develop an algorithm ¾ Code the program ¾ Test and debug the program ¾ Document and maintain the program
Define the problem ¾ ¾
Define what the job is, NOT HOW. What program is to accomplish ¾ What is the output. ¾ What is the input. ¾ Any formula (calculation).
Develop an Algorithm ¾
Algorithm ¾ ¾ ¾
¾
a set of sequential instructions that are followed to solve a problem. Involves decisions to change the actions or cause parts of algorithm to be repeated. An algorithm can be represented by a pseudocode or flowchart.
Pseudocode ¾ ¾
expresses an algorithm in everyday English rather than programming language. Describe instructions in your own word.
¾
Flowchart ¾ ¾
a diagram to represent a flow of an algorithm. Basic flowchart :Rectangle represents processing or taking an action. Diamond represents making a decision.
Parallelogram represents an Input and output. Begin and end
Code the program ¾
¾ ¾
Algorithm pseudocode or flowchart is converted into program code, using the vocabulary or rules of usage of the programming language that you are using. Errors can be made during coding which prevent the successful compiling and linking. Common errors :¾ Syntax error = caused by a typographical errors and incorrect use of the programming language. ¾ Logic error = an error due to incorrect order of statements, incorrect formula others that can cause the incorrect output. ¾
Runtime error = occurs when a program gives the computer instructions that it is incapable of executing. Causes a program to terminate abnormally (crash or abort).
Test and Debug the program ¾ ¾
To provide input to make sure the result is correct or as needed by the . Involves various testing stages :¾ Alpha testing = a desk-check, read through the program to make sure there are no syntax and logic errors. ¾
Debug the program to detect, locate and remove all errors in a computer program, by entering some of the input data.
¾
Beta testing = runs the real-world data to test the program to make sure it works correctly (variety of live data).
Document and Maintain the program ¾
¾
Documentation ¾ Written description of a program, what it does and how to use. ¾ Purpose for reference to other programmers if any maintenance to be taken. Maintenance ¾ Any activities to keep the program in good working condition, error free and up-to-date. ¾ Involves any amendments, additional coding or repairs to the programs.
Structured Programming VS Object Oriented Programming ¾
Structured Programming ¾
Is a disciplined approach to writing programs that are clearer than unstructured programs, easier to test, debug and modify. ¾ Top-down approach to writing programs that breaks programs in modular forms and s standard logic tolls called control structures (Sequential, Selection, Case, Iteration). ¾
Object Oriented Programming ¾
Is a disciplined approach to programming that results in program that are easier to read, understand and less likely to contain errors. ¾ Data and instructions for processing the data are combined into self-sufficient “object” that can be used in other program.
Principles of Structured Programming ¾
Use Standard logic tools (Control structures) :¾ Sequential = one program statement follows another in sequence order. ¾
Selection = represents a choice, offers two paths to follow when decisions must be made by a program.
¾
Case = variation on selection. More than a single yes-or-no decision.
¾
Iteration = process may be repeated as long as a certain condition remains true.