Скачать презентацию Computer Programming for Business gkamau kabarak ac ke Kabarak Скачать презентацию Computer Programming for Business gkamau kabarak ac ke Kabarak

3d315b667c61f02463e7a4c1f20976a2.ppt

  • Количество слайдов: 58

Computer Programming for Business gkamau@kabarak. ac. ke, Kabarak University Business School Computer Programming for Business [email protected] ac. ke, Kabarak University Business School

Computer Systems: Hardware and Software Computer Systems Consist of Similar Hardware Devices and Components Computer Systems: Hardware and Software Computer Systems Consist of Similar Hardware Devices and Components [email protected] ac. ke, Kabarak University Business School Chapter 2, Slide 7 Starting Out with Visual Basic 3 rd Edition

Computer Hardware § Refers to the physical components § Not one device but a Computer Hardware § Refers to the physical components § Not one device but a system of many devices § Major types of components include: • • • Central Processing Unit (CPU) Main memory Secondary storage devices Input devices Output devices [email protected] ac. ke, Kabarak University Business School

Organization of a Computer System Input Device Central Processing Unit Main Memory Output Device Organization of a Computer System Input Device Central Processing Unit Main Memory Output Device Secondary Storage [email protected] ac. ke, Kabarak University Business School

The CPU § Fetches instructions from main memory § Carries out the operations commanded The CPU § Fetches instructions from main memory § Carries out the operations commanded by the instructions § Each instruction produces some outcome § A program is an entire sequence of instructions § Instructions are stored as binary numbers § Binary number - a sequence of 1’s and 0’s [email protected] ac. ke, Kabarak University Business School

Main Memory § Commonly known as random access memory, or just RAM § Holds Main Memory § Commonly known as random access memory, or just RAM § Holds instructions and data needed for programs that are currently running § RAM is usually a volatile type of memory § Contents of RAM are lost when power is turned off [email protected] ac. ke, Kabarak University Business School

Secondary Storage § A nonvolatile storage medium § Contents retained while power is off Secondary Storage § A nonvolatile storage medium § Contents retained while power is off § Hard disk drives are most common • Records data magnetically on a circular disk • Provides fast access to large amounts of data § Optical devices store data on CD’s as pits § USB (Universal Serial Bus) flash or jump memory devices • High capacity device plugs into USB port • Portable, reliable, and fits easily in a pocket [email protected] ac. ke, Kabarak University Business School

Input Devices § Any type of device that provides data to a computer from Input Devices § Any type of device that provides data to a computer from the outside world § For example: • Keyboard • Mouse • Scanner [email protected] ac. ke, Kabarak University Business School

Output Devices § Any type of device that provides data from a computer to Output Devices § Any type of device that provides data from a computer to the outside world § Examples of output data: • A printed report • An image such as a picture • A sound § Common output devices include: • Monitor (display screen) • Printer [email protected] ac. ke, Kabarak University Business School

Software § The programs that run on a computer § Two major categories • Software § The programs that run on a computer § Two major categories • Operating systems (OS) ◦ Controls the processes within the computer ◦ Manages the computer's hardware devices • Application Software ◦ Solve problems or perform tasks needed by users ◦ Examples include word processing, spreadsheets, powerpoint, games, Internet browsers, playing music (MP 3), Visual Basic etc. ◦ Each program is referred to as an application ◦ This book develops applications in Visual Basic [email protected] ac. ke, Kabarak University Business School

1. 2 Programs and Programming Languages A Program: Is a set of instructions a 1. 2 Programs and Programming Languages A Program: Is a set of instructions a computer follows in order to perform a task A Programming Language: Is a special, high level language used to write computer programs [email protected] ac. ke, Kabarak University Business School Chapter 2, Slide 16 Starting Out with Visual Basic 3 rd Edition

What Is a Program? § Computers can only follow instructions § A computer program What Is a Program? § Computers can only follow instructions § A computer program is a set of instructions on how to solve a problem or perform a task § In order for a computer to compute someone’s gross pay, we must tell it to perform the steps on the following slide [email protected] ac. ke, Kabarak University Business School

Computer Programming Langauges • Low level languages (Machine languages & Assembly languages) • High Computer Programming Langauges • Low level languages (Machine languages & Assembly languages) • High level languages (4 th Generation languages, Natural languages, Object oriented and event driven languages) [email protected] ac. ke, Kabarak University Business School Chapter 2, Slide 18 Starting Out with Visual Basic 3 rd Edition

What is a program? § The steps in our algorithm must be stated in What is a program? § The steps in our algorithm must be stated in a form that the computer can understand § The CPU processes instructions as a series of 1’s and 0’s called machine language § This is a very tedious format for people § Instead, programming languages allow us to use words instead of numbers § Software converts the programming language statements to machine language [email protected] ac. ke, Kabarak University Business School

Low Level Language gkamau@kabarak. ac. ke, Kabarak University Business School Low Level Language [email protected] ac. ke, Kabarak University Business School

Machine Code § Computers “speak” in ones and zeros. Ex: 0 or 1 = Machine Code § Computers “speak” in ones and zeros. Ex: 0 or 1 = bit 01011011 = Byte § Machine Code is the Low Level Language that computers directly use. § It is written in the ones and zeros that computers “understand. ” Ex: 0010000000101100 has a specific meaning to specific computer hardware. Low Level Language [email protected] ac. ke, Kabarak University Business School

Assembly Language § Assembly Language substitutes ones and zeros with symbols and abbreviations. Ex: Assembly Language § Assembly Language substitutes ones and zeros with symbols and abbreviations. Ex: MOV ES, AH = Moves/copies the value of AH to ES. § Makes programming easier. § When finished, Assembly Language is converted to Machine Code (ones and zeros) for the computer to use. Low Level Language [email protected] ac. ke, Kabarak University Business School

Advantages/Disadvantages § Advantages of Low Level Language • Very efficient • Very versatile § Advantages/Disadvantages § Advantages of Low Level Language • Very efficient • Very versatile § Disadvantages of Low Level Languages • Time consuming, meticulous work • Error prone Low Level Language [email protected] ac. ke, Kabarak University Business School

High Level Language gkamau@kabarak. ac. ke, Kabarak University Business School High Level Language [email protected] ac. ke, Kabarak University Business School

High Level Language The language is used to solve problems. • It made problem High Level Language The language is used to solve problems. • It made problem solution easier and less error prone. • Problem oriented language are Pascal, Cobol, and Fortran. • Object oriented language are Java, and C & C++ High Level Language [email protected] ac. ke, Kabarak University Business School

What is Structured Programming? (Also known as Modular Programming) • It’s a logical structure What is Structured Programming? (Also known as Modular Programming) • It’s a logical structure of a program that makes writing code more efficient and simpler to modify. • Structured programming is easier to fix/ modify as well as work faster when trying to solve a problem. • An advantage of using structured design is the capability to reduce the use of the GOTO statement. (Although some structured program languages do support the GOTO statement. ) [email protected] ac. ke, Kabarak University Business School Chapter 2, Slide 26 Starting Out with Visual Basic 3 rd Edition

3 Building Blocks of the Composition of Structured Programming 1. Concatenation • Creating fundamental 3 Building Blocks of the Composition of Structured Programming 1. Concatenation • Creating fundamental statements that follow a logical sequence in order to be executed. • • Each statement or command must logically flow into the next without causing unwanted activities or executions. Concatenation is also a process of combining two character strings, or setting them equal to one another. Structured Programming [email protected] ac. ke, Kabarak University Business School

3 Building Blocks of the Composition of Structured Programming (Cont. ) 2. Selection • 3 Building Blocks of the Composition of Structured Programming (Cont. ) 2. Selection • A control structure that permits a variety of statements to execute, based on the condition of the program. • • Selection statements contain keywords that assist to categorize the order as a logical executable. Some examples of selection declarations: • “if” statements • “if-else” statements • “then” statements • “endif” statements • “switch” statements Structured Programming [email protected] ac. ke, Kabarak University Business School

3 Building Blocks of the Composition of Structured Programming (Cont. ) 3. Repetition • 3 Building Blocks of the Composition of Structured Programming (Cont. ) 3. Repetition • A statement is performed and remains active until the program reaches a point where another operation is applied. • In repetition, an action is used called a ‘loop”. • A loop is a continuous instruction implemented until a • certain condition is met. Examples of repetition keywords are: • “repeat” statement • “for” statement • “do” statement • “while” statement • “do-while statement • “do-until” statement • Structured Programming [email protected] ac. ke, Kabarak University Business School

Additional Structured Programming Information • • • Most types of structured programs begin with Additional Structured Programming Information • • • Most types of structured programs begin with a distinct entry, but allow more than one outlet for the program. Certain types of structured programming will permit components to interact with one another in the overall structure of the program. Each module in structured programming characterizes a different processing task. Structured Programming [email protected] ac. ke, Kabarak University Business School

Object-Oriented Programming gkamau@kabarak. ac. ke, Kabarak University Business School Object-Oriented Programming [email protected] ac. ke, Kabarak University Business School

Why OOP? § Early Programming techniques required code and data to be kept separate Why OOP? § Early Programming techniques required code and data to be kept separate from each other. § Problems arose when the code or data was inevitably changed. § Because of this programmers decided to place the code and data in a single location called an object. [email protected] ac. ke, Kabarak University Business School

The History of OOP § Object-oriented programming began with Simula, a programming language developed The History of OOP § Object-oriented programming began with Simula, a programming language developed from 1962 to 1967 by Ole-Johan Dahl and Kristen Nygaard at the Norwegian Computing Center in Oslo, Norway. § In the early 1970 s Alan Kay developed Smalltalk, an OOP language that took advantage of graphic user interfaces and led to the development of Mac and Windows operating systems. § The most popular OOP language is C++, developed by Bjarne Stroustrup. [email protected] ac. ke, Kabarak University Business School

Common Programming Languages § § BASIC FORTRAN COBOL Pascal § § C C++ C# Common Programming Languages § § BASIC FORTRAN COBOL Pascal § § C C++ C# Java § Visual Basic is not just a programming language § It’s a programming environment with tools to: • Create screen elements or objects • Write programming language statements [email protected] ac. ke, Kabarak University Business School

Computing Gross Pay § § § § Display message: Computing Gross Pay § § § § Display message: "How many hours did you work? " Allow user to enter number of hours worked Store the number the user enters in memory Display message: "How much are you paid per hour? " Allow the user to enter an hourly pay rate Store the number the user enters in memory Multiply hours worked by pay rate and store the result in memory Display a message with the result of the previous step This well-defined, ordered set of steps for solving a problem is called an algorithm [email protected] ac. ke, Kabarak University Business School

Methods of Programming § Procedural • Constructed as a set of procedures (operational, functional Methods of Programming § Procedural • Constructed as a set of procedures (operational, functional units) • Each procedure is a set of instructions • The Gross Pay computation is a procedure § Object-Oriented • Uses real-world objects such as students, transcripts, and courses • Objects have data elements called attributes • Objects also perform actions [email protected] ac. ke, Kabarak University Business School

Example of an Object § This is a Visual Basic GUI object called a Example of an Object § This is a Visual Basic GUI object called a form § Contains data and actions § Data, such as Hourly Pay Rate, is a text property that determines the appearance of form objects § Actions, such as Calculate Gross Pay, is a method that determines how the form reacts § A form is an object that contains other objects such as buttons, text boxes, and labels [email protected] ac. ke, Kabarak University Business School

Example of an Object § Form elements are objects called controls § This form Example of an Object § Form elements are objects called controls § This form has: • Two Text. Box controls • Four Label controls • Two Button controls § The value displayed by a control is held in the text property of the control § Left button text property is Calculate Gross Pay § Buttons have methods attached to click events [email protected] ac. ke, Kabarak University Business School

Event Driven Programming: Events § The GUI environment is event-driven § An event is Event Driven Programming: Events § The GUI environment is event-driven § An event is an action that takes place within a program • Clicking a button (a Click event) • Keying in a Text. Box (a Text. Changed event) § Visual Basic controls are capable of detecting many, many events § A program can respond to an event if the programmer writes an event procedure [email protected] ac. ke, Kabarak University Business School

Chapter 5: Introduction to Basic Programming in Visual Basic As a Visual Basic Programmer, Chapter 5: Introduction to Basic Programming in Visual Basic As a Visual Basic Programmer, you must design and create the two major components of an application: (i) The GUI elements (forms and other controls) and (ii) the programming statements that respond to and/or perform actions (event procedures) [email protected] ac. ke, Kabarak University Business School

Visual Basic Controls § As a Windows user you’re already familiar with many Visual Visual Basic Controls § As a Windows user you’re already familiar with many Visual Basic controls: ◦ ◦ Label - displays text the user cannot change Text. Box - allows the user to enter text Button – performs an action when clicked Radio. Button - A round button that is selected or deselected with a mouse click ◦ Check. Box – A box that is checked or unchecked with a mouse click ◦ Form - A window that contains these controls § Tutorial 1 -3 demonstrates these controls [email protected] ac. ke, Kabarak University Business School

Name Property § § All controls have properties Each property has a value (or Name Property § § All controls have properties Each property has a value (or values) Not all properties deal with appearance The name property establishes a means for the program to refer to that control § Controls are assigned relatively meaningless names when created § Programmers usually change these names to something more meaningful [email protected] ac. ke, Kabarak University Business School

Examples of Names § The label controls use the default names (Label 1, etc. Examples of Names § The label controls use the default names (Label 1, etc. ) § Text boxes, buttons, and the Gross Pay label play an active role in the program and have been changed Label 1 Label 2 txt. Hours. Worked txt. Pay. Rate Label 3 lbl. Gross. Pay btn. Calc. Gross. Pay btn. Close [email protected] ac. ke, Kabarak University Business School

Naming Conventions § Control names must start with a letter § Remaining characters may Naming Conventions § Control names must start with a letter § Remaining characters may be letters, digits, or underscore § 1 st 3 lowercase letters indicate the type of control • txt… • lbl… • btn… for Text Boxes for Labels for Buttons § After that, capitalize the first letter of each word § txt. Hours. Worked is clearer than txthoursworked [email protected] ac. ke, Kabarak University Business School

Event Handler – Compute Gross Pay Private Sub btn. Calc. Gross. Pay_Click(By. Val sender Event Handler – Compute Gross Pay Private Sub btn. Calc. Gross. Pay_Click(By. Val sender As System. Object, _ By. Val e As System. Event. Args) Handles btn. Calc. Gross. Pay. Click ‘Define a variable to hold the gross pay. Dim sng. Gross. Pay As Single ‘Convert the values in the text boxes to numbers, ‘and calculate the gross pay. sng. Gross. Pay = CSng(txt. Hours. Worked. Text) * CSng(txt. Pay. Rate. Text) ‘Format the gross pay for currency display and ‘assign it to the Text property of a label. lbl. Gross. Pay. Text = Format. Currency(sng. Gross. Pay) End Sub [email protected] ac. ke, Kabarak University Business School

Event Handler - Close Private Sub btn. Close_Click(By. Val sender As System. Object, _ Event Handler - Close Private Sub btn. Close_Click(By. Val sender As System. Object, _ By. Val e As System. Event. Args) Handles btn. Close. Click ‘End the program by closing its window. Me. Close() End Sub [email protected] ac. ke, Kabarak University Business School

Language Elements § Keywords: Words with special meaning to Visual Basic (e. g. , Language Elements § Keywords: Words with special meaning to Visual Basic (e. g. , Private, Sub) § Programmer-defined-names: Names created by the programmer (e. g. , sng. Gross. Pay, btn. Close) § Operators: Special symbols to perform common operations (e. g. , +, -, *, and /) § Remarks: Comments inserted by the programmer – these are ignored when the program runs (e. g. , any text preceded by a single quote) [email protected] ac. ke, Kabarak University Business School

Language Elements: Syntax § Syntax defines the correct use of key words, operators, & Language Elements: Syntax § Syntax defines the correct use of key words, operators, & programmer-defined names § Similar to the syntax (rules) of English that defines correct use of nouns, verbs, etc. § A program that violates the rules of syntax will not run until corrected [email protected] ac. ke, Kabarak University Business School

The Programming Process Consists of Several Steps, Which Include Design, Creation or Coding, Testing, The Programming Process Consists of Several Steps, Which Include Design, Creation or Coding, Testing, and Debugging Activities [email protected] ac. ke, Kabarak University Business School

Step 1: Developing an Application § Clearly define what the program is to do Step 1: Developing an Application § Clearly define what the program is to do § For example, the Wage Calculator program: • Purpose: To calculate the user’s gross pay • Input: Number of hours worked, hourly pay rate • Process: Multiply number of hours worked by hourly pay rate (result is the user’s gross pay) • Output: Display a message indicating the user’s gross pay [email protected] ac. ke, Kabarak University Business School

Step 2: Developing an Application § Visualize the application running on the computer and Step 2: Developing an Application § Visualize the application running on the computer and design its user interface [email protected] ac. ke, Kabarak University Business School

Step 3: Developing an Application § Make a list of the controls needed Type Step 3: Developing an Application § Make a list of the controls needed Type Text. Box Label Name txt. Hours. Worked txt. Pay. Rate lbl. Gross. Pay Button btn. Calc. Gross. Pay Button btn. Close Description Allows the user to enter the number of hours worked. Allows the user to enter the hourly pay rate Displays the gross pay, after the btn. Calc. Gross. Pay button has been clicked When clicked, multiplies the number of hours worked by the hourly pay rate When clicked, terminates the application Label Form (default) Description for Number of Hours Worked Text. Box Description for Hourly Pay Rate Text. Box Description for Gross Pay Earned Label A form to hold these controls [email protected] ac. ke, Kabarak University Business School

Step 4: Developing an Application § Define values for each control's relevant properties: Control Step 4: Developing an Application § Define values for each control's relevant properties: Control Type Form Label Text. Box Button Control Name (Default) lbl. Gross. Pay txt. Hours. Worked txt. Pay. Rate btn. Calc. Gross. Pay btn. Close Text "Wage Calculator" "Number of Hours Worked" "Hourly Pay Rate" "Gross Pay Earned" "$0. 00" "" "" "Calculate Gross Pay" "Close" [email protected] ac. ke, Kabarak University Business School

Step 5: Developing an Application § List the methods needed for each control: Method Step 5: Developing an Application § List the methods needed for each control: Method btn. Calc. Gross. Pay_Click Description Multiplies hours worked by hourly pay rate These values are entered into the txt. Hours. Worked and txt. Pay. Rate Text. Boxes Result is stored in lbl. Gross. Pay Text property btn. Close_Click Terminates the application [email protected] ac. ke, Kabarak University Business School

Step 6: Developing an Application § Create pseudocode or a flowchart of each method: Step 6: Developing an Application § Create pseudocode or a flowchart of each method: • Pseudocode is an English-like description in programming language terms Store Hours Worked x Hourly Pay Rate in sng. Gross. Pay. Store the value of sng. Gross. Pay in lbl. Gross. Pay. Text. • A flowchart is a diagram that uses boxes and other symbols to represent each step Start Multiply hours worked by hourly payrate. Store result in sng. Gross. Pay. Copy value in sng. Gross. Pay to lbl. Gross. Pay text property [email protected] ac. ke, Kabarak University Business School End

Step 7: Developing an Application § Check the code for errors: • Read the Step 7: Developing an Application § Check the code for errors: • Read the flowchart and/or pseudocode • Step through each operation as though you are the computer • Use a piece of paper to jot down the values of variables and properties as they change • Verify that the expected results are achieved [email protected] ac. ke, Kabarak University Business School

Step 8: Developing an Application § Use Visual Basic to create the forms and Step 8: Developing an Application § Use Visual Basic to create the forms and other controls identified in step 3 • This is the first use of Visual Basic, all of the previous steps have just been on paper • In this step you develop the portion of the application the user will see [email protected] ac. ke, Kabarak University Business School

Step 9: Developing an Application § Use Visual Basic to write the code for Step 9: Developing an Application § Use Visual Basic to write the code for the event procedures and other methods created in step 6 • This is the second step on the computer • In this step you develop the methods behind the click event for each button • Unlike the form developed on step 8, this portion of the application is invisible to the user [email protected] ac. ke, Kabarak University Business School

Step 10: Developing an Application § Attempt to run the application - find syntax Step 10: Developing an Application § Attempt to run the application - find syntax errors • Correct any syntax errors found • Syntax errors are the incorrect use of an element of the programming language • Repeat this step as many times as needed • All syntax errors must be removed before Visual Basic will create a program that actually runs [email protected] ac. ke, Kabarak University Business School

Step 11: Developing an Application § Run the application using test data as input Step 11: Developing an Application § Run the application using test data as input • • • Run the program with a variety of test data Check the results to be sure that they are correct Incorrect results are referred to as a runtime error Correct any runtime errors found Repeat this step as many times as necessary [email protected] ac. ke, Kabarak University Business School

1. 5 Visual Studio and the Visual Basic Environment Visual Studio Consists of Tools 1. 5 Visual Studio and the Visual Basic Environment Visual Studio Consists of Tools That You Use to Build Visual Basic Applications [email protected] ac. ke, Kabarak University Business School

The Visual Studio IDE § Visual Studio is an integrated development environment, often abbreviated The Visual Studio IDE § Visual Studio is an integrated development environment, often abbreviated as IDE § Provides everything needed to create, test, and debug software including: • The Visual Basic language • Form design tools to create the user interface • Debugging tools to help find and correct programming errors § Visual Studio supports other languages beside Visual Basic such as C++ and C# [email protected] ac. ke, Kabarak University Business School

The Visual Basic Environment § Tutorial 1 -4 introduces elements of the IDE: • The Visual Basic Environment § Tutorial 1 -4 introduces elements of the IDE: • • Customizing the IDE Design window – a place to design and create a form Solution Explorer window – shows files in the solution Properties window – modify properties of an object Dynamic Help window – a handy reference tool Toolbar – contains icons for frequently used functions Toolbox window – objects used in form design Tooltips – a short description of button’s purpose [email protected] ac. ke, Kabarak University Business School