1 / 73

Introduction to Computer Programs: History and Importance

This chapter provides a brief history of programming languages and introduces the concept of programming. It explores the importance of computer programs, the relationship between compilers, interpreters, assemblers, and programs, and the structure of C++ programs. The chapter also covers the program development life cycle and problem-solving phases.

newtonk
Download Presentation

Introduction to Computer Programs: History and Importance

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 1 introduction to computer programs

  2. Chapter Outline • A Brief History of Programming Language • Introduction to Programming • What is a computer program and importance of computer programming • Importance of good programs. • Relationship between compilers, interpreters, assemblers and programs • C++ program structure • Program Development Life Cycle • Problem solving phases; problem definition, algorithm design and implementation • Analysis, design, coding, maintenance

  3. Chapter Outcome At the end of this class, student should be able to: • Understand the concept and importance of program and programming • Differentiate between compiler, program, interpreter and assembler • Apply the steps in program development life cycle.

  4. A Brief History Of Programming Language • Programming Language is an artificial and formal language that has a limited vocabulary consisting of a set of keywords for making up instructions and a set of precise grammar rules. • Example: C, C++, Java, COBOL

  5. A Brief History Of Programming Language Binary digit (bit) The digit 0 or 1 Binary code  A sequence of 0s and 1s Byte  A sequence of eight bits The Language of Computer Digital signals are sequences of 0s and 1s Machine language: language of a computer

  6. A Brief History Of Programming Language Types of Programming Language

  7. A Brief History Of Programming Language Example of Programming Language machine language: BMI = weight/pow(height,2); 100100 010001 // Load 100110 010010 // Multiply 100010 010011 // Store assembler compiler

  8. Introduction To Programming • An electronic machine, operating under the control of instructions stored in its own memory What is Computer? A device capable of performing computations and making logical decisions at speed faster than human being.

  9. Basic Operation of a Computer Accepting data from a user Manipulating data Producing results INPUT PROCESS OUTPUT STORAGE Storing results ** These operations are under the control of instructions stored in the computer’s memory

  10. Component of a Computer COMPUTER HARDWARE SOFTWARE The series of instructions that tells the computer hardware how to perform tasks The electric, electronic and mechanical equipment that makes up a computer

  11. What is a program? • A program is a set of instructions that tells the computer how to solve a problem or perform a task. • A program is like a recipe. It contains a list of ingredients (variables) and a list of directions (statements) that tell the computer what to do with the variables. • A computer program is a set of detailed directions telling the computer exactly what to do, one step at a time. • A program can be as short as one line of code, or as long as several millions lines of code.

  12. What is a program? Computer process data under the control of sets of instructions called computer program. Computer programs guide the computer through orderly sets of actions specified by computer programmers.

  13. What is a programming? A programming is designing and writing a computer program. The programmer must decide what the program needs to do, develop the logic of how to do it, and write instructions for the computer in a programming language that the computer can translate into its own language and execute.

  14. The Importance Of Good Program • Some people consider Computer Programming as an Art which must follow certain standards in order to promote program clarity, readability, and comprehension so as to produce programs that are easier to read, test, debug, modify, and maintain. • Standards that have been emphasize by most of the programmers are: • Names for variables, types and functions. • Indent style and spacing.

  15. The Importance Of Good Program • Names for variables, types and functions. • Choosing an appropriate variable names is seen as the basis for good style programming • The following are some rules that can be used when naming variables, types and functions: • Function names will start with a lower case letter. • Example: double averageMark (double, double); • Variable names start with a lower case letter and the length must not be more than 40 characters. • Constant names can be all capital letters. • Example:const int MAX_SIZE = 10.

  16. The Importance Of Good Program • Indent style and spacing. • In order to improve its readability in programming, indentation is used to format program source code. • Adding spaces in between sentence makes your program much more readable. • A new level of indentation should be used at every level of statement nesting in your program. • The minimum number of spaces at each indentation should be at least 3, and many programmers use a tab mark (typically 8 spaces).

  17. The Importance Of Good Program Style 1 is much easier to read because they are indented well, and logical blocks of code are grouped and displayed together more clearly. • Indent style and spacing. • Comparison

  18. Relationship Between Compilers, Interpreters, Assemblers and Program All programs have to be translated into machine code before the computer can actually run them.  Programs written in high-level languages are translated into machine language by a compiler or interpreter.

  19. Relationship Between Compilers, Interpreters, Assemblers and Program • Interpreters  • a computer program that translates and executes a program written in a high-level language. • translates the source program, instruction by instruction, each time that program is run. • An interpreter translates program statements one at a time. • Interpreters are helpful during the debugging stage, but are slower during execution of the finished program.

  20. Relationship Between Compilers, Interpreters, Assemblers and Program • Compilers • a computer program that translates programs written in a high-level language into machine code. • translates each high-level instruction into several machine-code instructions all at once time. • Compiler runs much faster than an interpreted program.

  21. Relationship Between Compilers, Interpreters, Assemblers and Program • Assemblers • Consists of little more than a table look up routine, where each word of the source language (assembly language) is looked up in a table for its numerical equivalent, which is then output as part of the target language program. • Assembly language generally gives the programmer precise and direct access to every capability of the computer hardware.

  22. C++ Program Structure • How to write a complete program that consist certain element: • Begin the program with comments for documentation • Include header files, if any are used in the program • Declare variables and constants, if any • Write the definition of the function main

  23. Elements Of Computer Program • General form of a C++ Program • // Introductory comments// file name, programmer, when written or modified// what program does#include <iostream.h> void main() { constant declarations ;variable declarations; • executable statements ; • }

  24. Elements Of Computer Program • #include <iostream.h> compiler directive/header file • void main( )main function • { • //display greeting message comment • cout<<”Welcome to CSC 128 class”; statement • } • OUTPUT • Welcome to CSC 128 class braces Example of C++ program:

  25. /* • File Name : bmi.cpp • Programmer : Alif • Matrix No : 2006174538 • Topic : Exercise 1 • Program purpose : This program to calculate bmi for a user. • Date : 20 October 2013 • */ • #include <iostream.h> • #include <math.h> • void main() • { • double weight, height,bmi; • cout << "Enter weight in kg: "; • cin >> weight; • cout << "Enter height in meter: "; • cin >> height; • bmi = weight /pow(height,2); • cout << "The BMI is : "<<bmi<<endl; • } Comments Preprocessor directives Function Begin block Function Body End block Elements Of Computer Program Example of C++ program:

  26. Elements Of Computer Program

  27. Comments Important part of a program's documentation. It is used to explain the purpose of a program. Explain the parts of program and keep note regarding changes to the source code. Describe about the reason of the program and understand the program more clearly. Increased the user understanding of the program. Store the names of programmers for future reference. Used to make program documentation.

  28. Comments • Can be used in 2 ways: • Using /* */ symbol • Used for one or more than one line of comments in group • Example: /* This is the example of comment in C++ program.Thisis the second line */

  29. Comments 2. Using // symbol • Used only for one line • Example: // This is example of comments // This is the second line

  30. Preprocessor Directive • A line of code that begins with the # symbol.   • Are processed by preprocessor (which is usually bundled into the compiler) before compilation. • Are not executable code lines but instructions to the compiler. • Each header file stores functions that are related to a particular application. • The directive #include <iostream> tells the preprocessor to include the contents of the file iostream.h, which includes input-output operations (such as printing to the screen). 

  31. Function Main Function Every C++ program contains one or more functions, one of which must be named main. Every C++ program has a main function. A function is a block of code that carries out a specific task. The word main is followed in the code by a pair of parentheses ( ).

  32. Function Braces Right after these parentheses we can find the body of the main function enclosed in braces { }. What is contained within these braces is what the function does when it is executed. Braces used to mark the beginning and end of blocks of code. The open braces ({ ) are place in the beginning of code after the main functions and close braces ( }) are used to show closing of code. The code after the ( }) will not be read/evaluate by compiler

  33. Function Statement • A function consists of a sequence of statements that perform the work of the function. • It consists of instructions or command which make the program work. • Each statement in C++ ends with a semicolon (;). • There are 3 type of statement : • Input statement- cin>>statement; • Output statement-cout<<“statement”; • Operation statement-mathematical operation

  34. Problem Solving Phases • To be a good programmer, you must be a good problem solver. • To be a good problem solver, you must understand a problem in a methodical way, from initial inspection and definition to final solution.

  35. Problem Solving Phases Program Development Life Cycle Creating new program is called program development The process associated with creating successful applications programs is called the Program Development Life Cycle (PDLC). There are 5 steps to Program Development Life Cycle:

  36. Problem Solving Phases Phase 1: Analysis • Done by reviewing the program specifications. • Eliminate ambiguities in the problem statement. • Other criteria must be identified especially the data that will be used as input, process involve and output that will be produced. • Indicating what the new system should do. • In this step, the objectives, outputs, inputs, and processing requirements are determined. • The program objectives are the problems that you are trying to solve.

  37. Problem Solving Phases Phase 1: Analysis Example of Problem Solving Exercise • Write a program to calculate the bmi of a user Objective : - To calculate the bmi of a user Output : - bmi Input : - weight , height Process : - Declare  double bmi, weight, height - Calculate  bmi= weight/pow(height,2)

  38. Problem Solving Phases Phase 2: Design Develop a series of steps with a logical order which, when applied would produce the output of the problem. Good program design is very important in order to make the development process run smoothly, as well as to make future revisions easier. In program design step, a solution is created using structured programming techniques such as top-down approach and algorithm which consist of pseudocode and flowchart.

  39. Problem Solving Phases Phase 2: Design Algorithm

  40. Problem Solving Phases Phase 2: Design What is Algorithm? • A step-by-step problem solving process in which a solution is arrived at a finite amount of time. • A sequence of a finite number of steps arranged in a specific logical order which when executed will produce the solution for that problem. • An algorithm must satisfy some requirements which are: • Unambiguousness (clear) • Generality (unspecific) • Correctness • Finiteness (limitation)

  41. Problem Solving Phases Phase 2: Design

  42. Problem Solving Phases Phase 2: Design Algorithm – Pseudocode • Is a semiformal, English like language with a limited vocabulary that can be used to design and describe algorithms. • Each pseudo code statement includes keywords that describe operations and some appropriate English like description of operands. • Each pseudo code statement should be written on a separate line.

  43. Problem Solving Phases Phase 2: Design Algorithm – Pseudocode • The statements that make up a sequence control structure should begin with unambiguous words such as compute, set and initialize. • For the selection control structure use an if-else statement. • For repetition control structure use the for /while /do..while statement and indent the loop body. • All words in a pseudo code statement must be unambiguous and as easy as possible for nonprogrammers to understand.

  44. Problem Solving Phases Phase 2: Design Algorithm – Pseudocode BEGIN DECLARE double bmi, weight, height READ weight, height CALCULATE bmi=weight/pow(height,2) DISPLAY bmi • Example:(Sequential Control Structure) • calculate the bmi of a user

  45. Problem Solving Phases Phase 2: Design Algorithm – Pseudocode BEGIN DECLARE intnum GET num IF (num>0) DISPLAY positive number ELSE DISPLAY negative number END • Example: (Selection Control Structure) • Identify whether a number is a positive or negative number

  46. Problem Solving Phases Phase 2: Design Algorithm – Pseudocode BEGIN DECLARE int num, n, total INITIALIZE total=0, n=1 WHILE (n<=3) GET num; total=total+num; n++; DISPLAY total END • Example: (Repetition Control Structure) • Get three numbers and find the total of the three numbers

  47. Problem Solving Phases Phase 2: Design Algorithm – Flowchart • A graphic presentation of the detailed logical sequence of steps needed to solve programming problems. • Uses geometric symbols and familiar relational operators to provide a graphic display of the sequence of steps involved in a program. • The steps in a flowchart follow each other in the same logical sequence as their corresponding program statements will follow in a program. • Different symbols are used to represent different actions, such as start/stop, decision, input/output, processing, and looping symbols.

  48. Problem Solving Phases Phase 2: Design Algorithm – Flowchart

  49. Problem Solving Phases Phase 2: Design Algorithm – Flow Chart Example: Sequential Control Structure Calculate the bmi of a user

More Related