 What Does This Program Do? ACSL.  Frequently one must use or modify sections of another programmer’s code.  It is essential to be able to read and.

Slides:



Advertisements
Similar presentations
2.1 Program Construction In Java
Advertisements

What Does This Program Do?
CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Java Programming, 3e Concepts and Techniques Chapter 3 Section 63 – Manipulating Data Using Methods – Day 2.
Chapter 10.
Introduction to Computers and Programming Lecture 7:
The number of calories burned per hour by cycling, jogging and swimming are 200, 475 and 275 respectively. A person loses 1pound of weight for each 3500.
The scanf Function The scanf function reads input from the standard input device into one or more variables Example: scanf(“%lf”, &miles); Reads a real.
Mark Dixon, SoCCE SOFT 131Page 1 04 – Information Processing: Data-types, Variables, Operators & Functions.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
C++ for Engineers and Scientists Third Edition
PRINCIPLES OF PROGRAMMING Revision. A Computer  A useful tool for solving a great variety of problems.  To make a computer do anything (i.e. solve.
1 Lab Session-III CSIT-120 Fall 2000 Revising Previous session Data input and output While loop Exercise Limits and Bounds Session III-B (starts on slide.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Introduction to Python
Created by, Author Name, School Name—State FLUENCY WITH INFORMATION TECNOLOGY Skills, Concepts, and Capabilities.
Chapter 3: Data Types and Operators JavaScript - Introductory.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
Input, Output, and Processing
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
The while Loop Syntax while (condition) { statements } As long condition is true, the statements in the while loop execute.
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Constants Numeric Constants Integer Constants Floating Point Constants Character Constants Expressions Arithmetic Operators Assignment Operators Relational.
1 E0001 Computers in Engineering Built in Functions.
ORDER OF CONTENT AND INSTRUCTIONS A program in its simplest form usually contains three kinds of activity:  INPUT : The program asks the user for some.
By Chad Blankenbeker.  The for-loop is best used when you know how many times it is going to be looped  So if you know you want it to only loop 10 times,
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
CS161 Topic #16 1 Today in CS161 Lecture #16 Prepare for the Final Reviewing all Topics this term Variables If Statements Loops (do while, while, for)
1 Flow Control Ifs, loops. 2 Data Type At the lowest level, all data in a computer is written in 1’s and 0’s (binary) How the data gets interpreted, what.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
Decision Structures, String Comparison, Nested Structures
Digital Image Processing Lecture 6: Introduction to M- function Programming.
Pointers *, &, array similarities, functions, sizeof.
Operators and Expressions. 2 String Concatenation  The plus operator (+) is also used for arithmetic addition  The function that the + operator performs.
Introduction to Python Dr. José M. Reyes Álamo. 2 Three Rules of Programming Rule 1: Think before you program Rule 2: A program is a human-readable set.
Lecture – Pointers1 C++ Pointers Joseph Spring/Bob Dickerson School of Computer Science Operating Systems and Computer Networks Based on notes by Bob Dickerson.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Structuring Data: Arrays ANSI-C. Representing multiple homogenous data Problem: Input: Desired output:
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Visual Basic Review LBS 126. VB programming Project Form 1Form 2Form 3 Text boxButton Picture box Objects Text box Button Objects.
Midterm Review Tami Meredith. Primitive Data Types byte, short, int, long Values without a decimal point,..., -1, 0, 1, 2,... float, double Values with.
Programming Logic and Design Fifth Edition, Comprehensive Chapter 6 Arrays.
Expressions Version Topics Arithmetic expressions Conversions Operator precedence String class 2.
October 15, 2013 Welcome! We will begin shortly..
OPERATORS IN C CHAPTER 3. Expressions can be built up from literals, variables and operators. The operators define how the variables and literals in the.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Visual Basic 6 (VB6) Data Types, And Operators
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Data Conversion & Scanner Class
Variables, Expressions, and IO
Other Kinds of Arrays Chapter 11
The order in which statements are executed is called the flow of control. Most of the time, a running program starts at the first programming statement,
Java Programming: From Problem Analysis to Program Design, 4e
MATLAB: Structures and File I/O
Introduction to MATLAB
Arithmetic Operator Operation Example + addition x + y
Decision Structures, String Comparison, Nested Structures
Unit 2 Programming.
Q W E R T Y U I O P A S D F G H J K L Z X C V B N M
Decision Structures, String Comparison, Nested Structures
Chapter 2: Basic Elements of Java
Programming Funamental slides
CS150 Introduction to Computer Science 1
elementary programming
Expressions An expression is a portion of a C++ statement that performs an evaluation of some kind Generally requires that a computation or data manipulation.
Chapter 5 Decisions.
Basic 9 Mr. Husch.
Presentation transcript:

 What Does This Program Do? ACSL

 Frequently one must use or modify sections of another programmer’s code.  It is essential to be able to read and understand an arbitrary program.  Code fragments used in this category are examples of “good” BASIC programming.

 The dialect of BASIC that we will use is ACSL BASIC. The questions will emphasize elementary structured flow of control rather than the particular syntax of the dialect.  Topics covered in the Intermediate Division include (but are not limited to): the evaluation of arithmetic expressions, loops (single and nested), branching, subscripted variables, multi-dimensional arrays, and string manipulations.  In the Junior Division, the specific topic to be tested is given in the title of the category.

 The following system functions may be used: INT, ABS, LEFT$, RIGHT$, MID$, LEN, VAL, STR$, SQR and SGN.  The functions NOT, AND and OR will also be used; they have the order of precedence listed (that is, NOT is highest and OR is the lowest).

 The following statements may be used: INPUT, DATA, READ, RESTORE, PRINT, TAB, FOR/NEXT, GOTO, GOSUB, RETURN, IF-THEN, IF-THEN-ELSE, LET, REM, DIM, DEF (for user defined functions), END and STOP.

 Files and matrix commands will NOT be used. Assume that our programs are immune to syntax errors, variables have enough storage (for example, one doesn’t need an explicit “DIM X(100)” in a program that uses an array with 100 elements).

 While most commands are functions that are the same on each system, the following frequently vary from system to system. On the next slide we have listed these functions and the interpretation that will be used for the contests. 

 INT(A) returns the largest integer not greater than A.  LEFT$(A$,N) returns a string consisting of the first N characters of the string A$.  RIGHT$(A$,N) returns a string consisting of the last N characters of the string A$.  MID$(A$,A,B) returns a string consisting of the B characters beginning with the A th character of A$. For example, if A$=”AMERICAN COMPUTER” then MID$(A$,7,5) would equal “AN CO”.

 LEN(A$) returns an integer representing the number of characters in the string A$. If A$ is null (A$= “”) then LEN(A$)=0.  STR$(A) converts the integer A into a string. Note that an extra space will exist on the left of the string. For example, if A=123 then STR$(A)= “ 123”.  VAL(A$) is the inverse to STR$. This converts the string to its numeric value. The string’s contents must form a valid number.

Sample Problem 1 After the following program is executed, what is the final value of B?  10 read H, R  15 data 50, 10  20 B = 0  25 if H<=48 then 40  30 B = B + (H-48)*2*R  35 H=48  40 rem  45 if H<=40 then 60  50 B = B +(H-40)*(3/2)*R  55 H=40  60 rem  65 B = B + H*R  70 end

 This program computes an employee’s weekly salary, given the hourly rate (R) and the number of hours worked in the week (H). The employee is paid his/her hourly rate for the number of hours worked, up to 40; time and a half for the overtime hours, up to 48 hours; double for all hours after 48. The following table monitors variables B and H through the program execution:  LINE B H        Therefore, the final value of B is 560.

Sample Problem 2  After the following program is executed, what is the final value of X?  10 X = 0  20 for K = 7 to 52 step 6  30 X = X + K  40 next K  50 end K takes on values of 7, 13, 19, …, 49. The loop adds these numbers together in line 30.

Sample Problem 3  After the following program is executed, what is the final value of X? (Assume that the initial value of T$ is the null string.)  10 read A$  20 X = 0  25 for J = len(A$) to 1 step –1  30 T$ = T$ + mid$(A$,J,1)  35 next J  40 for J = 1 to len(A$)  45 if mid$(A$,J,1) = mid$(T$,J,1) then X = X+1  50 next J  55 data BANANAS  60 end

 The program first stores the reverse of A$ into T$, and then counts the number of letters that are in the same position in both strings.  Those positions marked with an asterisk contribute one to the value of X. There are 5 such positions.

Sample Problem 4  After the following program is executed, what is the final value of C(4)?  10 A(1)=12: A(2)=41: A(3)=52  15 A(4)=57: A(5)=77: A(6)=-100  20 B(1)=17: B(2)=34: B(3)=81  25 J=1: K=1: L=1  30 rem  35 if B(K) > A(J) then 60  40 C(L) = B(K)  45 L = L+1  50 K = K+1  55 goto 35  60 C(L) = A(J)  65 L = L+1  70 J = J+1  75 if A(J)>0 then 30  80 end

 The following table traces the variables through the execution of the program.  J K L A(J) B(K) C(L)      Thus the value of C(4) is 41. Note that this program merges two arrays in increasing order into one.