CS101: Introduction to Computer programming

Slides:



Advertisements
Similar presentations
4 Control Statements: Part 1.
Advertisements

ALGORITHMS AND FLOWCHARTS
Control Structures Selections Repetitions/iterations
CS 240 Computer Programming 1
Chapter 11 Describing Process Specifications and Structured Decisions
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING TECHNIQUES
Chapter 2: Problem Solving
Chapter 2: Problem Solving
INTRODUCTION TO PROGRAMMING
 Control structures  Algorithm & flowchart  If statements  While statements.
ITEC113 Algorithms and Programming Techniques
Chapter 2- Visual Basic Schneider
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
Chapter 3 Planning Your Solution
Review Algorithm Analysis Problem Solving Space Complexity
ALGORITHMS AND FLOWCHARTS
1 L07SoftwareDevelopmentMethod.pptCMSC 104, Version 8/06 Software Development Method Topics l Software Development Life Cycle Reading l Section 1.4 – 1.5.
Chapter 2: Problem Solving
CSEB114: PRINCIPLE OF PROGRAMMING Chapter 2: Problem Solving.
Chapter 2: Problem Solving
U NDERSTANDING P ROBLEMS AND HOW TO S OLVE THEM BY USING C OMPUTERS.
TMF1013 : Introduction To Computing Lecture 1 : Fundamental of Computer ComputerFoudamentals.
Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and Elizabeth Drake Chapter 2: Flowcharts.
Slide 1 Software Development 1. Requirement Specification 2. Analysis 3. Algorithm Design 4. Implementation 5. Testing 6. Documentation.
Chapter 2 Problem Solving On A Computer 2.1 Problem Solving Steps Solving a problem on a computer requires steps similar to those followed when solving.
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.
CMSC 1041 Algorithms II Software Development Life-Cycle.
Module 4 Part 1 Introduction To Software Development : Systems Analysis & Design Introduction To Software Development : Systems Analysis & Design.
กระบวนการแก้ปัญหาด้วย คอมพิวเตอร์ 3 พฤษภาคม :00-17:00.
Pseudocode. Simple Program Design, Fourth Edition Chapter 2 2 Objectives In this chapter you will be able to: Introduce common words, keywords, and meaningful.
Pseudocode Simple Program Design Third Edition A Step-by-Step Approach 2.
Flowcharts. Problem Solving Computer programs are written to solve problems or perform tasks Programmers translate the solutions or tasks into a language.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
PROGRAMMING PAPER 2 AS Algorithms.
ITEC113 Algorithms and Programming Techniques
CMSC 104: Peter Olsen, Fall 99Lecture 9:1 Algorithms III Representing Algorithms with pseudo-code.
Principles of Programming - NI July Chapter 2: Problem Solving In this chapter you will learn about: Introduction to Problem Solving Software development.
 In this chapter you will learn about:  Introduction to Problem Solving  Software development method (SDM)  Specification of needs  Problem analysis.
CSEB114: Principle of programming
Problem-solving with Computers. 2Outline  Computer System  5 Steps for producing a computer program  Structured program and programming  3 types of.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Programming Fundamentals Introduction to Problem Solving  Programming is a problem solving activity. When you write a program, you are actually writing.
Evolution of C and C++ n C was developed by Dennis Ritchie at Bell Labs (early 1970s) as a systems programming language n C later evolved into a general-purpose.
Pseudocode. Algorithm A procedure for solving a problem in terms of the actions to be executed and the order in which those actions are to be executed.
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
Program Design & Development EE 201 C7-1 Spring
 Problem Analysis  Coding  Debugging  Testing.
GC101 Introduction to computers and programs
Programming Languages
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Chapter 2- Visual Basic Schneider
PROGRAM CONTROL STRUCTURE
Algorithms and Flowcharts
Introduction To Flowcharting
Programming Fundamentals
Algorithm and Ambiguity
An Introduction to Visual Basic .NET and Program Design
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Chapter 2- Visual Basic Schneider
Introduction to Algorithms and Programming
Understanding Problems and how to Solve them by using Computers
Computer Science Core Concepts
Click to add Text Computers & Instructions. Computers are given instructions in the form of computer programs that are created through the development.
Introduction to Programming
Basic Concepts of Algorithm
Presentation transcript:

CS101: Introduction to Computer programming Lecture-1: Introduction to Problem Solving - CS002: Review - CS101: Introduction to Computer programming

Outline In this chapter you will learn about: Introduction to Problem Solving Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Introduction to Problem Solving Problem solving is the process of transforming the description of a problem into a solution by using our knowledge of the problem domain and by relying on our ability to select and use appropriate problem-solving strategies, techniques and tools. Computers can be used to help us solving problems

Software Development Method (SDM) Is a framework that is used to structure, plan, and control the process of developing an information system, which include the following steps: Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Example (Problem) Lets have the following problem: Design a program to compute the car parking fee base on these rates: first 2 hours = SR 1 per hour, the following hours is SR 2 per hour.

Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Step-1: Specification of Needs To understand exactly: what the problem is what is needed to solve it what the solution should provide if there are constraints and special conditions.

Specification of needs (Example) What the problem is Need to calculate the parking fee What is needed to solve it Total time What the solution should provide The parking fee If there are constraints and special conditions. None

Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Step-2: Problem Analysis In the analysis phase, we should identify the following: Inputs to the problem, their form and the input media to be used Outputs expected from the problem, their form and the output media to be used Special constraints or conditions (if any) Formulas or equations to be used

Problem analysis (Example) Input: Total time (time) Output: Parking fees (fees) Formula: If time <= 2, fees = time If time > 2, fees = [(time – 2)X2] +2 Constraint None

Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Step-3: Design algorithm An algorithm is a sequence of a finite number of steps arranged in a specific logical order which, when executed, produces the solution for a problem. An algorithm must satisfy these requirements: It may have an input(s) It must have an output It should not be ambiguous (there should not be different interpretations to it)

Control Structures In 1966, two researchers, C. Bohn and G. Jacopini, demonstrated that any algorithm can be described using only 3 control structures: Sequence Selection Repetition Called control structures or logic structures

The Sequence Structure The sequence structure directs the computer to process the program instructions, one after another, in the order listed in the program

The Sequence Structure (continued)

The Selection Structure Selection structure: makes a decision and then takes an appropriate action based on that decision Also called the decision structure

The Selection Structure (continued)

The Repetition Structure Repetition structure: directs computer to repeat one or more instructions until some condition is met Also called a loop or iteration

The Repetition Structure (continued)

The Repetition Structure (continued) What could you do if you don’t know precisely how many steps separate Rob from the chair?

The Repetition Structure (continued)

Design Algorithm An algorithm can be represented using pseudocodes or flowcharts: Pseudocode: is a semiformal, English-like language with limited vocabulary that can be used to design and describe algorithms. Flowcharts: is a graph used to depict or show a step by step solution using symbols which represent a task prepared by NI, edited by MAF

Pseudocodes: The Sequence control structure A series of steps or statements that are executed in the order they are written in an algorithm. The beginning and end of a block of statements can be optionally marked with the keywords begin and end. Example-1: Begin Read the birth date from the user. Calculate the difference between the birth date and today’s date. Print the user age. End

Age = current year – birth date Flowchart – example-1 Flowchart Symbols Begin Read birth date Calculate Age = current year – birth date Display age End Terminal symbol - indicates the beginning and end points of an algorithm. Process symbol - shows an instruction other than input, output or selection. Input-output symbol - shows an input or an output operation. Selection symbol - shows a selection process for two-way selection. Flow lines - indicate the logical sequence of execution steps in the algorithm.

Pseudocodes: The Selection control structure Defines two courses of action depending on the outcome of a condition. A condition is an expression that is, when computed, evaluated to either true or false. The keyword used are if and else. Format: if condition then-part else else-part end_if Example-2: if age is greater than 55 print “Retire” else print “Work Work Work” end_if

Flowchart – example-2 Read age Age > 55? NO YES print “retired” Begin Read age End Age > 55? NO YES print “retired” print “keep working”

Pseudocodes: The Repetition control structure Specifies a block of one or more statements that are repeatedly executed until a condition is satisfied. Example-3: Summing up 1 to 10 set cumulative sum to 0 set current number to 1 while current number is less or equal to 10 add the cumulative sum to current number add 1 to current number end_while print the value of cumulative sum

Flowchart – example 3 sum = 0 current_number = 1 NO Begin End current_number <= 10? NO YES sum = 0 current_number = 1 sum = sum + current_number current_number = current_number + 1 print sum

Our Problem Algorithm (Pseudocode )

Algorithm (Flowchart)

Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Step-4: Implementation The process of implementing an algorithm by writing a computer program using a programming language (for example, using C language) The output of the program must be the solution of the intended problem The program must not do anything that it is not supposed to do (Think of those many viruses, buffer overflows, trojan horses, etc. that we experience almost daily. All these result from programs doing more than they were intended to do)

Implementation (from pseudocodes)

Implementation (from flowchart)

Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Step-5: Testing and Verification Program testing is the process of executing a program to demonstrate its correctness Program verification is the process of ensuring that a program meets user-requirement After the program is compiled, we must run the program and test/verify it with different inputs before the program can be released to the public or other users (or to the instructor of this class)

Testing and Verification (Syntax)

Testing and Verification (Syntax)

Testing and Verification(Values)

Software Development Method (SDM) Specification of needs Problem analysis Design algorithm Implementation Testing and verification Documentation

Step-6: Documentation Contains details produced at all stages of the program development cycle. Can be done in 2 ways: Writing comments between your line of codes Creating a separate text file to explain the program Important not only for other people to use or modify your program, but also for you to understand your own program after a long time (believe me, you will forget the details of your own program after some time ...)

Documentation

Documentation

Summary This chapter introduced the concept of problem solving-a process of transforming the description of a problem into a solution. A commonly used method – SDM which consists of 6 steps 3 basic control structures : sequence, selection and repetition structures Pseudocode vs. Flow chart