Introduction to programming


Published on

Published in: Education, Technology
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Introduction to programming

  1. 1. Introduction toProgramming
  2. 2. Computer Program• A computer program is nothing morethan a list of instructions that tell thecomputer what to do.• A computer program is an organizedlist of instructions that are designed tocause the computer to behave inpredetermined manner in order toaccomplish a task. Introduction to Programming
  3. 3. Computer Program Windows OS with all itsicons, toolbars, and menus is reallynothing more than a series of instructionsthat the computer follows each time youpress a button, click on a menu, orrespond to a dialog box. At the base level, all programsaccept input from the user, process thedata, and display, save or print the results. Introduction to Programming
  4. 4. Goals of a Program• Be easily read and understood• Be easy to correct if problems arise• Be easy to modify as elements in the task may change• Function as it was intended, to solve a specific problem or perform a specific task Introduction to Programming
  5. 5. Programming Language A programming language is avocabulary and set of grammaticalrules for instructing a computer toperform specific tasks. These grammatical rules arealso called the syntax of thelanguage. Introduction to Programming
  6. 6. Programming Languages1. Machine languages2. Assembly languages3. High-level languages4. Fourth-generation languages Introduction to Programming
  7. 7. Machine languages Machine languages use binary toprovide instructions to the computer. Machine languages are notcommon today as they are specific toeach CPU and require long lists ofzeros and ones. These programs are very difficult towrite and very error-prone. Introduction to Programming
  8. 8. Assembly languages Assembly languages use a specialrepresentation of instructions to givethe computer instructions. These languages are only used byprogrammers developing complicatedprocesses like operating systems. Introduction to Programming
  9. 9. High-level languages High-level languages use English-like commands to give instructions. They includeBASIC, Pascal, C, C+, C++, COBOL, Java, JavaScript and Fortran. Of course, the computer does notspeak English. It speaks binary, therefore theprogramming instructions written in a high-level language must be converted intobinary using a compiler or interpreter. Introduction to Programming
  10. 10. Interpreters vs. Compilers Interpreters translate programsone line at a time while compilersconvert a whole file or program atonce and then generate a separateexecutable file. The executable file usually endswith the extension .exe and can berun without the programminglanguage. Introduction to Programming
  11. 11. Fourth-generation languages Fourth-generation languages arelanguages that write code for the userthrough a series of menus andprompts. Some examples of fourthgeneration languages includeORACLE, and Visual BASIC. Introduction to Programming
  12. 12. Common Features ofProgramming Languages There are many programminglanguages that can be used tocreate a computer program. Each of these languages hasdifferent syntax. However, a basic set ofinstructions is always present inany programming language. Introduction to Programming
  13. 13. Basic Set of Instructions1. Input2. Output3. Mathematics4. Conditional execution5. Repetition Introduction to Programming
  14. 14. BASIC Language BASIC stands for Beginners All-Purpose Symbolic Instruction Code. It is developed in the mid-1960sat Dartmouth College by ProfessorsJohn G. Kemeny and Thomas E.Kurtz. Introduction to Programming
  15. 15. Why Study BASIC? When you learn BASIC, you alsolearn many of the fundamentals ofother programming languages. You can also create programseasily. Once you get into it, youll findthat the fun in creating programs isworth coming back to. Introduction to Programming
  16. 16. QBASIC QBASIC is a programminglanguage written for computers backin 1975, by Bill Gates and Paul Allen. Introduction to Programming
  17. 17. Filename Menu BarImmediate Window
  18. 18. WORK AREA
  20. 20. 10 CLS500 END
  21. 21. 10 CLS20 DISPLAY 12500 END
  22. 22. Errors in Programming If you made any mistakes you will begiven an error message. The error message, also called adiagnostic message, will indicate the linenumber and a description of the error. At this point, you will have to do whatis called debugging. Programmers spend a great deal oftime debugging programs. Introduction to Programming
  23. 23. Debugging Debugging is the process offinding and fixing errors in a program. The word debugging comesfrom a common computer problem inthe 50s. Bugs would fly inside thecomputer. Technicians had to find andremove them in order for the systemto work.This word is still in use today. Introduction to Programming
  24. 24. Types of Programming Errors1. Syntax errors2. Logic errors Introduction to Programming
  25. 25. Syntax Error A syntax error is a mistake in thegrammar or structure of a command. For example, in QBASIC, the syntaxfor PRINT says you must type PRINT, aspace, and then the literal, number orexpression. If by mistake you omit the commandPRINT, then the command will not work.This is a syntax error. Introduction to Programming
  26. 26. Syntax Error All syntax errors are captured bythe compiler or interpreter. When you get a syntax error inyour program, you should read anddecipher the error message, thenmove to the line identified and fix theerror. Introduction to Programming
  27. 27. Logic Error A logic error is much more difficult to isolateand fix. A logic error is a mistake that the compileror interpreter cannot identify. This kind of error occurs when yourinstructions have no syntax error, but the programdoes not accomplish its intended purpose. For example, if you were asked to find thearea of a circle, but instead calculated thecircumference of a circle, then you would have alogic error. Introduction to Programming
  28. 28. Correcting Logic Error The only way to determine a logicerror is to test your program. You should check if the programworks correctly, figure out what the answershould be (on your own), then check youranswer with the result the programprovides. If the computer provides a wronganswer, then you will have to examine yourprogram to locate and fix the error. Introduction to Programming
  29. 29. Save your program! Once you have found your error andcorrected it, rerun your program. When all errors are fixed, save thefile. To do this, press ALT + F (“File“) andthen press S("Save“). Your file will besaved with the name you provide and willend with the extension .bas. The maximum number of charactersfor the QBASIC program filename is eight. Introduction to Programming
  30. 30. 10 CLS20 DISPLAY 12500 END
  31. 31. 10 CLS20 PRINT 12500 END Change 12 by any number
  32. 32. 10 CLS20 PRINT LORA500 END
  33. 33. Recall your Algebra!Constants and VariablesConstants are represented by numerals.Examples: 5, -3, 4.56, - 13.9Variables are represented by letters.Examples: x, y, n, C, F Introduction to Programming
  34. 34. Recall MS Excel!
  35. 35. MS Excel FormulaIn MS Excel, a cell can contain formula.Example: Cell C1 contains =A1 * B1A1 and B1 are cell addresses.They can be used as variables in a formula. Introduction to Programming
  36. 36. Variable NamesIn Algebra, x + y means x is increased by y.In Algebra, xy is the product of x and y.In QBASIC, xy is only a single variable name and NOT a product of x and y. Introduction to Programming
  37. 37. 10 CLS20 PRINT LORA500 END
  38. 38. QBASIC COMMANDS1. CLS – clears the screen2. END – terminates the program3. PRINT – displays the result of computer processing Introduction to Programming