What Does This Program Do?

Slides:



Advertisements
Similar presentations
Topic Reviews For Unit ET156 – Introduction to C Programming Topic Reviews For Unit
Advertisements

Chapter 4 Loops Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved
4 Control Statements: Part 1.
2.1 Program Construction In Java
Arithmetic Calculations
UNIT 9: Pointers Data Variable and Pointer Variable Pass by Reference
Chapter 9 – One-Dimensional Numeric Arrays. Array u Data structure u Grouping of like-type data u Indicated with brackets containing positive integer.
1.
Chapter 7: Arrays In this chapter, you will learn about
CSI 1306 ALGORITHMS - PART 4 LIST PROCESSING. Lists Sometimes a problem deals with a list of values We represent such a list with a single name, and use.
Modern Programming Languages, 2nd ed.
Lilian Blot CORE ELEMENTS PART I Python Language Autumn 2013 TPOP 1.
Arrays.
Control Structures Selections Repetitions/iterations
1 of 31 Images from Africa. 2 of 31 My little Haitian friend Antoine (1985)
CSci 1130 Intro to Programming in Java
EC-111 Algorithms & Computing Lecture #11 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
Nested if-else Statements.  Should be indented to make the logic clear.  Nested statement executed only when the branch it is in is executed. For example,
CSI 1306 PROGRAMMING IN VISUAL BASIC PART 2. Part 2  1. Strings  2. Translating Conditional Branch Instructions  3. Translation Set 2  4. Debugging.
Types of selection structures
Pointers and Arrays Chapter 12
Standard Algorithms Find the highest number. ! Your name and today’s date ! Find the maximum Dim numbers(20) As Integer.
Visual Basic Statements Chapter 5. Relational Operators  OperationSymbol  Equal  =  Less than  <  Greater than  >  Not equal   Less than.
Types and Arithmetic Operators
Dr. Yang, Qingxiong (with slides borrowed from Dr. Yuen, Joe) LT4: Control Flow - Loop CS2311 Computer Programming.
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.
C++ for Engineers and Scientists Third Edition
CSCI/CMPE 4341 Topic: Programming in Python Chapter 3: Control Structures (Part 1) – Exercises 1 Xiang Lian The University of Texas – Pan American Edinburg,
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.
Chapter 7: Arrays. In this chapter, you will learn about: One-dimensional arrays Array initialization Declaring and processing two-dimensional arrays.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Chapter 8 Arrays and Strings
Object-Oriented Program Development Using Java: A Class-Centered Approach, Enhanced Edition.
Flow of Control Part 1: Selection
C++ Programming: From Problem Analysis to Program Design, Fifth Edition Arrays.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
1 E0001 Computers in Engineering Built in Functions.
C++ for Engineers and Scientists Second Edition Chapter 11 Arrays.
CONTENTS Processing structures and commands Control structures – Sequence Sequence – Selection Selection – Iteration Iteration Naming conventions – File.
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.
Pointers *, &, array similarities, functions, sizeof.
CHAPTER 6 ARRAYS IN C++ 2 nd Semester King Saud University College of Applied studies and Community Service CSC 1101 By: Fatimah Alakeel Edited.
Operator precedence.  Evaluate a + b * c –multiplication first? a + (b * c) –addition first? ( a + b) * c  Java solves this problem by assigning priorities.
CECS 5020 Computers in Education Visual Basic Variables and Constants.
Midterm Exam Topics (Prof. Chang's section) CMSC 201.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
CS Class 04 Topics  Selection statement – IF  Expressions  More practice writing simple C++ programs Announcements  Read pages for next.
Computer Programming Arrays 1. Question #1 2 Question Choose the correct answer..
 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.
October 15, 2013 Welcome! We will begin shortly..
Chapter 6 Arrays in C++ 2nd Semester King Saud University
BASIC ELEMENTS OF A COMPUTER PROGRAM
Topic: Python’s building blocks -> Statements
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.
Java Programming: From Problem Analysis to Program Design, 4e
Arithmetic Operator Operation Example + addition x + y
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
And now for something completely different . . .
3-3 Side Effects A side effect is an action that results from the evaluation of an expression. For example, in an assignment, C first evaluates the expression.
Chapter 2: Basic Elements of Java
Review for Final Exam.
Programming Funamental slides
Chapter (3) - Looping Questions.
Summary Two basic concepts: variables and assignments Basic types:
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.
Review for Final Exam.
CS 101 First Exam Review.
Presentation transcript:

What Does This Program Do?

The dialect of BASIC that we will use is ACSL BASIC 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. Students familiar with BASIC or any other high-level language (e.g., Pascal, PL/C, C, FORTRAN), should be able to master this category with just a little additional preparation.

Topics covered include (but are not limited to): evaluation of arithmetic expressions, loops (single and nested), branching, subscripted variables, multi-dimensional arrays, string manipulations.

System Functions INT, ABS, LEFT$, RIGHT$, MID$, LEN, VAL, STR$, SQR 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: RETURN, IF-THEN, IF-THEN-ELSE, LET, REM, (comment) DIM, DEF (for user defined functions), END STOP INPUT, DATA, READ, RESTORE, PRINT, TAB, FOR/NEXT, GOTO, GOSUB,

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).

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 Ath 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 Problems 10 read H, R 15 data 50, 10 20 B = 0 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 20 0 50 30 40 50 35 40 48 50 160 48 55 160 40 65 560 40 Therefore, the final value of B is 560.

After the following program is executed, what is the final value of X 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.

45 if mid$(A$,J,1) = mid$(T$,J,1) then X = X+1 50 next J 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. A$ B A N S   *

10 A(1)=12: A(2)=41: A(3)=52 15 A(4)=57: A(5)=77: A(6)=-100 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) 1 1 1 12 17 12 2 1 2 41 17 17 2 2 3 41 34 34 2 3 4 41 81 41 Thus the value of C(4) is 41. Note that this program merges two arrays in increasing order into one.