Introduction to Programming PDF
Document Details
Uploaded by FairSugilite8913
NCU
Vincent Richards
Tags
Summary
These lecture notes provide an introduction to programming concepts. It covers topics like variables, data types, and operators.
Full Transcript
1 INTRODUCTION TO PROGRAMMING Instructor: Vincent Richards Office: CIS Dept. Office hrs.: MW(9:30-10:50, 5:00-6:20), TUTH (9:30-10:50, 5:00-6:20) by appt E-mail: [email protected] Tel#: 963-7285 Website: http://lms.ncu.edu.jm ...
1 INTRODUCTION TO PROGRAMMING Instructor: Vincent Richards Office: CIS Dept. Office hrs.: MW(9:30-10:50, 5:00-6:20), TUTH (9:30-10:50, 5:00-6:20) by appt E-mail: [email protected] Tel#: 963-7285 Website: http://lms.ncu.edu.jm 2 System Development Life Cycle (SDLC) Is a series of well-defined steps that should be followed when a system is created or changed. Represents the big picture of what happens during system creation or modification. The System Development Life Cycle is comprised of 6 steps, namely: Analyze the current system Define the new system requirements Design the new system Develop the new system Implement the new system Evaluate the new system 3 The Program Development Cycle (PDC) The fourth step of the SDLC (Development of the new system) is comprised of a series of well-defined steps called the Program Development Cycle. A programmer carries out the steps in the PDC. What is a Program? A program is an organized lists of instructions that, when executed, causes the computer to behave in a predetermined manner. Without programs, computers are useless. What is Programming? Programming is instructing a computer to do something for you with the help of a programming language 4 Identifiers Manipulation of data is a basic feature of a computer’s abilities. This data must be present in the memory (RAM) of the computer for operations to be done on it. The computer accesses this data via memory addresses. Identifiers are required to keep track of these memory addresses (receptacles, data containers). Identifiers allow us humans to give these ‘data containers’ more meaningful names. This makes the task of manipulation of data more manageable. 5 Identifiers Internally the computer sees a HEXIDECIMAL label representing the memory location, we see familiar titles / labels such as YEAR, FNAME, AGE, which we are able to put into some context. 6 Variables are identifiers whose value can be changed within a program have the following attributes a logical name (i.e. FNAME meaning Christian Name. Names MUST begin with a letter and NOT contain certain restricted characters/symbols) a data type (real, integer, string, character, boolean, date) a size or length 7 Variables are identifiers whose value can be changed within a program have the following attributes a logical name (i.e. FNAME meaning Christian Name. Names MUST begin with a letter and NOT contain certain restricted characters/symbols) a data type (real, integer, string, character, boolean, date) a size or length Constants are identifiers whose value cannot be changed within the program 8 Literal (Literal Constant) are values taken at face value example : Let CIRC = 2 * PI * R CIRC is a variable 2 is a literal PI is a constant R is a variable 9 Basic Data Types Real / Numeric -values from the set of real numbers (eg. -12.348, 0, 199.0, 1654.984034) Integers -values from the set of whole numbers (-3075, -2, 0, 23, 94754) Character -value from a set of symbols which may be represented on the computer (a single member of the ASCII set of characters) enclosed within quotes. I.e. “A”, “B”, “c”, “#”, “5”, “\”, “&” String -a combination of one or more characters enclosed in quotes. I.e. “123”, “Lisa”, “lj*&^#$$” 10 Basic Data Types Real / Numeric -values from the set of real numbers (eg. -12.348, 0, 199.0, 1654.984034) Integers -values from the set of whole numbers (-3075, -2, 0, 23, 94754) Character -value from a set of symbols which may be represented on the computer (a single member of the ASCII set of characters) enclosed within quotes. I.e. “A”, “B”, “c”, “#”, “5”, “\”, “&” String -a combination of one or more characters enclosed in quotes. I.e. “123”, “Lisa”, “lj*&^#$$” 11 Operators, operands, Expressions and statements Operators - the symbols used in processing Arithmetic: (+,-, / , *, =) Relational (>, =, ) Logical (AND, OR, NOT) Operands - Can be a variable, a constant, or a literal constant. - What the operator operates on. 12 Expressions - consists of operators and operands or an identifier by itself - it evaluates to a value - the values are drawn from the data types - arithmetic expressions can be assigned to a variable Statement - a complete instruction - by itself it accomplishes a task - can be derived from expressions 13 Evaluating expressions Arithmetic - follows the general rule of mathematical precedence i.e. ( ) then powers eg. Xy, then * and /, then + and - Logical - evaluated to either True [T] of False [F] - the logical operators are used to connect the relational expressions 14 Truth Tables The logical operators are used in compound conditions. Example: If SalesAmt > 10000 AND SalesPerson = “Bill” then Bonus = AveSales * 2 else Bonus = AveSales * 1.5 Endif Truth tables illustrate the outcome of combining conditions using the logical operators stated. I.e. say that X and Y are conditions which may be either True or False 15 Logical AND A logical AND is True if and only if both X and Y are True Logical OR (inclusive) A logical OR is True if any of both X and Y are True, including both being true. 16 Logical NOT A logical NOT negates or reverses a condition such that True becomes False, and False becomes True. Flowcharts were the first design tool to be widely used, but unfortunately they do not reflect some of the concepts of structured programming very well. Pseudocode, on the other hand, is a newer tool and has features that make it more reflective of the structured concepts. The drawback is that the narrative presentation is not as easy to understand and/or follow. Rules for Variable Names Begin with lowercase letter Contain no spaces Additional words begin with capital Unique names within code Consistent use of names Language Independence Resist the urge to write in whatever language you are most comfortable with, in the long run you will save time. Remember you are describing a logic plan to develop a program, you are not programming!