1 / 48

Chapter 4 Programming Concepts

Chapter 4 Programming Concepts. Dept. of Computer Engineering Khon Kaen University. Major Concepts. Computer Software Processing a high-level language program The software development method Applying the software development method Professional ethics for computer programmers.

amiesner
Download Presentation

Chapter 4 Programming Concepts

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 4Programming Concepts Dept. of Computer Engineering Khon Kaen University

  2. Major Concepts • Computer Software • Processing a high-level language program • The software development method • Applying the software development method • Professional ethics for computer programmers

  3. Computer Software • Two major categories of software • System software: operating systems • Example: Windows, Apple OS X, Unix • Application software • Example: Microsoft PowerPoint, Microsoft Word Processing

  4. Operating Systems • Communicating with the user • Managing allocation of resources • Collecting input from input devices • Conveying program output to output devices • Accessing data from secondary storage • Writing data to secondary storage

  5. Some Widely Used OSs • Command-Line Interface • Unix • MS-DOS • Linux • Graphical User Interface • Mac OS X • Windows 9x, NT, 2000, Me, XP • UNIX + X Windows System • Linux + X Windows System

  6. OSs: Command-Line Interface • This OS displays a brief message called prompt that indicates readiness to receive input. • The user then types a command at the keyboard • Then, the OS finds the executable program that corresponds to the command and then invoke the program

  7. MS-DOS Command Interface C:\>dir temp/w Volume in drive C has no label. Volume Serial Number is 8835-FDA8 Directory of C:\temp [.] [..] [C#] [DirectX9] [License] SSHSecureShellClient-3.2.2.exe 1 File(s) 6,070,272 bytes 5 Dir(s) 28,122,365,952 bytes free

  8. UNIX Command Interface gear.kku.ac.th:/home/krunapon/public_html %ls 168493 Kanda.htm index.html srProjs03.zip DotNET index-en.html pubs

  9. OSs: Graphical User Interface (GUI) • The GUI interface provides the user with a system of icons and menus • To issue commands • Users move the mouse cursor to point to the appropriate icon or menu selection • Users then click a button once or twice

  10. OSs: GUI (Cont.) • Icons are pictures that represent computer resources and files, such as printers, documents, and programs • You double-click an icon to choose (activate, launch) a program • The Windows OS offers two unique tools • Taskbar • Start button

  11. Icons Window control buttons Scroll box Program running in a window Dialog box Scroll bar Start button Start menu Task bar Desktop

  12. Application Software • A program used for a specific task such as word processing, accounting, or database management • Application software tells the computer how to accomplish tasks the user requires, such as creating a document • Programmers use programming languages to write most application software

  13. Programming Languages • Commands or lists of instructions for a computer to execute • Types of programming languages • Machine language: binary numbers directly understood by a computer • Assembly language: in the form of mnemonic codes and variable names. • converted to machine codes by the assembler and linker

  14. Programming Languages (Cont.) • Types of programming (Cont.) • High-level language • A programming language that combines algebraic expressions and English words • Converted to machine codes by a compiler or an interpreter or a compiler • Examples: BASIC, C, C++, COBOL, FORTRAN, Java, Lisp, Pascal

  15. Assembler & Linker

  16. Machine and Assembly Languages A = A + B

  17. Object-Oriented Programming (OOP) • Programs are organized as cooperative collections of objects • What is an Object? • An object is a software bundle of related properties • Software objects are used to model real-world objects you find in everyday life • Objects communicate with one another by exchanging messages

  18. OOP (Cont.) • Objects that share common properties can be grouped into classes • Classes can be organized into a hierarchy of subclasses and superclasses • A class inherits state and behavior from its superclass. • OOP languages • C++, Java, C#

  19. Classes and Objects

  20. A Class Hierarchy Vehicle has: driver’s seat four wheels Automobile has: driver’s seat four wheels passengers’ seats Truck has: driver’s seat four wheels Truck bed Sports car has: driver’s seat four wheels rear spoiler

  21. Processing a High-Level Language Programming • A source file is a file program written in a high-level language • Syntax is the grammar rules when writing a source file • Compiler translates the high-level language program (a source file) to file containing the machine language • An object file is an output of the compiler.

  22. Executing a Program • To execute a program, the CPU • Must load each program instruction in memory • Send out the command signals required to carry out the instruction • The program can have both input data and program output

  23. Input Data • Input data is the data that is the input of the program • During execution, data can be entered into memory and manipulated in some specific way. • Special program instructions are used for accepting the input data from the users and this input data then is loaded into memory

  24. Program Output • After input data has been processed, • Special program instructions for displaying or printing values in memory can be executed to • Display the program results on a computer monitor • Save the program results in a file

  25. An Execution of a Program

  26. Major Concepts • Computer Software • Processing a high-level language program • The software development method • Applying the software development method • Professional ethics for computer programmers

  27. Software Development Method • 1. Specify the problem • 2. Analyze the problem • 3. Design the algorithm to solve the problem • 4. Implement the algorithm • 5. Test and verify the completed program • 6. Maintain and update the program

  28. SW Development (Cont.) • 1. Specifying the problem requirement • State the problem clearly and unambiguously • Have a clear understanding of what is required for its solution • 2. Analyzing the problem • Identifying the problem inputs and outputs • Identifying any additional requirements or constraints on the solution • Develop a list of problem variables and their relationships

  29. SW Development (Cont.) • Daily problem: I want to know the total cost of 5 kilograms of mangoes that are 30 baht per kilogram • Step 1. Specify the problem requirement • Translate the daily problem into the computer programming problem Compute and display the total cost of mangoes given the number of kilograms of mangoes purchased and the cost per kilogram of mangoes.

  30. SW Development (Cont.) • Step 2. Analyze the problem • Underline phases in the problem statement that identify the inputs and output Compute and display the total cost of mangoes given the number of kilograms of mangoes purchased and the cost per kilogram of mangoes.

  31. SW Development (Cont.) • Step 2. Analyzing the problem Problem Inputs • Quantity of mangoes purchases (in kilograms) • Cost per kilogram of mangoes (in Baht per kilogram) Problem Outputs • Total cost of mangoes (in Baht)

  32. SW Development (Cont.) • Step 2. Analyzing the problem • Develop a list of formulas that specify relationships between the inputs and the outputs • Total costs of mangoes = Cost per kilogram x the number of kilograms of mangoes

  33. SW Development (Cont.) • Step 2. Analyzing the problem • Sometimes we may need to make certain assumptions or simplifications to derive these relationships • The process of modeling a problem by extracting the essential variables and their relationships is called abstraction

  34. SW Development (Cont.) • Step 3. Designing the algorithm to solve the problem • Develop a list of steps called algorithm to solve the problem • An algorithm is usually designed based on the divide and conquer approach or the top-down design approach

  35. Divide and Conquer • Divide the problem into the major steps or sub-problems that need to be solved • Conquer each sub-problem and then combine the solutions of sub-problems to form the solution of the original problem. This process is called algorithm refinement • Sub-problems are further divided until they are easily solved by program code

  36. SW Development (Cont.) • Step 3. Designing the algorithm • Algorithm of a Sample Problem • 1. Get the input data • 2. Perform the computations • 3. Display results • Then verify that the algorithm solves the problem as intended by desk-checking • Carefully perform each step (or its refinement) just as a computer would and verify that the algorithm works as expected

  37. SW Development (Cont.) • Step 4. Implementing the algorithm • Write the algorithm as a program coding • Convert each algorithm step into one or more statements in a programming language • Step 5. Test and verify the completed program • Compile and run the program • Test the program with different data sets • Ensure that the program works correctly for the given problem specification

  38. SW Development (Cont.) • Step 6. Maintain and update the program • Modify a program to remove previously undetected errors • Keep the program up-to-date as government regulations or company policies change • Coding Hints • Make very small additions/changes and test the partly finished code • Don’t write a complete program, and then expect it to work first time

  39. Applying the SW Development • Case study: Converting miles to kilometers Problem: Your summer survey job requires you to study some maps that give distances in kilometers and some that use miles. You and your coworkers prefer to deal in measurements. Instruction: Write a program that performs the necessary conversation

  40. Problem Analysis • Since you prefer to deal in metric measurements so you must convert distance measurements in miles to kilometers • Therefore, the problem input is distance in miles and the problem output is distance in kilometers

  41. Problem Analysis (Cont.) • To write the program, you need to know the relationship between miles and kilometers. • One mile is equal to 1.609 kilometers

  42. Problem Analysis (Cont.) • Data requirements • Problem input • Miles the distance in miles • Problem output • Kms the distance in kilometers • Relevant formula • 1 mile = 1.609 kilometers

  43. Algorithm Design • Steps in the algorithm • 1. Get the distance in miles • 2. Convert the distance to kilometers • 3. Display the distance in kilometers • Now decide whether any step of the algorithm needs further refinement

  44. Algorithm Design (Cont.) • Algorithm refinement • The distance in kilometers is 1.609 times the distance in miles • Algorithm with refinements • Step 1. Get the distance in miles • Step 2. Convert the distance in kilometers: • 2.1 The distance in kilometers is 1.609 times the distance in miles • Step 3. Display the distance in kilometers

  45. Algorithm Design (Cont.) • Desk-checking the algorithm • If step 1 gets a distance of 10.0 miles • Step 2.1 would convert it to 1.609x10.00 = 16.09 kilometers • And then step 3 should display number “16.09” as a program output

  46. Implementation // Miles.cpp // Converts distance in miles to kilometers. #include <iostream> // class for stream input/output using namespace std; // use the standard namespace int main() // start of main function { const float km_per_mile = 1.609; // 1.609 km in a mile float miles, // input: distance in miles kms; // output: distance in kilometers // Get the distance in miles. cout << "Enter the distance in miles: "; cin >> miles; // Convert the distance to kilometers. kms = km_per_mile * miles; // Display the distance in kilometers. cout << "The distance in kilometers is " << kms << endl; return 0; } Enter the distance in miles: 10.0 The distance in kilometers is 16.09

  47. Professional Ethics for Computer Programmers • Computer programmers and software engineers should follow certain standards of professional conduct: • Privacy and misuse of data • Computer hacking • Plagiarism and software piracy • Misuse of a computer resource

More Related