DATA AND ABSTRACTION. Today you will learn : How to work with variables How to break a program down Good program design

Similar documents
Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

Programming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs

A Beginner s Guide to Programming Logic, Introductory. Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Full file at

Basics of Java Programming

Ex: If you use a program to record sales, you will want to remember data:

Review: Exam 1. Your First C++ Program. Declaration Statements. Tells the compiler. Examples of declaration statements

CSc 10200! Introduction to Computing. Lecture 2-3 Edgardo Molina Fall 2013 City College of New York

C/C++ Programming for Engineers: Working with Integer Variables

Lecture 3 Tao Wang 1

9/5/2018. Overview. The C Programming Language. Transitioning to C from Python. Why C? Hello, world! Programming in C

More Programming Constructs -- Introduction

The C Programming Language. (with material from Dr. Bin Ren, William & Mary Computer Science)

Basic operators, Arithmetic, Relational, Bitwise, Logical, Assignment, Conditional operators. JAVA Standard Edition

Chapter 2: Introduction to C++

Chapter 2: Special Characters. Parts of a C++ Program. Introduction to C++ Displays output on the computer screen

9/10/10. Arithmetic Operators. Today. Assigning floats to ints. Arithmetic Operators & Expressions. What do you think is the output?

Information Science 1

DaMPL. Language Reference Manual. Henrique Grando

Section we will not cover section 2.11 feel free to read it on your own

Introduction to TURING

Course Outline. Introduction to java

LECTURE 3 C++ Basics Part 2

GO MOCK TEST GO MOCK TEST I

3. Java - Language Constructs I

Fundamentals of Programming CS-110. Lecture 2

Basic Operations jgrasp debugger Writing Programs & Checkstyle

(I m not printing out these notes! Take your own.)

BEGINNING PROBLEM-SOLVING CONCEPTS FOR THE COMPUTER. Chapter 2

Accelerating Information Technology Innovation

Information Science 1

CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

Operators. Lecture 3 COP 3014 Spring January 16, 2018

A complex expression to evaluate we need to reduce it to a series of simple expressions. E.g * 7 =>2+ 35 => 37. E.g.

I Internal Examination Sept Class: - BCA I Subject: - Principles of Programming Lang. (BCA 104) MM: 40 Set: A Time: 1 ½ Hrs.

3. Except for strings, double quotes, identifiers, and keywords, C++ ignores all white space.

Hello, World and Variables

Page. No. 1/15 CS201 Introduction to Programmming Solved Subjective Questions From spring 2010 Final Term Papers By vuzs Team

CS313D: ADVANCED PROGRAMMING LANGUAGE

COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

Chapter 2: Using Data

Unit 3. Constants and Expressions

CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CS/IT 114 Introduction to Java, Part 1 FALL 2016 CLASS 8: SEP. 29TH INSTRUCTOR: JIAYIN WANG

Visual C# Instructor s Manual Table of Contents

Objectives. Chapter 2: Basic Elements of C++ Introduction. Objectives (cont d.) A C++ Program (cont d.) A C++ Program

Creating a C++ Program

BASIC ELEMENTS OF A COMPUTER PROGRAM

COMP Primitive and Class Types. Yi Hong May 14, 2015

Chapter 2: Basic Elements of C++

Chapter 3: Operators, Expressions and Type Conversion

Chapter 2: Basic Elements of C++ Objectives. Objectives (cont d.) A C++ Program. Introduction

Programming for Engineers Iteration

1. What type of error produces incorrect results but does not prevent the program from running? a. syntax b. logic c. grammatical d.

Preview from Notesale.co.uk Page 6 of 52

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

CMSC201 Computer Science I for Majors

Assoc. Prof. Dr. Marenglen Biba. (C) 2010 Pearson Education, Inc. All rights reserved.

Chapter 2 Working with Data Types and Operators

Microsoft Visual Basic 2005: Reloaded

The C++ Language. Arizona State University 1

DATA TYPES AND EXPRESSIONS

Lesson 02 Data Types and Statements. MIT 11053, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

CMPT 125: Lecture 3 Data and Expressions

Computers Programming Course 6. Iulian Năstac

C: How to Program. Week /Mar/05

Introduction to Programming EC-105. Lecture 2

Expressions and Casting. Data Manipulation. Simple Program 11/5/2013

Lecture 2: Variables and Operators. AITI Nigeria Summer 2012 University of Lagos.

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

WEEK 4 OPERATORS, EXPRESSIONS AND STATEMENTS

COMP-202: Foundations of Programming. Lecture 5: More About Methods and Data Types Jackie Cheung, Winter 2016

CS Kangmei Yang. Page 1

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

Chapter 2 Basic Elements of C++

The Arithmetic Operators. Unary Operators. Relational Operators. Examples of use of ++ and

The Arithmetic Operators

GO - OPERATORS. This tutorial will explain the arithmetic, relational, logical, bitwise, assignment and other operators one by one.

Expressions and Casting

H192 Midterm 1 Review. Tom Zajdel

2.1. Chapter 2: Parts of a C++ Program. Parts of a C++ Program. Introduction to C++ Parts of a C++ Program

Full file at

Chapter 2: Using Data

REVIEW. The C++ Programming Language. CS 151 Review #2

Copy: IF THE PROGRAM or OUTPUT is Copied, then both will have grade zero.

MODULE 02: BASIC COMPUTATION IN JAVA

Fundamentals. Fundamentals. Fundamentals. We build up instructions from three types of materials

Chapter 2 - Introduction to C Programming

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 9 C++

IT 374 C# and Applications/ IT695 C# Data Structures

Unit 3, Lesson 2 Data Types, Arithmetic,Variables, Input, Constants, & Library Functions. Mr. Dave Clausen La Cañada High School

Chapter 3 Syntax, Errors, and Debugging. Fundamentals of Java

Lesson 02 Data Types and Statements. MIT 12043, Fundamentals of Programming By: S. Sabraz Nawaz Senior Lecturer in MIT Department of MIT FMC, SEUSL

2. Numbers In, Numbers Out

Reserved Words and Identifiers

CIS 110: Introduction to Computer Programming

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Decisions, Decisions. Testing, testing C H A P T E R 7

Transcription:

DATA AND ABSTRACTION Today you will learn : How to work with variables How to break a program down Good program design

VARIABLES Variables are a named memory location Before you use a variable you must declare it A declaration is a statement that provides a data type and an identifier for the variable Declaring a variable with a starting value is called initializing the variable Declaration Examples num mysalary num yoursalary = 14.55 String myname String yourname = Julian

VARIABLES CONTINUED NAMING CONVENTIONS All programming languages have rules for naming variables. Most generally consist of letters and numbers. Symbols maybe be allowed in special circumstances Choose descriptive names of a reasonable length Camel Casting to make multiple words seem as one word. num hourlywage DATA TYPES num Numeric values Integers and floating point decimals Strings Collection of characters char Single character boolean True or False value Every language has its own set of data types it uses. These are some of the most common

TWO TRUTHS AND A LIE 1. A variable s data type describes the kind of values the variable can hold and the types of operations that can be performed with it 2. If name is a string variable, then the statement set name = Ed is valid 3. If salary is a numeric variable, then the statement set salary = 12.50 is valid In this statement the salary is set as a string variable not numeric. Remove the quotation marks for it to be a numeric value

VARIABLE ASSIGNMENTS This is an assignment statement set myanswer = mynumber * 2 The = (equal sign) is an assignment operator It has right to left associativity The expression on the right is evaluated first then assigned to the memory address the named variable on the left references It is an example of a binary operator It requires two operands, one on each side of it

ARITHMETIC OPERATIONS Most programming languages use the standard arithmetic operators + (plus sign) Addition - (minus sign) Subtraction *(asterisk) Multiplication / (division) division Some languages have different interpretations of some of these / real division // integer division % remainder division The order of operations is the same as you know from your math classes PEMDAS

TWO TRUTHS AND A LIE 1. The assignment operator always operates from right to left; programmers would say it has right to left associativity 2. The operand to the right of an assignment operator must be a name that represents a memory address 3. The following adds 5 to a variable name points: points = points + 5 The operand to the left of the assignment operator must be a variable

MODULARIZATION Programmers often break up a project in to smaller more reasonable parts These parts are often called modules, methods, function, or subroutines This allows many programmers to work on a project (reduces your work) This allows you to reuse your work This also makes your work more reliable Modularization provides for the idea of Abstraction Process or paying attention to the important ideas while ignoring nonessential details

ABSTRACTION EVERY DAY Think about what you have done today and share it with someone or the class Try to explain it in every little detail WITH ABSTRACTION Got dressed Cleaned myself up Ate breakfast Drove to school WITHOUT ABSTRACTION Picked out pants, shirt and socks Put on pants Put on shirt Put on socks Walked to bathroom

TWO TRUTHS AND A LIE 1. Modularization eliminates abstraction, a feature that makes programs more confusing 2. Modularization makes it easier for multiple programmers to work on a project 3. Modularization allows you to reuse your work more easily Modularization promotes abstraction and makes large projects easier to understand and program

MODULARIZING A PROGRAM Programs usually consist of a main program which dictates the basic steps of the program, or the mainline logic This main program access modules that provide more refined details for actions of the program Modules can access or call other modules to make the programming logic clear and easy to use

WHAT MAKES A MODULE? A header includes an identifier and any other necessary information the module needs to execute A body these are the executable statements of the module A return statement marks the end of the module and identifies the point at which control returns to the mainline logic Predefined Process or Module Symbols

MODULARIZING A BILLING PROGRAM

BILLING PROGRAM PART 2 Each module is like a small program They can declare variable, perform actions, check conditions, iterate, and return information Variables declared in a module can only be used in that module We say they are local variables While variable declared outside a module can be used in any module These are global variables Where a variable can be seen or used is known as the variables scope

COMPLEX PROGRAMS Many programs can be large and complex in terms of their overall objective Breaking them into modules makes it easier, but tracking them can be complex as well A hierarchy chart may help with these complexities

TWO TRUTHS AND A LIE 1. You can use a hierarchy chart to illustrate modulus relationships 2. A hierarchy chart tells you what tasks are to be performed within a module 3. A hierarchy chart tells you only which modules call other modules A hierarchy chart tells you nothing about the tasks that are to be performed in a module. It only shows the number of modules and which call each module

FEATURES OF GOOD DESIGN Programming comments written explanations that are not part of program logic but serve as documentation for the readers of the program In pseudocode we often use to forward slashes to begin comments In a flow chart we use an annotation symbol

FEATURES OF GOOD DESIGN Names of variables and modules should be self-documenting Utilize camel casting to display multiple words as one Utilize temporary variables when solving complex problems Use clear and direct prompts when getting user input Echo (display) the input users submitted so they can be reminded of their input