Slide 01


Published on

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

  • Be the first to like this

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

No notes for slide

Slide 01

  1. 1. Chapter 1: Introduction to C Page
  2. 2. 1.1 Introduction to Computers <ul><li>Overview of computer system : </li></ul>Page Computer System Software Hardware The physical equipments. E.g. keyboard, mouse, monitor, processor, memory, etc. Collection of programs that tell hardware how to perform tasks.
  3. 3. 1.1 Introduction to Computers <ul><li>2 categories of computer software : </li></ul>Page Computer System Software Hardware System Software Application Software Programs that manage computer resources. Programs that help users to solve their problems.
  4. 4. 1.1 Introduction to Computers <ul><li>System software and application software : </li></ul>Page Computer System Software Hardware System Software Application Software Operating System System Support Software System Development Software General-Purpose Software Application-Specific Software
  5. 5. Example of system software: <ul><li>UNIX, Linux, MS Windows, Mac OS, etc. </li></ul><ul><li>Disk defragmenter, screen saver, antivirus tool, etc. </li></ul><ul><li>Programs that creates programs. </li></ul><ul><li>MS Visual C++ 6.0, MS Visual Studio 2008, Java NetBeans, etc. </li></ul>Page Operating System System Support Software System Development Software
  6. 6. Example of application software: <ul><li>MS Word 2007, Windows Media Player, Window Live Messenger, etc. </li></ul><ul><li>LRT ticketing system, hotel reservation system, payroll system, etc. </li></ul>Page General-Purpose Software Application-Specific Software
  7. 7. 1.2 Computer Languages <ul><li>Program: A set of instructions that tell computer how to perform tasks. </li></ul><ul><li>We use a computer / programming language to write program. </li></ul><ul><li>Categories of computer languages: </li></ul><ul><ul><li>Machine languages </li></ul></ul><ul><ul><li>Symbolic languages </li></ul></ul><ul><ul><li>High-level languages </li></ul></ul>Page
  8. 8. Evolution of computer languages: Page
  9. 9. Program in machine language: Page
  10. 10. Machine Language <ul><li>Use binary codes ( 0 s and 1 s). </li></ul><ul><li>The only language computer can understand. </li></ul><ul><li>Platform-dependent. </li></ul><ul><li>Very hard to program. </li></ul>Page 10010010 00110101 10101110
  11. 11. Program in symbolic language: Page
  12. 12. Symbolic Language <ul><li>a.k.a. assembly language . </li></ul><ul><li>Use symbolic codes, mnemonics and meaningful abbreviations. </li></ul><ul><li>Platform-dependent. </li></ul><ul><li>Easier to program. </li></ul><ul><li>E.g. MASM 6.15, Turbo Assembler, etc. </li></ul>Page
  13. 13. Wait a minute… <ul><li>Since computers only understand machine language. Then, how computers recognize other computer languages such as symbolic language? </li></ul>Page ?
  14. 14. Translate it!!! <ul><li>Programmer writes a program using preferable programming language. Finally, translate it into machine language by using a translator and the program is ready to run!!! </li></ul>Page Source Program Translator 10001011 11001101 00110011 Machine Language
  15. 15. Assembler <ul><li>Symbolic language has to be translated to machine language before it can be run. </li></ul><ul><li>Translator: assembler . </li></ul>Page Symbolic Language Machine Language Assembler Source Program Translator 0s and 1s
  16. 16. Example of high-level language: Page
  17. 17. Page
  18. 18. High-Level Language <ul><li>a.k.a procedural language . </li></ul><ul><li>Use English-like codes and mathematical operators. </li></ul><ul><li>Platform-independent. </li></ul><ul><li>Very easy to program. </li></ul><ul><li>E.g. C, Pascal, etc. </li></ul>Page
  19. 19. Compiler / interpreter <ul><li>High-level language has to be translated to machine language before it can be run. </li></ul><ul><li>Translator: compiler / interpreter. </li></ul>Page High-Level Language Machine Language Compiler / Interpreter Source Program Translator 0s and 1s
  20. 20. The Compilation Process <ul><li>Compiler converts source program into object program (machine language version). </li></ul><ul><li>If encounters error, program error listing is shown. </li></ul><ul><li>Object program is then loaded and run. </li></ul>Page Compiler Object Program Results Program Error Listing Data Source Program Machine Language Translator
  21. 21. 1.3 Introduction to C <ul><li>C is a high-level language. </li></ul><ul><li>For systems and applications programming. </li></ul><ul><li>Portable / platform-independent: run at other platforms with no or little alterations. </li></ul>Page
  22. 22. Exercise 1.1 <ul><li>By following the instructions giving by your lecturer, write, compile and run your first C program – the Hello World program! </li></ul>Page #include <stdio.h> int main(void) { printf(&quot;Hello World! &quot;); return 0; }
  23. 23. Exercise 1.2 <ul><li>Create a new program that display the following lyrics on screen: </li></ul>Page Welcome, welcome all of you Glad you are with us Shake hands, no need to be blue Welcome to you!
  24. 24. 1.4 Program Development <ul><li>To develop a program, programmer must complete the following steps: </li></ul><ul><ul><li>Understand the problem </li></ul></ul><ul><ul><li>Develop a solution </li></ul></ul><ul><ul><li>Write the program </li></ul></ul><ul><ul><li>Test the program </li></ul></ul>Page
  25. 25. <ul><li>Take time to understand the problem and design the solution, before you code the actual program. </li></ul><ul><li>This reduce the chances of misunderstanding and errors. Hence, the final program can be implemented in a shorter time and with a better quality. </li></ul>Page An old programming proverb: Resist the temptation to code!!!
  26. 26. Program Development <ul><li>Understand the problem </li></ul><ul><li>Carefully study the user requirements. </li></ul><ul><li>Understand what he wants the program to do and what kind of output he wants to have. </li></ul>Page Develop a solution Understand the problem Write the program Test the program
  27. 27. Program Development <ul><li>Develop a solution </li></ul><ul><li>Design the logic of the program by using tools such as: </li></ul><ul><ul><li>Structure chart </li></ul></ul><ul><ul><li>Pseudocode </li></ul></ul><ul><ul><li>Flowchart </li></ul></ul>Page Develop a solution Understand the problem Write the program Test the program We will talk about them later.
  28. 28. Program Development <ul><li>Write the program </li></ul><ul><li>Code the actual program by using the preferable programming language. </li></ul>Page Develop a solution Understand the problem Write the program Test the program
  29. 29. Program Development <ul><li>Test the program </li></ul><ul><li>Run and test the program to ensure it is free of logical errors. </li></ul>Page Develop a solution Understand the problem Write the program Test the program
  30. 30. Example 1.1 <ul><li>You would like to install new floor covering in your home and would like to calculate the cost that would be involved. Your plan is as follows: </li></ul><ul><ul><li>Only the living space will be carpeted. The garage and closets will not be considered. </li></ul></ul><ul><ul><li>The kitchen and bathrooms will be covered with linoleum. The rest of the house is to be carpeted. </li></ul></ul>Page
  31. 31. <ul><li>You need a computer program to compute the flooring cost. How should you approach this problem? </li></ul>Page
  32. 32. <ul><li>A big programming problem. </li></ul>Divide and Conquer!!! Page
  33. 33. <ul><li>Break down the task into a few big subtasks. </li></ul>Divide and Conquer!!! Page
  34. 34. <ul><li>Decompose each big subtask into smaller subtasks. </li></ul>Divide and Conquer!!! Page
  35. 35. <ul><li>Further break down each smaller subtask into even smaller subtasks. </li></ul>Divide and Conquer!!! Page
  36. 36. <ul><li>Eventually the subtasks become so small that they are trivial to implement in C language. </li></ul>Divide and Conquer!!! Page
  37. 37. Divide and Conquer!!! <ul><li>a.k.a. stepwise refinement or top-down design . </li></ul>Page
  38. 38. Tool: Structure Chart <ul><li>A hierarchy chart that shows the functional flow through the program. </li></ul><ul><li>Shows how the program is broken into logical steps. Each step will be a separate module. </li></ul>Page
  39. 39. A structure chart: Page
  40. 40. Tool: Pseudocode <ul><li>Use English words to convey program logic. </li></ul><ul><li>Contains the logical steps / algorithms to accomplish the task. </li></ul>Page
  41. 41. A pseudocode: Page
  42. 42. Tool: Flowchart <ul><li>Use standard graphical symbols to represent the logical flow of data through a program. </li></ul><ul><li>[ show flowchart ] </li></ul>Page
  43. 43. Flowchart Symbols Page Input/Output Processing Module Decision Flowlines Terminal Off-page Connector On-page Connector
  44. 44. Example 1.2 <ul><li>Problem: Calculate the sum of 2 numbers. </li></ul><ul><li>Hint: The general algorithm for a programming problem is normally: </li></ul><ul><ul><li>Get the data </li></ul></ul><ul><ul><li>Perform the computations </li></ul></ul><ul><ul><li>Display the results </li></ul></ul>Page
  45. 45. Example 1.2: Structure chart Page Sum Two Numbers Get User Input Calculate Sum Display Sum
  46. 46. Example 1.2: Pseudocode Page START Prompt and read number1 Prompt and read number2 sum = number1 + number2 Display sum END
  47. 47. Example 1.2: Flowchart Page START END Read number1 Read number2 sum = number1 + number2 Display sum
  48. 48. Exercise 1.3 <ul><li>By using structure chart, pseudocode and flowchart, design the solution for a program that reads three (3) numbers from user, calculates their total and average, and displays the calculated total and average on the screen. </li></ul>Page