Chapter 2 Modular Programs with Calculations and Strings

Slides:



Advertisements
Similar presentations
Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
Advertisements

Chapter 3 – Fundamental Statements
Computer Programming w/ Eng. Applications
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.
Variables and I/O. Types Strings –Enclosed in quotation marks –“Hello, World!” Integers –4, 3, 5, 65 Floats –4.5, 0.7 What about “56”?
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Basic Elements of C++ Chapter 2.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
1 © 2000 John Urrutia. All rights reserved. Qbasic Constructing Qbasic Programs.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
1 CSC103: Introduction to Computer and Programming Lecture No 6.
Input, Output, and Processing
1 INTRODUCTION TO PROBLEM SOLVING AND PROGRAMMING.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
1 © 2000 John Urrutia. All rights reserved. Qbasic Input, Calculations and Functions.
Lecture 2: Introduction to C Programming. OBJECTIVES In this lecture you will learn:  To use simple input and output statements.  The fundamental data.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Microsoft Visual Basic 2005: Reloaded Second Edition Chapter 3 Variables, Constants, Methods, and Calculations.
Exam 1 Review Instructor – Gokcen Cilingir Cpt S 111, Sections 6-7 (Sept 19, 2011) Washington State University.
Introduction to Computer Programming
Computing with C# and the.NET Framework Chapter 2 C# Programming Basics ©2003, 2011 Art Gittleman.
Variables & Function Calls. Overview u Variables  Programmer Defined & Intrinsic  Data Types  Calculation issues u Using Functions  The val() function.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Chapter 2 Variables.
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Three Memory Locations and Calculations.
Hungarian Notation A must in this course Every object used MUST be renamed including the form(s) using the following rules Form  frmFormName E.g. frmTemperature.
Data Types and Conversions, Input from the Keyboard CS303E: Elements of Computers and Programming.
Variables Hold information that may be manipulated, used to manipulate other information or remembered for later use A storage location in memory (RAM)
Introduction to Java Applications Part II. In this chapter you will learn:  Different data types( Primitive data types).  How to declare variables?
Data Types and Conversions, Input from the Keyboard If you can't write it down in English, you can't code it. -- Peter Halpern If you lie to the computer,
 Constants A constant is a fixed value of a data type that cannot be changed Integer Constants Whole numbers → Do not have decimal points Examples: 83.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Chapter 3: Introducing the Microsoft.NET Framework and Visual Basic.NET Visual Basic.NET Programming: From Problem Analysis to Program Design.
Chapter 4: Variables, Constants, and Arithmetic Operators Introduction to Programming with C++ Fourth Edition.
Slide 1 Chapter 3 Variables  A variable is a name for a value stored in memory.  Variables are used in programs so that values can be represented with.
TK1913 C++ Programming Basic Elements of C++.
Chapter 2 Variables.
Chapter Topics The Basics of a C++ Program Data Types
Topics Designing a Program Input, Processing, and Output
Arithmetic operations and operators, converting data types and formatting programs for output. Year 11 Information Technology.
Chapter 6 JavaScript: Introduction to Scripting
BASIC ELEMENTS OF A COMPUTER PROGRAM
Visual Basic Variables
Data Types and Conversions, Input from the Keyboard
Line Continuation, Output Formatting, and Decision Structures
Basic Elements of C++.
Computing with C# and the .NET Framework
Java Programming: From Problem Analysis to Program Design, 4e
Basic Elements of C++ Chapter 2.
Variables In programming, we often need to have places to store data. These receptacles are called variables. They are called that because they can change.
Line Continuation, Output Formatting, and Decision Structures
Chapter 2: Basic Elements of Java
CIS16 Application Development Programming with Visual Basic
Chapter 2 Variables.
Reading Input from the Keyboard
Rocky K. C. Chang September 18, 2018 (Based on Zelle and Dierbach)
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Computing in COBOL: The Arithmetic Verbs and Intrinsic Functions
Topics Introduction to Functions Defining and Calling a Function
Introduction to Java Applications
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Chapter 2 Variables.
DATA TYPES AND OPERATIONS
Data Types and Arithmetic in C
Presentation transcript:

Chapter 2 Modular Programs with Calculations and Strings QBASIC Chapter 2 Modular Programs with Calculations and Strings

QBASIC Character Set Letters: a-z and A-Z Digits: 0-9 Blank: the space character ( ) Special characters: + - * / \ = < > . , ’ ” ( ) : ; ^ _ $ # ? ! % &

Qbasic Keywords A keyword has a predefined meaning within Qbasic. Examples: LET END REM PRINT

Constants & Variables Constants Variables “literal” values that cannot be changed May or may not have a label Variables Value can be changed Must be referenced by a label

QBASIC Constants Numeric Constants Can only contain these 13 characters: + - . 0 1 2 3 4 5 6 7 8 9 If not identified with a label they are called a “literal” Can not have + - internal or trailing Can only have one decimal

Numeric Constants 123 +234 -456 +123.456 .678 amount = 345678.1234567

Labels A name assigned to represent a variable. Should be meaningful. Must start with a letter Should be meaningful. Can have periods imbedded. Should carry the data type.

The LET statement Assigns a value to a variable. Can be Explicit or Implicit LET variable.Name = value LET my.nbr! = 0 LET my.str$ = “This is my string” LET tot! = tot! + purchases! + taxes!

QBASIC Data Types All data in QBASIC is identified by a data type Numbers % – Integer -32,768 to 32,767 & – Long integer -2,147,483,648 to 2,147,483,647 ! – Single precision 7 digit (1038 ) (Default data type) # – Double precision 15 digit (10308 )

QBASIC Data Types Strings: $ - data type identifier Any set of characters enclosed in double quotation marks. “ ” Maximum of 14,656 Characters

Arithmetic Operators * – Multiplication ^ – Exponentiation / – Division \ – Integer Division MOD – Modula (remainder) + – Addition - – Subtraction

Calculations Order of operations (precedence) ^ (Power) +, - (Unary) *, /, \, MOD, +, - (Arithmetic) <, <=, >, >=, <>, = (Relational) Boolean operators NOT, AND, OR, XOR, EQV, IMP

Some math Examples LET A% = 100 LET B% = 4 PRINT A% * B% PRINT A% + B% - B% * 4 MOD 3 400 PRINT A% + B% - B% * (4 MOD 3) 103 100

Functions A function is a set of instructions that perform a specific task. FunctionName (argument1, …) Built-in & User defined X$ = INT(X)

Built-in Functions Conversions System MKI$ - CVI, MKD$ - CVD CHR$ - ASC CINT(), CSGN(), CDBL() System DATE$ - TIME$

The INPUT statement INPUT variable-list INPUT “prompt ” ; or , variable-list prompt – any valid string ; – Question mark generated , – No Question mark generated variable-list – mix and match separate with commas

Using INPUT to prompt users INPUT “Want a date”; date.in Want a date?__ INPUT “Enter date”, date.in Enter date __

Modular Programming As we have seen previously: Heirarchy Charts allow us to break large problems into smaller more manageable blocks that perform a specific unit of work Each of these “blocks” can be represented as a “subroutine”. A fixed combination of instructions that can be re-used.

Subroutines A subroutine is identified with a label just like variables. Subroutines are “called” from someplace in the program using GOSUB and return to the statement following the call using the RETURN statement.

GOSUB label.name GOSUB my.summation PRINT “The sum is “; x% END my.summation: INPUT “Number Please:”, y% x%=(y-1)+(y-2)+(y-3)… RETURN

RETURN [ label.name] Returns to caller by default Command following the GOSUB gets control Returns to label if specified Should only be used under special circumstances.

Hierarchy Chart Score Average Program Input Name & Scores Calculate Average Output Name & Average

Flowchart Start End Return Start Return Return Return End Input name & scores Calculate Average Output Name & Average End Input Scores Write Output Input Name Input 3 Scores Return Avg1 = (3 Scores)/3 Average = Avg1 Round Print Name & Average Start Input Scores Calculate Average Write Output Input name & scores Input Name Avg1 = (3 Scores)/3 Print Name & Average Input 3 Scores Return Calculate Average Average = Avg1 Round Return Output Name & Average Return End

Code MAIN: GOSUB Input.Name.Scores GOSUB Calculate.Average GOSUB Write.Output END.MAIN: END Input.Name.Scores: INPUT “Enter Name: “ , Name$ INPUT “Enter Score 1: “ , Score1% INPUT “Enter Score 2: “ , Score2% INPUT “Enter Score 3: “ , Score3% RETURN Calculate.Average: Avg=INT((Score1%+ Score2%+ Score3%)/3)):RETURN Write.Output: PRINT Name$; ” – “; Avg: RETURN