Accumulators in Programming

Slides:



Advertisements
Similar presentations
Chapter 04 (Part III) Control Statements: Part I.
Advertisements

Data Types. Every program must deal with data The data is usually described as a certain type This type determines what you can do with the data and how.
Chapter 5 Using Data and COBOL Operators. Initializing Variables When you define a variable in WORKING- STORAGE, you also can assign it an initial value.
PROBLEM SOLVING WITH LOOPS Chapter 7. Concept of Repetition Structure Logic It is a computer task, that is used for Repeating a series of instructions.
Counting Loops.
1 Printing in Python Every program needs to do some output This is usually to the screen (shell window) Later we’ll see graphics windows and external files.
Introduction to Computer Programming - Project 2 Intro to Digital Technology.
Chapter 7: The Repetition Structure Introduction to Programming with C++ Fourth Edition.
Arrays and Loops. Learning Objectives By the end of this lecture, you should be able to: – Understand what a loop is – Appreciate the need for loops and.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
CHAPTER #7 Problem Solving with Loop. Overview Loop logical structure Incrementing Accumulating WHILE/WHILE-END FOR Nested loop Pointer Algorithmic instruction.
List Algorithms Taken from notes by Dr. Neil Moore & Dr. Debby Keen
The Little man computer
Review Array Array Elements Accessing array elements
Chapter 10 Programming Fundamentals with JavaScript
CSE 374 Programming Concepts & Tools
REPETITION CONTROL STRUCTURE
Advanced Excel Topics – Loops
Introduction To Repetition The for loop
Chapter 2 - Introduction to C Programming
Foundations of Programming: Arrays
Programming Mehdi Bukhari.
ECS10 10/10
Loop Structures.
Java for Beginners.
CS 115 Lecture 8 Structured Programming; for loops
Chapter 5: Control Structure
Chapter 5: Looping Starting Out with C++ Early Objects Seventh Edition
Repetition-Counter control Loop
Chapter 2 - Introduction to C Programming
Java Review: Reference Types
Topics Introduction to Repetition Structures
Structured Programming; for loops Taken from notes by Dr. Neil Moore
While loops The while loop executes the statement over and over as long as the boolean expression is true. The expression is evaluated first, so the statement.
Chapter 4 LOOPS © Bobby Hoggard, Department of Computer Science, East Carolina University / These slides may not be used or duplicated without permission.
Arrays, For loop While loop Do while loop
Chapter 10 Programming Fundamentals with JavaScript
Java for Beginners University Greenwich Computing At School DASCO
Chapter 2 - Introduction to C Programming
List Algorithms Taken from notes by Dr. Neil Moore
Winter 2018 CISC101 11/22/2018 CISC101 Reminders
Number and String Operations
Chapter 2 - Introduction to C Programming
Maths Unit 8 – Sequences Picture sequences Number sequences
T. Jumana Abu Shmais – AOU - Riyadh
Algorithm Discovery and Design
CIS 16 Application Development Programming with Visual Basic
Module 4 Loops.
Chapter 6: Repetition Statements
Chapter 2 - Introduction to C Programming
Starting Out with Programming Logic & Design
HYPERTEXT PREPROCESSOR BY : UMA KAKKAR
CISC101 Reminders All assignments are now posted.
For loops Taken from notes by Dr. Neil Moore
GCSE OCR 1 The CPU Computer Science J276 Unit 1
Chapter 9: More About Data, Arrays, and Files
Topics Introduction to Repetition Structures
Chapter 2 - Introduction to C Programming
Winter 2019 CISC101 4/28/2019 CISC101 Reminders
Review of Previous Lesson
LOOPS The loop is the control structure we use to specify that a statement or group of statements is to be repeatedly executed. Java provides three kinds.
OPERATORS in C Programming
Basic 9 Mr. Husch.
Software Development Techniques
This is an introduction to JavaScript using the examples found at the CIS17 website. In previous examples I specified language = Javascript, instead of.
Basic program gives only one quess and then the program ends.
The values to be assigned to the structure members are surrounded by braces and separated by commas. The first value in the list is assigned to the first.
OPERATORS in C Programming
Python Creating a calculator.
Presentation transcript:

Accumulators in Programming Assumes you have knowledge of the assignment operator = and a loop

What is an accumulator? An accumulator is not new syntax, it is just a new way to using the assignment operator It is a logical concept that is used in most languages The general idea is that a variable is given the job of holding the “total” of several values. “Total” is in quotes because it is not always an arithmetic sum, it can be done using many different operations. An accumulator could hold the sum of 10 numbers, the concatenation (“sticking together”) of 5 strings, the product of 15 numbers, etc. An accumulator starts at a known value (like zero), and is changed by “adding” on a different value. The result is stored right back in the same variable.

Calculator Analogy Suppose you wanted to add up a bunch of numbers using a calculator You would first clear the display of the calculator so that it showed a zero. (You usually don’t want previous results mixed in with your total.) You punch in a number and hit the + key The display shows the first number (since it’s the sum of zero and the number) You punch in another number and hit + The display shows the sum of the two numbers entered. You repeat the process until you have entered as many numbers as you needed the sum of. The number in the display is your accumulator.

A Counter – a special form of an accumulator Sometimes you need to know how many times something happens The number of aliens killed The number of numbers read in An accumulator is useful here too You can add a constant term to an accumulator variable If you do, that is called a counter A counter is a specialized form of an accumulator Just changes the accumulator by a constant value Num_count = Num_count + 1 DozenCount = DozenCount + 12