Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!

Slides:



Advertisements
Similar presentations
Objectives Understand the software development lifecycle Perform calculations Use decision structures Perform data validation Use logical operators Use.
Advertisements

ABNIAC The following slide presentation is to acquaint the student with ABNIAC. The version used for presentation is the Java version, which can be found.
Understanding the Mainline Logical Flow Through a Program (continued)
To type the VB code behind the command button (named cmdPush), Double-Click on the Push Me (caption) command button As a result the Visual Basic Code Window.
Visual Basic Fundamental Concepts. Integrated Development Enviroment Generates startup form for new project on which to place controls. Features toolbox.
4-1 Coding Complete COBOL Programs: The PROCEDURE DIVISION Chapter 4.
1 Chapter 4. To familiarize you with methods used to 1. Access input and output files 2. Read data from an input file 3. Perform simple move operations.
Chapter To familiarize you with  Why COBOL is a popular business-oriented language.  Programming practices and techniques  History of COBOL.
1 Visual Basic for Applications (VBA) for Excel Prof. Yitzchak Rosenthal.
® Microsoft Access 2010 Tutorial 11 Using and Writing Visual Basic for Applications Code.
InvEasy (Project1) Please use speaker notes for additional information!
Modifications to program Addda.cbl Please use speaker notes for additional information!
Break Processing Please use speaker notes for additional information!
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
1 Κατανεμημένες Διαδικτυακές Εφαρμογές Πολυμέσων Γιάννης Πετράκης.
Class 3 Programming in Visual Basic. Class Objectives Learn about input/output Learn about strings Learn about subroutines Learn about arrays Learn about.
08/10/ Iteration Loops For … To … Next. 208/10/2015 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Chapter 4: The Selection Process in Visual Basic.
Totals on the Screen Please use speaker notes for additional information!
Copyright © 2001 by Wiley. All rights reserved. Chapter 5: The Repetition Process in Visual Basic Event Driven Loops Determinate Loops Indeterminate Loops.
Logic Structure - focus on looping Please use speaker notes for additional information!
Lecture 31 Numeric Edited Alphabetic (A) AlphaNumeric (X) Numeric (9, V, S) Numeric Edited (9, Z, comma, decimal point, minus sign) –Z = zero suppressed.
1 Interactive vs Batch Programs Cobol suited for developing both types of programs Interactive programs Accept input data from keyboard Input data processed.
Array - adding to array at run time Please see speaker notes for additional information!
Programming Test #1 Solutions. Multiple Choice 1. B) the grammar of the coding language 2. C) String 3. A) Single 4. C) 2Burgers4Me 5. B) Design Time.
SYSTEMSDESIGNANALYSIS 1 OO: Chapter 9 Visual Basic: Building Components Jerry Post Copyright © 1999.
Chapter 7 File I/O 1. File, Record & Field 2 The file is just a chunk of disk space set aside for data and given a name. The computer has no idea what.
New Project in Visual Basic Please use speaker notes for additional information!
MS Visual Basic Applications Walter Milner. Event-driven programming Standard approach for GUIs Contrast with old character interfaces – program determines.
Random Files Please see speaker notes for additional information!
Visual Basic Programming
Explanation of SAMPLEIF (if88in1.cbl or if88in1.html) Please use speaker notes for additional information!
Data Types and Variables. Data Type! Computers are all about Data! Data can be in the form of Text Dates Sounds Pictures.
HELLO WORLD program in COBOL - CIS12 Please use speaker notes for additional information!
MS Visual Basic 6 Walter Milner. VB 6 0 Introduction –background to VB, A hello World program 1 Core language 1 –Projects, data types, variables, forms,
COBOL Screens Please use speaker notes for additional information!
Two Forms Please use speaker notes for additional information!
1 CS105 Discussion 5 – Variables and If Announcements MP 1 due on Monday Midterm 1 on Tuesday If you need a conflict, request it NOW!!
Lab 6 (2) Arrays ► Lab 5 (1) Exercise Review ► Array Concept ► Why Arrays? ► Array Declaration ► An Example of Array ► Exercise.
Pay Example (PFirst98) Please use speaker notes for additional information!
Visual Basic I/O Programs (ProjRead1, ProjRead2, ProjWrite1, ProjPay) Please use speaker notes for additional information!
Maximum Profit Please use speaker notes for additional information!
Lesson 1. Security At the menu bar at the top you will see the word Tools. Click your mouse on Tools scroll down to Macro. Move the Mouse over and down.
110 E-1 Variables, Constants and Calculations(2) Chapter 3: Operations on variables, scope of a variable, formatting data Doing Arithmetic.
Analysis of SAMPLE1.CBL Please check speaker notes for additional information!
Slide 1 Controls v Control naming convention –Label: lblName –Command Button: cmdName –Text Box: txtName.
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
Introduction to Programming
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Chapter 4 PROCEDURE DIVISION. Paragraphs PROCEDURE DIVISION divided into paragraphs Each is independent module or routine Made up of series of instructions.
Using a Database Access97 Please use speaker notes for additional information!
COMPREHENSIVE Access Tutorial 11 Using and Writing Visual Basic for Applications Code.
Data and variables in Visual Basic. Annoucement Lecture on Thursday 7:30PM C106 Visual Basic download: 
Creation of Variables with Numeric, alphanumeric, date, picture, memo data types Constant - A quantity that does not change during the execution of a program.
AVCE ICT – Unit 7 - Programming Session 12 - Debugging.
Week 1 Lecture 1 Slide 1 CP2028 Visual Basic Programming 2 “The VB Team” Copyright © University of Wolverhampton CP2028 Visual Basic Programming 2 v Week.
General Introduction Algorithms. Let’s write a program  A program is a collection of statements written in a language the computer understands.  A computer.
Chapter 6 - Visual Basic Schneider1 Chapter 6 Repetition.
National Diploma Unit 4 Introduction to Software Development Procedures and Functions.
Subroutines (PrArith, Math,projCP1, PrAdrProc, PrAdrProcFunc) Please use speaker notes for additional information!
26/06/ Iteration Loops For … To … Next. 226/06/2016 Learning Objectives Define a program loop. State when a loop will end. State when the For.
Visual Basic - Break Processing
Processing multiple files
Keyboard Input and Screen Display ––––––––––– Interactive Programming
Please use speaker notes for additional information!
Objectives Learn about Function procedures (functions), Sub procedures (subroutines), and modules Review and modify an existing subroutine in an event.
Department Array in Visual Basic
Language Constructs Construct means to build or put together. Language constructs refers to those parts which make up a high level programming language.
Using screens and adding two numbers - addda.cbl
Tutorial 11 Using and Writing Visual Basic for Applications Code
Presentation transcript:

Programming Examples to Accompany Structure Topic Please use speaker notes for additional information!

Start Get input number not end of user input Calculate the double of the input by multiplying by 2 Display/print answer Get input number Y N Stop Pseudocode: start get input number while not end of user input calculate the answer (multiply input by 2) display/print the answer get input number end loop stop

This shows the program written from the logic in the flowchart and pseudocode on the previous slide. It also shows the output that was generated when the program was run. COBOL

This shows the definition of the variables I am going to use in the program. INPUT-NUM is where I will have the user key in a number to be doubled. DOUBLE-NUM will hold the result of doubling the number. ANS-WS is where the enter key the user presses when they want to move on to the next number is stored. COBOL

I am using the DISPLAY AND ACCEPT commands to take in user input. The DISPLAY asks the user to key in information and the ACCEPT takes the information and stores it in the place of that name. DISPLAY “ENTER INPUT NUMBER”. This command prompts the user to enter a number. ACCEPT INPUT-NUM. This command takes the data the user enters (note the data cannot be more than two characters) and stores it in INPUT-NUM. Note that when the user entered , the computer took only the 12 and stored it as INPUT-NUM. This means that DOUBLE-NUM will be 024. It is 024 because DOUBLE-NUM has a PIC of 999 and can therefore hold three numbers. COBOL

PERFORM UNTIL INPUT-NUM=99 means that processing will stop when the user enters 99. While the user enters other numbers the processing between the PERFORM and the END-PERFORM will be executed. Note that one of the things I added to the pseudocode was the end loop. The processing that is done is to use the COMPUTE statement to do the math and then DISPLAY the original number and the double number. The ACCEPT ANS-WS waits for the user to press the enter key or take some other keyboard action. Then the processing takes in a new number. Pseudocode: start get input number while not end of user input calculate the answer (multiply input by 2) display/print the answer get input number end loop stop COBOL

IDENTIFICATION DIVISION. PROGRAM-ID. DOUBLE. DATA DIVISION. FILE SECTION. WORKING-STORAGE SECTION. 01 INPUT-AREA. 05 INPUT-NUM PIC WORK-AREAS. 05 DOUBLE-NUM PIC USER-RESPONSE. 05 ANS-WS PIC X. PROCEDURE DIVISION. PROCESS. DISPLAY "ENTER INPUT NUMBER". ACCEPT INPUT-NUM. PERFORM UNTIL INPUT-NUM = 99 COMPUTE DOUBLE-NUM = INPUT-NUM * 2 DISPLAY INPUT-NUM " " DOUBLE-NUM ACCEPT ANS-WS DISPLAY "ENTER INPUT NUMBER" ACCEPT INPUT-NUM END-PERFORM. STOP RUN. Pseudocode: start get input number while not end of user input calculate the answer (multiply input by 2) display/print the answer get input number end loop stop COBOL

IDENTIFICATION DIVISION. PROGRAM-ID. DOUBLE. ENVIRONMENT DIVISION. SELECT NUMBER-FILE ASSIGN TO "E:\CIS17\COBOL\DOUBLE.TXT". DATA DIVISION. FILE SECTION. FD NUMBER-FILE DATA RECORD IS NUMBER-RECORD. 01 NUMBER-RECORD. 05 INPUT-NUM PIC 99. WORKING-STORAGE SECTION. 01 WORK-AREAS. 05 DOUBLE-NUM PIC EOF-CHECK-AREA. 05 EOF-IND PIC X VALUE "N". 01 USER-RESPONSE. 05 ANS-WS PIC X. PROCEDURE DIVISION. PROCESS. OPEN INPUT NUMBER-FILE. READ NUMBER-FILE AT END MOVE "Y" TO EOF-IND. PERFORM UNTIL EOF-IND = "Y" COMPUTE DOUBLE-NUM = INPUT-NUM * 2 DISPLAY INPUT-NUM " " DOUBLE-NUM ACCEPT ANS-WS READ NUMBER-FILE AT END MOVE "Y" TO EOF-IND END-READ END-PERFORM. STOP RUN. Pseudocode: start get input number while not end of user input calculate the answer (multiply input by 2) display/print the answer get input number end loop stop COBOL

This is the file that is being read. You can see on the output that the first line is for 02 and the second line is for 12 and the third line is for 25 etc. COBOL

Using Visual Basic, I am not exactly following the logic flowchart that was laid out. Visual Basic is event driven. This means that when the user clicks on something, it causes certain code to happen. In this case, I am having the user enter a number and then click on Start Program. The calculation is done and appears in the box on the left. There is no loop in this program because each time the user enters a number, they click on the Start Program button and that one calculation gets done. VB

Option Explicit Dim wkDoubleNum As Integer Private Sub cmdDoubleFile_Click() wkDoubleNum = txtInputNum.Text * 2 picDoubleNum.Print "#: "; txtInputNum.Text; " Double: "; wkDoubleNum End Sub Private Sub cmdEnd_Click() End End Sub When the End button is clicked this subroutine is executed and the program Ends. When the Start Program button is clicked it executed the cmdDoubleFile subroutine which does the math and calculates the double amount which it stores in the variable wkDoubleNum and then prints the results in the picDoubleNum box. The variable wkDoubleNum is declared as an Integer. VB

Option Explicit Dim wkDoubleNum As Integer Private Sub cmdDoubleFile_Click() wkDoubleNum = txtInputNum.Text * 2 picDoubleNum.Print "#: "; txtInputNum.Text; " Double: "; wkDoubleNum End Sub Private Sub cmdEnd_Click() End End Sub Pseudocode: start get input number while not end of user input calculate the answer (multiply input by 2) display/print the answer get input number end loop stop The get input number is handled by providing a box on the form for the user to enter the number. The loop is handled by the user who enters a number and then presses the key to Start Program which does the routine called cmdDoubleFile. The user controls the loop with the click event so no loop is coded into the program. VB

Option Explicit Dim wkDoubleNum As Integer Dim wkInputNum As Integer Private Sub cmdDoubleFile_Click() Do While Not EOF(1) Input #1, wkInputNum wkDoubleNum = wkInputNum * 2 picDoubleNum.Print "#: "; wkInputNum; "Double: "; wkDoubleNum Loop MsgBox "Processing Complete" Close #1 End End Sub Private Sub Form_Load() Open App.Path & "\double.txt" For Input As #1 End Sub Pseudocode: start while not end of user input get input number calculate the answer (multiply input by 2) display/print the answer end loop stop VB Pseudocode: start get input number while not end of user input calculate the answer (multiply input by 2) display/print the answer get input number end loop stop