430 likes | 1.5k Views
What is Programming?. A program is a list of instructions that is executed by a computer to accomplish a particular task . Creating those instructions is programming by a programmer. Programming language : Special language (like French or German) Understood by the computer
E N D
What is Programming? • A program is a list of instructions that is executed by a computer to accomplish a particular task. • Creating those instructions is programming by a programmer
Programming language: • Special language (like French or German) • Understood by the computer • Tells the computer what to do • Used by a programmer to write a program • Visual Basic, Java, C#, C++, COBOL • Machine language: • Language of the computer • Every “Programmer” language is converted to machine language • Consists of bits on or off only • Compiler or interpreter: • Software that translates programming languages to machine language
Coding the program: • Select the programming language • Write the instructions • Using software to translate the program into machine language: • Programmers write instructions in English-like high-level languages • Compilers or interpreters change the programs into low-level machine language that can be executed • Syntax errors are identified by the compiler or interpreter
Binary Machine Language – • all data types consist of 1s and 0s • 1 bit (0 or 1) • 4 bits = nibble • 1 byte = 8 bits = 2 nibbles • Is the storage for one character • 1 word = 4 bytes • 1 K = 1 KB = 1 kilobyte = 1,0240 bytes = 210 bytes • Kilo = 1,000 : 1 KB = 1,000 bytes • 1 Meg = 1 megabyte (MB) = 1 million = 1024 KB • 1 GB = 1 gigabyte (GB) = 1024 MB = 1,000,000,000 • Many people approximate to steps of 1000, not 1024
Programming Languages • Machine Languages • 0110110111110111 0000000100000000 0000000100000000 • Assembly Languages • One programmer instruction converted to 1 machine level instruction • ADD A,B • High-level Languages • Looks more like English words and algebraic expressions • Examples of high level languages • Programmer instruction converted to many machine level • ADA BASIC • C++ FORTRAN • COBOL Java • Pascal Visual Basic
One Machine Language Instruction Machine Language Generation Programmer written computer code Programmer written computer code Translator (Interpreter) Program(browser) Compiler Assembler FUNCTIONBrowsersnetscapeMS ExplorerJavascriptPHPASP Many machine Language Instructions .exe file Execute Execute MS Word, Windows XP, MS Excel, Vista, MS Explorer
Writing Programs • To write a program in a high-level language, you need: • Appropriate software • A text editor to type and edit program statements • A debugger to help find errors in program code • A compiler or interpreter to translate the program into machine language
Error Types • Logic errorsare more difficult to locate than syntax errors Syntax: the rules governing word usage and punctuation in the language(format, recipe, formula)
A program must be free of syntax errors to be run, or executed, on a computer • The program will not compile or be translated • A message will point out the offending instruction • To function properly, the logic must be correct • The program will still execute • The output may be incorrect • The program may exit prematurely • The program may ABEND (Abnormal Termination) • The program may execute with no errors/problems
Logic • A program must be free of syntax errors to be run, or executed, on a computer • To function properly, the logic must be correct • What’s wrong with this logic for making a cake?
Two major programming techniques: • Procedural programming • Object-oriented programming • Procedural programming: focuses on the procedures that programmers create • Object-oriented programming: focuses on objects that represent real-world things and their attributes and behaviors • Both techniques employ reusable program modules
Mainline Logical Flow Through a Program • Procedural program: one procedure follows another from beginning to end • Mainline logic has three distinct parts: • Housekeeping: steps to get ready • Main loop: instructions executed for every input record • End-of-job: steps taken at end of program • Break the logic down into at least three modules
Mainline Logical Flow Through a Program • Modularization of the program: • Keeps the job manageable • Allows multiple programmers to work simultaneously • Keeps the program structured
Housekeeping Tasks • Housekeeping tasks: include all steps that occur at the beginning of the program • Declare variables • Open files • Perform one-time-only tasks such as printing headings • Read the first input record
Annotate the Output • If the output consists of numbers or any data that has no explanatory text with it, you should annotate your output – this means to add some text so the user knows what the output means.