Introduction to programming
Upcoming SlideShare
Loading in...5
×
 

Introduction to programming

on

  • 956 views

 

Statistics

Views

Total Views
956
Views on SlideShare
956
Embed Views
0

Actions

Likes
1
Downloads
53
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Introduction to programming Introduction to programming Presentation Transcript

    • Introduction toProgramming
    • 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
    • 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
    • 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
    • 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
    • Programming Languages1. Machine languages2. Assembly languages3. High-level languages4. Fourth-generation languages Introduction to Programming
    • 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
    • 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
    • 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
    • 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
    • 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
    • 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
    • Basic Set of Instructions1. Input2. Output3. Mathematics4. Conditional execution5. Repetition Introduction to Programming
    • 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
    • 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
    • QBASIC QBASIC is a programminglanguage written for computers backin 1975, by Bill Gates and Paul Allen. Introduction to Programming
    • Filename Menu BarImmediate Window
    • WORK AREA
    • FORMAT IN WRITING PROGRAM LINESLINE NO. PROGRAM STATEMENT 10 CLS Space
    • 10 CLS500 END
    • 10 CLS20 DISPLAY 12500 END
    • 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
    • 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
    • Types of Programming Errors1. Syntax errors2. Logic errors Introduction to Programming
    • 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
    • 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
    • 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
    • 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
    • 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
    • 10 CLS20 DISPLAY 12500 END
    • 10 CLS20 PRINT 12500 END Change 12 by any number
    • 10 CLS20 PRINT LORA500 END
    • 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
    • Recall MS Excel!
    • 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
    • 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
    • 10 CLS20 PRINT LORA500 END
    • QBASIC COMMANDS1. CLS – clears the screen2. END – terminates the program3. PRINT – displays the result of computer processing Introduction to Programming