Chapter 1. Introduction to Programming and Visual Basic Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of

Similar documents
Chapter 1: Why Program? Computers and Programming. Why Program?

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

C H A P T E R 1. Introduction to Computers and Programming

Chapter 1: Why Program? Main Hardware Component Categories 8/23/2014. Main Hardware Component Categories: Why Program?

Departme and. Computer. CS Intro to. Science with. Objectives: The main. for a problem. of Programming. Syntax Set of rules Similar to.

Chapter 1: Introduction to Computers and Programming

CHAPTER 1: INTRODUCTION TO COMPUTERS AND PROGRAMMING. 1 Muhalim Mohamed Amin Faculty of

SCSP Programming Technique C

Week 0: Intro to Computers and Programming. 1.1 Why Program? 1.2 Computer Systems: Hardware and Software. Hardware Components

Chapter 2: Input, Processing, and Output

Introduction. Arizona State University 1

COMPUTER BASICS Processing/Storage

Review. Input, Processing and Output. Review. Review. Designing a Program. Typical Software Development cycle. Bonita Sharif

Using Visual Basic Studio 2008

Introduction to Computers

Introduction to Computers and Java

Fundamentals of Programming (Python) Basic Concepts. Ali Taheri Sharif University of Technology Spring 2018

Chapter 1 Introduction to Computers and Programming

Chapter 1: Introduction to Computers and Java

8/23/2014. Chapter Topics. Introduction. Java History. Why Program? Java Applications and Applets. Chapter 1: Introduction to Computers and Java

located at the top of this page. For instructions on how to use the Dropbox, read these stepby step

The Programming Process Summer 2010 Margaret Reid-Miller


Introduction to Computers and Java

CHAPTER 1 Introduction to Computers and Java

Lesson 1. Introduction to Programming OBJECTIVES

Introduction to Computers and Applications

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Computer Hardware. Java Software Solutions Lewis & Loftus. Key Hardware Components 12/17/2013

Chapter 1. Introduction to Computers and Programming. M hiwa ahmad aziz

Skill Area 336 Explain Essential Programming Concept. Programming Language 2 (PL2)

BITG 1113: Introduction To Computers And Programming Language LECTURE 1 LECTURE 1 1

AN INTRODUCTION TO THE COMPUTER

National 5 Computing Science Software Design & Development

Getting started 7. Setting properties 23

Getting started 7. Setting properties 23

Getting Started with TurningPoint

Computer Basics 1/24/13. Computer Organization. Computer systems consist of hardware and software.

Lab 4: Introduction to Programming

Address Bar. Application. The space provided on a web browser that shows the addresses of websites.

9/11/08 (c) 2008 Matthew J. Rutherford Class (c) 2008 Matthew J. Rutherford Class

SECTION 2 (Part B) Types And Components Of Computer Systems. Sophia Pratzioti

Computer Fundamentals

There are many types of computers, including:

Computer Basics 1/6/16. Computer Organization. Computer systems consist of hardware and software.

Introduction to Computers and Visual Basic.Net Pearson Education, Inc. All rights reserved.

Chapter 1 Lab Algorithms, Errors, and Testing

1) Which of the following is an example of a programming language? 1) A) Microsoft Word B) English C) HTML D) Java

15/09/15. Introduction to Computers & The Internet. Contents. Computer hardware and software. Input and output devices CPU. Memory.

Programming: detailed instructions which tell the computer hardware what to do aka software Computer Science: the study NOT of computers, but of what

4.03 IT PowerPoint. Objective 4.03 Understand Information Technology activities and careers.

Introduction to Software Development (ISD) David Weston and Igor Razgon

1) What is the first step of the system development life cycle (SDLC)? A) Design B) Analysis C) Problem and Opportunity Identification D) Development

central processing unit (CPU) software operating system (OS) input device output device

Chapter 1. Introduction to Computers and Java Objects. Background information. » important regardless of programming language. Introduction to Java

Chapter 2. Prepared By: Humeyra Saracoglu

Week One: Introduction A SHORT INTRODUCTION TO HARDWARE, SOFTWARE, AND ALGORITHM DEVELOPMENT

System Unit Components Chapter2

COMPUTER SYSTEMS. Section 1

Chapter 1 INTRODUCTION

An Overview of the Computer System. Kafui A. Prebbie 24

Chapter 1: An Overview of Computers and Programming Languages. Objectives. Objectives (cont d.) Introduction

Java and Software Design

Introduction to Computers and Java

CHAPTER INTRODUCTION. Final Draft Oct. 15, Slides by Donald W. Smith TechNeTrain.com. Copyright 2013 by John Wiley & Sons. All rights reserved.

Chapter Goals. Contents. 1.1 Computer Programs

Computer Principles and Components 1

Components of a personal computer

HANDOUT: COMPUTER PARTS

Sahalsoftware college. Welcome To understanding Basic Computer Concept

Computer Basics. Hardware. This class is designed to cover the following basics:

Elements of Computers and Programming Dr. William C. Bulko. What is a Computer?

Computer Basics. Dayton Metro Library

Parts of Computer hardware Software

4. Some computers may also be customised so that a program such as Word can be started using a keyboard command.

Exercise 2 : Complete each sentence or statement. 1. data consists of numbers that might be used in arithmetic operations.

Welcome Application. Introducing the Visual Studio.NET IDE. Objectives. Outline

ACS-1903 Basic program structure Feb 16, 2017

Types of Data. PE 231 Education Media AND Technology. Information. Assessment. Information Concepts

COP 1170 Introduction to Computer Programming using Visual Basic

Parts are adapted from Windows 98 by Mark Twain Media, Inc. A Computer System has Hardware and Software

HARDWARE. There are a number of factors that effect the speed of the processor. Explain how these factors affect the speed of the computer s CPU.

Windows 10 Automatic Backup

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

Chapter 4 The Components of the System Unit

Chapter. Focus of the Course. Object-Oriented Software Development. program design, implementation, and testing

Using Microsoft Word. Getting Started With Word. Exercise 1 Starting the Program

General Computing Concepts. Coding and Representation. General Computing Concepts. Computing Concepts: Review

Computer Organization

CSI31 Introduction to Computer Programming I. Dr. Sharon Persinger Fall

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Elementary Computing CSC M. Cheng, Computer Science 1

Introduction to Flowcharting

Computer Concepts and C Programming. Unit I 06CCP13

ICOM 4015: Advanced Programming

Download from Powered By JbigDeaL

Outline. Program development cycle. Algorithms development and representation. Examples.

Week 1 Introduction to Computer and Algorithm (Part1) UniMAP Sem II 11/12 DKT121: Basic Computer Programming 1

Zimmer CSCI /24/18. CHAPTER 1 Overview. COMPUTER Programmable devices that can store, retrieve, and process data.

Transcription:

Chapter 1 Introduction to Programming and Visual Basic Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Section 1.1 COMPUTER SYSTEMS: HARDWARE AND SOFTWARE Computer systems consist of similar hardware devices and hardware components. This section provides an overview of computer hardware and software organization. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Computer Hardware Refers to the physical components Not one device but a system of many devices Major types of components include: Central Processing Unit Main memory Secondary storage devices Input devices Output devices Chapter 1 - Slide 4

Organization of a Computer System Chapter 1 - Slide 5

The CPU Fetches instructions from main memory Carries out the operations commanded by the instructions Each instruction produces some outcome CPU gets instructions from a program A program is an entire sequence of instructions Instructions are stored as binary numbers Binary number - a sequence of 1 s and 0 s Chapter 1 - Slide 6

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 are lost when power is turned off Used as temporary storage Chapter 1 - Slide 7

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 flash memory devices High capacity device plugs into USB port Portable, reliable, and fits easily in a pocket Chapter 1 - Slide 8

Input Devices Any type of device that provides data to a computer from the outside world For example: Keyboard Mouse Scanner Chapter 1 - Slide 9

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 Chapter 1 - Slide 10

Software The programs that run on a computer Two major categories Operating systems 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, games, Internet browsers, playing music, etc) Each program is referred to as an application This book develops applications in Visual Basic Chapter 1 - Slide 11

Section 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 language used to write computer programs. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

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 Chapter 1 - Slide 13

Computing Gross Pay 1. Display message: "How many hours did you work?" 2. Allow user to enter number of hours worked 3. Store the number the user enters in memory 4. Display message: "How much are you paid per hour?" 5. Allow the user to enter an hourly pay rate 6. Store the number the user enters in memory 7. Multiply hours worked by pay rate and store the result in memory 8. 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 Chapter 1 - Slide 14

States and Transitions Memory snapshots show states of the program Program Starting State hours worked?? hourly pay rate?? amount earned?? 3. Store hours worked in memory Snapshot after Step 3 hours worked 20 hourly pay rate?? amount earned?? 6. Store hourly pay rate in memory Snapshot after Step 6 hours worked 20 hourly pay rate 25 amount earned?? 7. Multiply hours worked by pay rate and store amount earned in memory Snapshot after Step 7 hours worked 20 hourly pay rate 25 amount earned 500 Chapter 1 - Slide 15

Programming Languages The steps in our algorithm must be stated in a form the computer understands The CPU processes instructions as a series of 1 s and 0 s called machine language This is a tedious and difficult format for people Instead, programming languages allow us to use words instead of numbers Software converts the programming language statements to machine language Chapter 1 - Slide 16

Common Programming Languages Visual Basic Python JavaScript Java C# C C++ PHP Visual Basic is not just a programming language It s a programming environment with tools to: Create screen elements Write programming language statements Chapter 1 - Slide 17

What is a Program Made Of? Keywords (Reserved Words) Words with special meaning that make up a high-level programming language, cannot be used for any other purpose Operators Special symbols that perform various operations on data Variables Used to store data in memory, named by the programmer Syntax Set of rules Similar to the syntax (rules) of a spoken language, such as English, but must be strictly followed If even a single syntax error appears in a program, it will not compile or execute Chapter 1 - Slide 18

What is a Program Made Of? Statements Instructions made up of keywords, variables, and operators. Procedures Set of programming statements that perform a specific task Comments (Remarks) Ignored when the program runs, help human reader understand the purpose of programming statements In Visual Basic, any statement that begins with an apostrophe (') Chapter 1 - Slide 19

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 Chapter 1 - Slide 20

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 Chapter 1 - Slide 21

Example of an Object Form elements are objects called controls This form has: Two TextBox 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 Chapter 1 - Slide 22

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 TextBox (a TextChanged 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 Chapter 1 - Slide 23

Section 1.3 MORE ABOUT CONTROLS AND PROGRAMMING As a Visual Basic programmer, you must design and create an application s GUI elements (forms and other controls) and the programming statements that respond to and/or perform actions (event handlers). Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Visual Basic Controls As a Windows user you re already familiar with many Visual Basic controls: Label - displays text the user cannot change TextBox - allows the user to enter text Button performs an action when clicked RadioButton - A round button that is selected or deselected with a mouse click CheckBox A box that is checked or unchecked with a mouse click Form - A window that contains these controls Tutorial 1-3 demonstrates these controls Chapter 1 - Slide 25

Tutorial 1-3, Visual Basic Controls Chapter 1 - Slide 26

The 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 Chapter 1 - Slide 27

Examples of Names The Label controls use the default names (Label1, etc.) Text boxes, buttons, and the Gross Pay label play an active role in the program and have been changed Form1 Label1 Label2 Label3 txthoursworked txtpayrate lblgrosspay btncalcgrosspay btnclose Chapter 1 - Slide 28

Naming Conventions Control names must start with a letter Remaining characters may be letters, digits, or underscore 1st 3 lowercase letters indicate the type of control txt for Text Boxes lbl for Labels btn for Buttons After that, capitalize the first letter of each word txthoursworked is clearer than txthoursworked Chapter 1 - Slide 29

Section 1.4 THE PROGRAMMING PROCESS The programming process consists of several steps, which include designing, creating, testing, and debugging activities. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

Step 1 of 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 Chapter 1 - Slide 31

Step 2 of Developing an Application Visualize the application running on the computer and design its user interface Chapter 1 - Slide 32

Step 3 of Developing an Application Determine the controls needed Type Name Description TextBox txthoursworked Allows the user to enter the number of hours worked. TextBox txtpayrate Allows the user to enter the hourly pay rate Label lblgrosspay Displays the gross pay, after the btncalcgrosspay button has been clicked Button btncalcgrosspay When clicked, multiplies the number of hours worked by the hourly pay rate Button btnclose When clicked, terminates the application Label (default) Description for Number of Hours Worked TextBox Label (default) Description for Hourly Pay Rate TextBox Label (default) Description for Gross Pay Earned Label Form (default) A form to hold these controls Chapter 1 - Slide 33

Step 4 of Developing an Application Define the values of each control s relevant properties Control Type Control Name Text Form (Default) "Wage Calculator" Label (Default) "Number of Hours Worked" Label (Default) "Hourly Pay Rate" Label (Default) "Gross Pay Earned" Label lblgrosspay "$0.00" TextBox txthoursworked "" TextBox txtpayrate "" Button btncalcgrosspay "Calculate Gross Pay" Button btnclose "Close" Chapter 1 - Slide 34

Step 5 of Developing an Application Determine the event handlers and other code needed for each control Method btncalcgrosspay_click btnclose_click Description Multiplies hours worked by hourly pay rate These values are entered into the txthoursworked and txtpayrate TextBoxes Result is stored in lblgrosspay Text property Terminates the application Chapter 1 - Slide 35

Step 6 of Developing an Application Create a flowchart or pseudocode version of the code A flowchart is a diagram that graphically depicts the flow of a method Pseudocode is a cross between human language and a programming language Chapter 1 - Slide 36

Step 7 of 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 Chapter 1 - Slide 37

Step 8 of 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 Chapter 1 - Slide 38

Step 9 of Developing an Application Use the flowcharts or pseudocode from step 6 to write the actual code 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 Chapter 1 - Slide 39

Step 10 of 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 Chapter 1 - Slide 40

Step 11 of 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 Chapter 1 - Slide 41

Section 1.5 VISUAL STUDIO AND VISUAL BASIC EXPRESS EDITION (THE VISUAL BASIC ENVIRONMENT) Visual Studio and Visual Basic Express Edition consist of tools that you use to build Visual Basic applications. The first step in using Visual Basic is learning about these tools. Addison Wesley is an imprint of 2011 Pearson Addison-Wesley. All rights reserved.

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# Chapter 1 - Slide 43

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 Chapter 1 - Slide 44