Introduction to Programming / chapter 3 / COM1022

Slides:



Advertisements
Similar presentations
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
Advertisements

Flow Control Analysis & Design Tool: Flowcharts
Chapter 1 - An Introduction to Computers and Problem Solving
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 2 - Problem Solving
ITEC113 Algorithms and Programming Techniques
Chapter 2- Visual Basic Schneider
About the Presentations The presentations cover the objectives found in the opening of each chapter. All chapter objectives are listed in the beginning.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
Copyright 2003 Scott/Jones Publishing Brief Version of Starting Out with C++, 4th Edition Chapter 1 Introduction to Computers and Programming.
ALGORITHMS AND FLOWCHARTS
Computer Programming-1 CSC 111 Chapter 1 : Introduction.
Copyright © 2012 Pearson Education, Inc. Chapter 1: Introduction to Computers and Programming.
Alternate Version of STARTING OUT WITH C++ 4 th Edition Chapter 1 Introduction to Computers and Programming.
Chapter Introduction to Computers and Programming 1.
DCT 1123 Problem Solving & Algorithms
CSC141 Introduction to Computer Programming
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 1: Introduction to Computers and Programming.
PROGRAMMING LANGUAGES Prof. Lani Cantonjos. PROGRAM - set of step-by-step instructions that tells or directs the computer what to do. PROGRAMMING LANGUAGE.
Introduction to Computers (L02) * Hardware * Software * Programming Languages * Three Phase of Program Development * Development and Design Steps * Algorithms.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Overview of Programming and Problem Solving Textbook Chapter 1 1.
Software Life Cycle What Requirements Gathering, Problem definition
Problem Solving Techniques. Compiler n Is a computer program whose purpose is to take a description of a desired program coded in a programming language.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
Flowcharts.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Introduction to Computer Application (IC) MH Room 517 Time : 7:00-9:30pm.
CHAPTER 1 INTRODUCTION 1 st Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
CHAPTER 1 INTRODUCTION 1 st semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
CHAPTER 1 INTRODUCTION 2 nd Semester H King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Introduction to Computer Programming using Fortran 77.
Chapter 1: Introduction to Computers and Programming.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
 Problem Analysis  Coding  Debugging  Testing.
Programming Logic and Design Seventh Edition Chapter 1 An Overview of Computers and Programming.
Chapter 1 Introduction 2nd Semester H
Understand Problem Solving Tools to Design Programming Solutions
Programming Languages
Computer Programming.
Chapter 2- Visual Basic Schneider
ICS103 Programming in C Lecture 1: Overview of Computers & Programming
CS1001 Programming Fundamentals 3(3-0) Lecture 2
PROGRAM CONTROL STRUCTURE
Algorithms and Flowcharts
Lecture 2 Introduction to Programming
ALGORITHM Basic CONCEPTS of Basic Concepts of Algorithm
Introduction to Computer Programming
Algorithm and Ambiguity
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
How to develop a program?
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Chapter 1 Introduction(1.1)
CSC128 FUNDAMENTALS OF COMPUTER PROBLEM SOLVING
Chapter 2- Visual Basic Schneider
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
ICT Gaming Lesson 2.
Basic Concepts of Algorithm
Programming Logic and Design Eighth Edition
Introduction to Programming
Presentation transcript:

Introduction to Programming / chapter 3 / COM1022 PROGRAMMING LIFE CYCLE INTRODUCTION Computer Programming is the art of making a computer do what you want it to do. At the very fundamental level, it consists of issuing a sequence of commands to computers to achieve an objective. A computer program is simply a set of instructions computers follow to perform a specific task. A program to computers is similar to a recipe to cooks to make a dish. It describes the ingredients (Data/Input) and the sequence of steps (Process) needed to convert the ingredients into a dish of food (Result/Output).

HOW CAN WE PROGRAM OUR COMPUTER MACHINE Computational Problem Computational Problem develop develop Program modeling Program modeling encode A Program in a High-Level Language (e.g. C++, JAVA) encode Input Compiler Compiler program automatically produces A machine Language Program A machine Language Program Software Development Using machine language (Low-Level language) Software Development Using a High-Level language

PROGRAMMING LIFE CYCLE The development of the system/program - The general steps programmers go through to develop the system Problem Analysis Program Modeling Coding and Program’s source code Testing and debugging Documentation Maintenance

PROGRAMMING LIFE CYCLE Problem Analysis 1.    Human Problem solving is the logical process of identifying a problem and find out its solution. Users (as human) use intuition, experience, and knowledge to solve the problems. The following scenario illustrates how humans find a solution to a problem

PROGRAMMING LIFE CYCLE Problem Analysis EXAMPLE: Problem: Who get the highest score in class? Data/Input: i. Student name ii. score

PROGRAMMING LIFE CYCLE Problem Analysis Process: Look at the table Find the maximum score by scanning, now you get 65 Look at the left side and you know the student name Suraya. Answer Suraya Result/Output: Suraya

PROGRAMMING LIFE CYCLE Problem Analysis However, if the given data is as below:

PROGRAMMING LIFE CYCLE Problem Analysis By the same processes above, you need to spend more time to find out that Maria has the highest score of 66.

PROGRAMMING LIFE CYCLE Problem Analysis You might be in a worse scenario with the given data below:

PROGRAMMING LIFE CYCLE Problem Analysis Once the table size becomes bigger and bigger, you may need more concentration, with additional tool: notepad and pencil, or calculator to solve this problem. This example exhibits one of the human limitations to work with a large volume of data. It is impractical for humans to solve the massive and complex problem without using tools.

PROGRAMMING LIFE CYCLE Problem Analysis Computer Computers consist of two main components: hardware and software. These two components work collaboratively to carry out tasks users required to accomplish. Hardware is controlled by software, and software is written by humans; therefore, hardware is controlled by humans.

PROGRAMMING LIFE CYCLE Problem Analysis To make computers work effectively, humans (in this case, programmers) must think logically in order to solve the problem. Problem Analysis consists of input, process and output

PROGRAMMING LIFE CYCLE Problem Analysis Define the purpose of the program Identify the problem i. Input ii. Process iii. Output

PROGRAMMING LIFE CYCLE Problem Analysis Input data: a list of the source data provided to the problem. - Gather input data; i. from keyboard ii. from files or disk drives - Define input data type; i. Number ii. Character

PROGRAMMING LIFE CYCLE Problem Analysis Process: a list of actions needed to produce the required output. - Manipulate data to perform information - Process the input data - It is about steps to be taken in order to get the output

PROGRAMMING LIFE CYCLE Problem Analysis Output: a list of the outputs required. - Information - Display the results as output; i. Send it to the screen ii. Write to a file

PROGRAMMING LIFE CYCLE Example 1: Problem: - Create a program to read 10 numbers from keyboard. Program will calculate the average of that numbers. Print the number and the average.

PROGRAMMING LIFE CYCLE Example 1: Problem Analysis: 1. INPUT: 10 number 2. PROCESS: Calculate the average by using the formula; average=total/10 3. OUTPUT: 10 number and average

PROGRAMMING LIFE CYCLE Example 2: Problem: Add three numbers A program is required to read three numbers from a user, add them together, and print their total on the screen.

PROGRAMMING LIFE CYCLE Example 2: By looking at the problem above, you know that the program needs three numbers to be the input and the output is the sum total. Problem Analysis: 1. INPUT: number1, number2, number3 2. PROCESS: add numbers together 3. OUTPUT: total

PROGRAMMING LIFE CYCLE Example 3: Problem: - Grading system has a following policy: Score from 0 – 39; the grade is “F” Score from 40 – 49; the grade is “D” Score from 50 – 64; the grade is “C” Score from 65 – 79; the grade is “B” Score from 80 - 100; the grade is “A” The program accepts “Score” input (score must be 0 – 100), then displays the grade that the student earned.

PROGRAMMING LIFE CYCLE Example 3: Problem Analysis: 1. INPUT: score 2. PROCESS: get the grade for the score base on policy 3. OUTPUT: grade

PROGRAMMING LIFE CYCLE Exercise :  1. The factorial formula is “n! = 1 x 2 x 3 x … x n” (where n is any whole number)Write the program that accepts the input “n” and output the factorial value. 2. Find average score of “n” students in a class. The program will accept the input “n” from the user. 3. Find the minimum score of 10 students in a class. 4. Finding the total of 1 + 2 + 3 + 4 + 5 + … + n (Where n can be any whole number).Program will accept “n” from the user.

PROGRAMMING LIFE CYCLE Problem: Teacher, I want to go home

PROGRAMMING LIFE CYCLE Problem: Teacher, I want to go home Problem Analysis: Input; student particular Process; Felo give approval Output; approval

PROGRAMMING LIFE CYCLE Problem Analysis: Input; student particular Process; Felo give approval Output; approval Algorithm: Start Input student particular Felo give the approval 4. If yes, approve If not, not approve Student get the 7. End Problem: Teacher, I want to go home

PROGRAMMING LIFE CYCLE Problem Analysis: Input; student particular Process; Felo give approval Output; approval Program: #include <stdio.h> Main() { char name[]; char…….; cin>>name; cin>>…..; if ……….; else ……..; cout<<approval; return 0; } Algorithm: Start Input student particular Felo give the approval 4. If yes, approve If not, not approve Student get the 7. End Problem: Teacher, I want to go home

PROGRAMMING LIFE CYCLE Problem Analysis: Input; student particular Process; Felo give approval Output; approval Compilation: 01000001001111111 00000000111111101 01010001010101101 11111010101010101 01101001001010010 11101101001011010 11101010101010101 01010101010100101 10101110100101011 01010101001010110 01010101010010101 Algorithm: Start Input student particular Felo give the approval 4. If yes, approve If not, not approve Student get the 7. End Program: #include <stdio.h> Main() { char name[]; char…….; cin>>name; cin>>…..; if ……….; else ……..; cout<<approval; return 0; } Problem: Teacher, I want to go home

PROGRAMMING LIFE CYCLE Program Modeling creating model of solution. algorithm, the step-by-step instruction to solve a problem/accomplish a task, then the program will be written based on the algorithm using a programming language. There are many ways to represent an algorithm; however two techniques commonly used are pseudo code and flowchart.

PROGRAMMING LIFE CYCLE Program Modeling 1.  Pseudo code Pseudo code is Structured English used to represent an algorithm. It is easy for both users and programmers to read and write algorithms regardless of the programming experience. There is no standard pseudo code but we should follow some conventional rules below:   i. Statements are written in simple English. ii. Each statement is written on a separate line.

PROGRAMMING LIFE CYCLE Program Modeling iii. Statements are starting with the text START. iv. Statements are ending with the text END. Example: START Statement1 Statement2 Statement3 END

PROGRAMMING LIFE CYCLE Example 1: Problem: - Create a program to read 10 numbers from keyboard. Program will calculate the average of that numbers. Print the number and the average.

PROGRAMMING LIFE CYCLE Example 1: Problem Analysis: 1. INPUT: 10 number 2. PROCESS: Calculate the average by using the formula; average=total/10 3. OUTPUT: 10 number and average

PROGRAMMING LIFE CYCLE Example 1: Program Modeling: Pseudo code 1. START 2. Declare a name for every value to be input -NO1, NO2, NO3, NO4, NO5, NO6, NO7, NO8, NO9, NO10, Declare a name for the value of sum -TOTAL Declare a name for a value of average -AVERAGE Set all = 0 3. INPUT 10 numbers 4. Calculate the total by using the formula; TOTAL=NO1+NO2+… NO10

PROGRAMMING LIFE CYCLE Example 1: Program Modeling: Pseudo code 5. Calculate the average by using the formula; AVERAGE=TOTAL/10 6. PRINT 10 numbers and AVERAGE 7. END

PROGRAMMING LIFE CYCLE Example 2: Problem: Add three numbers A program is required to read three numbers from a user, add them together, and print their total on the screen.

PROGRAMMING LIFE CYCLE Example 2: Problem Analysis: 1. INPUT: number1, number2, number3 2. PROCESS: add numbers together 3. OUTPUT: total

PROGRAMMING LIFE CYCLE Example 2: Program Modeling: Pseudo Code 1. START 2. Declare num1, num2, num3 and Total Set num1, num2, num3 and Total = 0 3. INPUT num1, num2, num3 4. Add numbers together by using the formula; Total=num1+num2+ num3 5. PRINT total 6. END

PROGRAMMING LIFE CYCLE Exercise :  1. The factorial formula is “n! = 1 x 2 x 3 x … x n” (where n is any whole number)Write the program that accepts the input “n” and output the factorial value. 2. Find average score of “n” students in a class. The program will accept the input “n” from the user. 3. Find the minimum score of 10 students in a class. 4. Finding the total of 1 + 2 + 3 + 4 + 5 + … + n (Where n can be any whole number).Program will accept “n” from the user.

PROGRAMMING LIFE CYCLE Program Modeling 2.  Flowchart A graphic help us describe the logic of our algorithm Each type of operation, e.g. input, output, calculation/assignment, test a condition (to prepare for a jump), etc.. is represented by a symbol Symbols are connected by arrows to represent the order of the operations Flowchart are useful during algorithm design A flowchart can be relatively easily translated to a programming language

PROGRAMMING LIFE CYCLE In an algorithm we specify the computation operations (arithmetic, logical, data input, data output) to be done, and their sequence. Each type of computation operation is denoted by a special symbol in the flowchart language Symbols are connected by arrows to represent the order of the operations (sequence)

PROGRAMMING LIFE CYCLE A flowchart is a graphical diagram that define the “flow” of a program using a series of standard geometric symbols and lines, which are connected according to the logic of the algorithm. There are a lot of symbols used in flowcharting but the common five are: Terminal symbol Calculation symbol Input/Output symbol

PROGRAMMING LIFE CYCLE Decision or condition Testing symbol Branch symbol Data flow symbol

Flowcharts Symbols PROGRAMMING LIFE CYCLE Terminal: Start/End Every algorithm starts somewhere, and terminates somewhere Every flowchart must have one start symbol and one end symbols A start symbol denotes the start of the algorithm When an end symbol is encountered this indicates the algorithm has terminated. START Statement 1 Statement 2 Statement 3 END

Flowcharts Symbols PROGRAMMING LIFE CYCLE Calculation (square or rectangle) You use it to specify a calculation, e.g. arithmetic expression Examples: x = z+y a = pi * r*r z = z + 1 (add one to the current value of z and make that the new value of z) c = SQRT(x*x+y*y) x,z,y,a,c,pi, and r above can be thought of as nick names X = z + y A = A + 1

Flowcharts Symbols PROGRAMMING LIFE CYCLE Input/Output Use it to specify an input or an output operation By an input operation we mean a read operation of data from a peripheral device to Main Memory (e.g. user typing on a keyboard, or reading a byte from the Modem) By an output operation we mean a write operation of data to a peripheral device from Main Memory (e.g. data displayed on the monitor, or sent to the printer) Examples: Read a value for the radius,r, from the keyboard; print value of the area, a, on the screen input a Print a

Flowcharts Symbols PROGRAMMING LIFE CYCLE Decision or condition Testing (Diamond) Use it to specify a condition to be tested. Based on the condition being true or false the next operation will be determined A decision is composed of : A condition An operation to be done if condition is true An operation to be done if condition is false We use decisions to enable repeating a set of operations multiple times; we call this construct a loop. Decision No Statement 2 yes Statement 1

PROGRAMMING LIFE CYCLE Example 1: Problem: - Create a program to read 10 numbers from keyboard. Program will calculate the average of that numbers. Print the number and the average.

PROGRAMMING LIFE CYCLE Example 1: Problem Analysis: 1. INPUT: 10 number 2. PROCESS: Calculate the average by using the formula; average=total/10 3. OUTPUT: 10 number and average

PROGRAMMING LIFE CYCLE Example 1: Program Modeling: Pseudo code 1. START 2. Declare a name for every value to be input -a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 Declare a name for the value of sum -TOTAL Declare a name for a value of average -AVERAGE Set all = 0 3. INPUT 10 numbers 4. Calculate the total by using the formula; TOTAL=a1+a2+… a10

PROGRAMMING LIFE CYCLE Example 1: Program Modeling: Pseudo code 5. Calculate the average by using the formula; AVERAGE=TOTAL/10 6. PRINT 10 numbers and AVERAGE 7. END

PROGRAMMING LIFE CYCLE Example 1: Program Modeling: Flowchart START Average = Total/10 Set a1,a2,a3,a4,a5,a6, A7, a8, a9, a10 = 0 Set Total, Average = 0 PRINT a1,a2,a3,a4, a5,a6,a7,a8,a9,a10, Average INPUT a1,a2,a3,a4,a5, a6,a7,a8,a9,a10 Total = a1+a2+a3+a4+a5+ a6+a7+a8+a9+a10 END

PROGRAMMING LIFE CYCLE Example 2: Problem: Add three numbers A program is required to read three numbers from a user, add them together, and print their total on the screen.

PROGRAMMING LIFE CYCLE Example 2: Problem Analysis: 1. INPUT: number1, number2, number3 2. PROCESS: sum all the number together 3. OUTPUT: total

PROGRAMMING LIFE CYCLE Example 2: Program Modeling: Pseudo Code 1. START 2. Declare num1, num2, num3 and Total Set num1, num2, num3 and Total = 0 3. INPUT num1, num2, num3 4. Add numbers together by using the formula; Total=num1+num2+ num3 5. PRINT Total 6. END

PROGRAMMING LIFE CYCLE Example 1: Program Modeling: Flowchart START Total = num1 + num2 + num3 Set num1,num2,num3 = 0 Set Total = 0 PRINT Total INPUT num1, num2, num3 END

PROGRAMMING LIFE CYCLE Exercise :  1. The factorial formula is “n! = 1 x 2 x 3 x … x n” (where n is any whole number)Write the program that accepts the input “n” and output the factorial value. 2. Find average score of “n” students in a class. The program will accept the input “n” from the user. 3. Find the minimum score of 10 students in a class. 4. Finding the total of 1 + 2 + 3 + 4 + 5 + … + n (Where n can be any whole number).Program will accept “n” from the user.