Assignment statement and Arithmetic operation 1 The major part of data processing.

Slides:



Advertisements
Similar presentations
E.g.9 For to do loop for i:=1 to 10 do writeln(i); While do loop i:=1;
Advertisements

Selection Process If … then … else.... Condition Process 2 Process 1 Y.
Computer Programming Mr. José A. Ortiz Morris. Computer Language  Languages that the computer understands.  They are low level languages. (BINARY 1.
CS107 Introduction to Computer Science Lecture 3, 4 An Introduction to Algorithms: Loops.
Get a calculator!  How many parts are there to a triangle ? a b c  C Pardekooper AA BB CC.
1 Outline 13.1Introduction 13.2A Simple Program: Printing a Line of Text in a Web Page 13.3Another JavaScript Program: Adding Integers 13.4Memory Concepts.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
TrueBASIC Ch 4 & 5 Sample Problems. What are the errors? (4 total) INPUT age IF age > 7 THEN PRINT "rollercoaster" ELSE PRINT "ferris wheel" IF age
J. Michael Moore Input and Output (IO) CSCE 110 Drawn from James Tam's material.
An intro to programming concepts with Scratch Session 2 of 10 sessions I/O, variables, simple computing.
Input and Output (IO) CSCE 110 Drawn from James Tam's material.
1  Ex: Declare a variable to store user’s age: int age; Prompt the user to enter his/her age: printf (“ How old are you? “); Read / scan the entered value.
Computing Theory: BBC Basic Coding Year 11. Lesson Objective You will: Be able to define what BBC basic is Be able to annotate BBC basic code Be able.
INTRODUCTION TO PYTHON PART 2 INPUT AND OUTPUT CSC482 Introduction to Text Analytics Thomas Tiahrt, MA, PhD.
ADDING INTEGERS Positive + Positive = Positive Positive + Positive = Positive ( +3) + (+2) = +5 ( +3) + (+2) = +5 When a number is positive, you do not.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Instructor: Chris Trenkov Hands-on Course Python for Absolute Beginners (Spring 2015) Class #002 (January 17, 2015)
IPC144 Introduction to Programming Using C Week 1 – Lesson 2
Computer Science 210 Computer Organization Introduction to Boolean Algebra.
ARRAYS 1.Basic Ideas 2.The Array Type 3.Processing Arrays 4.Parallel Arrays 5.Two-dimensional Array 6.Arrays as Parameters.
Homework Assignment #3 J. H. Wang Oct. 29, 2007.
Functions Introduction to Programming By Engr. Bilal Ahmad 1ITP by Engr. Bilal Ahmad.
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
How to start Visual Studio 2008 or 2010 (command-line program)
Introduction to Engineering MATLAB – 2 Introduction to MATLAB - 2 Agenda Defining Variables MATLAB Windows.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
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.
Control Structures (A) Topics to cover here: Introduction to Control Structures in the algorithmic language Sequencing.
NA2204.1jcmt CSE 1320 Intermediate Programming C Program Basics Structure of a program and a function type name (parameters) { /* declarations */ statement;
Warm ups. Return Quizzes Let’s go over them!! 9-8 Special Products Objective: To identify and expand the three special products.
First steps Jordi Cortadella Department of Computer Science.
Introduction to Pascal The Basics of Program writing.
Ch. 10 For Statement Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2012.
Programming, an introduction to Pascal
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)
solve x + (-16) = -12 solve x + (-16) = X = 4.
 2000 Deitel & Associates, Inc. All rights reserved. Outline 8.1Introduction 8.2A Simple Program: Printing a Line of Text in a Web Page 8.3Another JavaScript.
Lecture 6: Output 1.Presenting results in a professional manner 2.semicolon, disp(), fprintf() 3.Placeholders 4.Special characters 5.Format-modifiers 1.
Using variable Variables are used to store values.
LAB SESSION ONE DIMENSIONAL ARRAY.
PROGRAMMING IN PYTHON LETS LEARN SOME CODE TOGETHER!
Calculator Program Explained by Arafa Hamed. First Designing The Interface Ask yourself how many places are there that will be used to input numbers?
 Definition Definition  Algorithmic Representation of Computer Functions Algorithmic Representation of Computer Functions  Algorithm Description Algorithm.
Sum of Arithmetic Sequences. Definitions Sequence Series.
int [] scores = new int [10];
GCSE Computing: Programming GCSE Programming Remembering Python.
Simple “VICO” (“VIPO”) Programs (Variables, Input, Calculating or Processing, Output)
Computer Programming 12 Mr. Jean March 5 th, 2014.
Variables.. Part 2 Calculations. Review of yesterday Three types of variables var num:int var average:real var username:string No decimals Might have.
Arithmetic, Functions and Input 9/16/13. Arithmetic Operators C++ has the same arithmetic operators as a calculator: * for multiplication: a * b – Not.
Input and Output Output Prompt: –A message displayed to the user indicating what they are to enter. Should be clear and exact on what you want. write:
CCSA 221 Programming in C CHAPTER 3 COMPILING AND RUNNING YOUR FIRST PROGRAM 1 ALHANOUF ALAMR.
Pascal Programming Today Chapter 2 1 Chapter 2. Pascal Programming Today Chapter 2 2 »Output statements write data to output devices (e.g. VDU). »Two.
Input, Output and Variables GCSE Computer Science – Python.
1-1 Logic and Syntax A computer program is a solution to a problem.
INC 161 , CPE 100 Computer Programming
Data Types and Conversions, Input from the Keyboard
ALGORITHMS part-1.
The CONST definition CONST Pi = , City = ‘New York’;
Programming Fundamental
Chapter 2 Assignment and Interactive Input
Assignment statement and Arithmetic operation 2
Number and String Operations
CS150 Introduction to Computer Science 1
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
INC 161 , CPE 100 Computer Programming
7 – Variables, Input and Output
Computer Science 1 For..do loop Dry Run Take notes on the For loop
Little Man Computer (continued).
Introduction to Python
Presentation transcript:

Assignment statement and Arithmetic operation 1 The major part of data processing

Data processing As you should still remember, there are 3 major steps in data processing: FINISH START INPUTPROCESSINGOUTPUT readln???? writeln, write We have learnt INPUT commands And also the OUTPUT commands What about the PROCESSING?

Assignment statements n Assignment statement is one of the statements used in processing data n It allows us to: –store DATA in variables – COPY data between variables and –store CALCULATION RESULT in variables

How to use it When we want to STORE the data 4 in variable X, we can use the following statement: Put the TARGET X at the front Put the special signs ‘:= ‘ next Put the DATA 4 at last

How to use it When we want to COPY the data stored in variable X into the variable Y, we can use the following statement: Put the TARGET Y at the front Put the special sign ‘ := ‘ next Put the SOURCE X at last

How to use it When we want to Store the sum of the values in A and B into Y, we can use the following statement: Put the TARGET Y at the front Put the special sign ‘:= ‘ next Put the FORMULA A+B at last

000 How does it work? program ARITHMETIC(input,output); varX, Y, Z : integer; begin X := 4; Y := X; Z := X + Y; writeln(X, Y, Z); end. Let’s consider the following example: 448 Store the data 4 into X Copy the content of X into Y Put the sum of X and Y in Z What is the output?

program ARITHMETIC(input,output); varX, Y, Z : integer; begin X := 4; Y := X; Z := X + Y; writeln(X,’+’,Y,’=’,Z); end. 4+4=8 This is the output

program AREA(input,output); varX, Y, Z : integer; begin X := 4; Y := 7; Z := X * Y; writeln(‘The area is ‘,Z); end. The area is 28 What is the output? This is the output

A, B, C are variables of integer type. What do the following statements do? 1. A:=B+C; 2. A+B:=A+B; 3. 3:=A+B; 4. C:=(A+B+C)/3; 5. A+3:=3+A; 6. B:=B; 7. C:= C + 1; Store the sum of B and C into A INVALID Compute the average of A, B and C, then store it in C (over writing the old value) INVALID Store the value in B back to B Store the sum of C and 1 back to C Increase the value in C by 1

program INCREMENT(input,output); varAGE : integer; begin AGE := 14; writeln( ‘ I am ‘,AGE, years old. ’ ); AGE := AGE + 1; writeln( ‘ I will be ‘,AGE, years old ’ ); writeln( ‘ next year. ’ ); end. I am 14 years old. I will be 15 years old next year. What is the output? This is the output

0 How does it work? 14 program INCREMENT(input,output); varAGE : integer; begin AGE := 14; writeln( ‘ I am ‘,AGE, ’ years old. ’ ); AGE := AGE + 1; writeln( ‘ I will be ‘,AGE, ’ years old ’ ); writeln( ‘ next year. ’ ); end. 15 Store the data 14 into AGE Display the first message Put the sum of AGE and 1 in AGE Display the second message. Note that the value of AGE has changed.

program INCREMENT2(input,output); varAGE : integer; begin write( ‘ Please input your age: ’ ); readln(AGE); writeln( ‘ You are ‘,AGE, years old. ’ ); AGE := AGE + 1; writeln( ‘ You will be ‘,AGE, years old ’ ); writeln( ‘ next year. ’ ); end. Please input your age:20 You are 20 years old. You will be 21 years old next year. What is the output if the input is 20? This is the output

Task 1. Write a program which asks the user to input TWO numbers and display the sum of them. Here is the sample output: Please input the first number : 21 Please input the second number: 11 The sum of them is : 32

Task 2. Write a program which asks the user to input THREE numbers and display the mean of them. Here is the sample output: Please input the first number : 5 Please input the second number: 13 Please input the third number: 9 The sum of them is : 9