So now we’re programming What do programs do? Manipulate (process) data Math Read files Write to files Create files.

Slides:



Advertisements
Similar presentations
Operators & Identifiers The Data Elements. Arithmetic Operators exponentiation multiplication division ( real ) division ( integer quotient ) division.
Advertisements

C++ Basics March 10th. A C++ program //if necessary include headers //#include void main() { //variable declaration //read values input from user //computation.
James Tam Getting Started With Pascal Programming How are computer programs created What is the basic structure of a Pascal Program Variables in Pascal.
James Tam Getting Started With Pascal Programming What is the basic structure of a Pascal Program Variables in Pascal Performing input and output with.
1 Key Concepts:  Data types in C.  What is a variable?  Variable Declaration  Variable Initialization  Printf()  Scanf()  Working with numbers in.
Overview of C++ Chapter 2 in both books programs from books keycode for lab: get Program 1 from web test files.
Chapter 2: Introduction to C++.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
Basic Elements of C++ Chapter 2.
Storing data Getting data out Data types Ruby as a foundation Program Variables Click icon to hear comments (the download may take a minute)
Elements of a C++ program 1. Review Algorithms describe how to solve a problem Structured English (pseudo-code) Programs form that can be translated into.
Input & Output: Console
Lesson 1: Introduction to ABAP OBJECTS Todd A. Boyle, Ph.D. St. Francis Xavier University.
1 The CONST definition CONST Pi = , City = ‘New York’; Constant identifiers are used when you do not want the value of an identifier to change why.
Pascal Programming Strings, Arithmetic operators and output formatting National Certificate – Unit 4 Carl Smith.
CS1 Lesson 2 Introduction to C++ CS1 Lesson 2 -- John Cole1.
Procedures and Functions Computing Module 1. What is modular programming? Most programs written for companies will have thousands of lines of code. Most.
Copyright 1999 by Larry Fuhrer. Pascal Programming Getting Started...
3 - Variables Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
CPS120: Introduction to Computer Science
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Pascal language Slides of Omar Al-Nahal. Components of Pascal Language Components of Pascal Language 1. Pascal Character set: - English Letters. - Decimal.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
INFORMATION TECHNOLOGY CSEC CXC 10/25/ PASCAL is a programming language named after the 17th century mathematician Blaise Pascal. Pascal provides.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Introduction to Pascal The Basics of Program writing.
Copyright © 2015, 2012, 2009 Pearson Education, Inc., Publishing as Addison-Wesley All rights reserved. Chapter 2: Introduction to C++
Programming, an introduction to Pascal
1 st semester Basic Pascal Elements อภิรักษ์ จันทร์สร้าง Aphirak Jansang Computer Engineering.
1 homework Due today: hw #1 (mailing list printout) readings to date: chapter 1 and chapter read appendix B (3 pages on DOS) and and.
Variables in Java x = 3;. What is a variable?  A variable is a placeholder in memory used by programmers to store information for a certain amount of.
CNS 1120 Exam 1 Review. Programming Language Elements Syntax = the rules to follow Syntax = the rules to follow Semantics = the meaning of symbols Semantics.
Introducing C++ Programming Lecture 3 Dr. Hebbat Allah A. Elwishy Computer & IS Assistant Professor
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Pascal Programming Today Chapter 11 1 Chapter 11.
INT213-Week-2 Working with Variables. What is variable
Chapter 4 Variables and constants. 4.1 Variables -Use of variables is good programming style -easier to modify -easier for a programmer to understand.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
Repetition. Loops Allows the same set of instructions to be used over and over again Starts with the keyword loop and ends with end loop. This will create.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Variables 1. What is a variable? Something whose value can change over time This value can change more than once over the time period (no limit!) Example:
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
1 More on Readln:numerical values Note: ENTER key counts sends a carriage return and a line feed to the computer definition: “white space”: space, tab,
CMP 131 Introduction to Computer Programming Violetta Cavalli-Sforza Week 5, Lecture 2 (Tuesday)
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Chapter 4 Chapter 4: Variables, Constants, and Arithmetic Operators.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Constants, Data Types and Variables
A variable is a name for a value stored in memory.
Chapter Topics The Basics of a C++ Program Data Types
IGCSE 4 Cambridge Data types and arrays Computer Science Section 2
Chapter 2: Introduction to C++
The CONST definition CONST Pi = , City = ‘New York’;
Basic Elements of C++.
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
Basic Elements of C++ Chapter 2.
2.1 Parts of a C++ Program.
Visual Basic Programming Chapter Four Notes Working with Variables, Constants, Data Types, and Expressions GROUPBOX CONTROL The _____________________________________.
kbkjlj/m/lkiubljj'pl;
Computer Science 1 Get out your notebook
C++ Data Types Data Type
CHAPTER FOUR VARIABLES AND CONSTANTS
Chapter 2: Introduction to C++.
An Introduction to Programming with C++ Fifth Edition
Variables Here we go.
Computer Science 1 Get out your notebook
Computer Science 1 Get out your notebook
Variables and Constants
Presentation transcript:

So now we’re programming

What do programs do? Manipulate (process) data Math Read files Write to files Create files

Good programmers Always Always start with pseudocode See page100

Programs must be named You choose the name It must be one word follow with a semi-colon Example: Program First_Program ;

Next, type program comments Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************)

Next, declare any constants Constants do not change value Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************) CONST Multiplier = 5;

Next, declare any variables Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************) VAR Fname : String[15]; Lname : String[25]; Sum, X, Y : Integer;

String Variables Contain alpha-numeric data Are 256 bytes in size unless declared –Use [ ] to declare smaller size

Char One byte only in size Byte Either True or False

Integers vs Real Whole numbers Legal values of - 32,768 to 32,767 Use LongInt for larger numbers +, -, *, div, MOD Must have decimals Can be used for exponents Maximum value determined by computer memory +, -, *, /

Integer vs Real Real Integer

Implications Integers variables can be assigned to Real Variables Real variables can not be assigned to Integer variables

Next Code must start with Begin and finish with End. Program First_Program; (***********************************) (* Program: First.pas *) (* Programmer: Sue Halfhill *) (* Date: September, 1999 *) (* Description: Program is a point of sale *) (* system *) (***********************************) VAR Fname : String[15]; Lname : String[25]; Sum, X, Y : Integer; Begin ====== End.

Putting values into variables Sum := 2 + 4; FName := ‘John’; Variable Name Assignment Operator Literal or Value being stored

Assigning Values Program First_Time; CONST Multiplier = 5; VAR Fname : String[15]; Lname : String[25]; Sum, Sum, X, Y : Integer; Begin X := 2; Y := 6; Sum := Multiplier(X + Y); Writeln(Sum); End;

How ‘Hard Code’ User Input Read from a file OH- OH

Read Procedure Read(parameter,parameter) Readln(parameter,pararmeter) Reading numeric data vs string data

Read(parameter,parameter) 7 5 Read(A,B) Space is a delimiter (separator) for integer or real data 7 5 With the read procedure the marker does not go to the next line

Readln(parameter,parameter) 7 5 Readln(A, B) With the readln procedure the marker goes to the next line

String Variables vs Read/Readln The size of A and B determine how much is read Dataline : string[9] reads up to 9 characters (letters, spaces, numbers, etc)

Write/Writeln Cursor similar to Read/Readln; Directs data to –screen Writeln(‘What is your name’); –to file Writeln(filename, Sum); –to printer Writeln(lst, ‘What is your name?’);

What’s A Function Black Box Command Result X := Length(Data_line) ;

String Functions

Begin Writeln(‘Please enter your social security number.’) Read(SSNumber); Writeln(‘Please enter your first name and last name.’) Readln(Data_line); X := Length(Data_line); Y := POS(Blank,Data_line); First_Name := COPY(Data_Line,1,y-1); Delete(Data_Line,1,y); X := Length(Data_Line); Last_Name := Data_line; End.

X := Length(Data_line) ; Y := POS(Blank, Data_line) ; First_Name := COPY(Data_line, 1, 5) ; Delete(Data_line, 1, y) ;

X := Length(Data_line); Anatomy of a Function Function Name Parameters Variable which holds value

X := Length(Data_line) ; Sue Halfhill Data_Line X = 12

Y := POS(Blank, Data_line) ; Sue Halfhill Blank Y = 4 2 parameters !!!!

First_Name := COPY(Data_line, 1, 3) ; First_Name Sue Halfhill Data_line } 3 1 Sue 3 parameters !!!!

Delete Delete(Data_line,1,y)

Math Functions Round Trunc Sqr Sqrt Str

STR(X,S) X is an integer or real value X must be formatted. X:4:2 S is a string variable.