| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.

Slides:



Advertisements
Similar presentations
ALGORITHMS AND FLOWCHARTS
Advertisements

Summer ’12 AP Computer Science APCS Summer Assignments Read thoroughly this ppt and solve examples 6 and 7.
More on Algorithms and Problem Solving
ALGORITHMS AND FLOWCHARTS
PROBLEM SOLVING TECHNIQUES
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Chapter 2: Problem Solving
ALGORITHMS AND FLOWCHARTS
Fundamentals of Algorithms MCS - 2 Lecture # 4
Algorithms. Introduction Before writing a program: –Have a thorough understanding of the problem –Carefully plan an approach for solving it While writing.
Structured Program Development in C
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 3P. 1Winter Quarter Structured Engineering.
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 FLOW CHARTS 1 Adapted from the slides Prepared by Department of Preparatory year Prepared by: lec. Ghader Kurdi.
Fundamentals of C programming
ALGORITHMS AND FLOWCHARTS
Introduction to Programming Lecture Number:. What is Programming Programming is to instruct the computer on what it has to do in a language that the computer.
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
Simple Program Design Third Edition A Step-by-Step Approach
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Introduction to Algorithms By Mr. Venkatadri. M. Two Phases of Programming A typical programming task can be divided into two phases: Problem solving.
Software Life Cycle What Requirements Gathering, Problem definition
Algorithm & Flow Charts
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.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
ALGORITHMS AND FLOWCHARTS CSCI 105 – Computer Fluency.
Chapter 2: General Problem Solving Concepts
Flowcharting & Algorithms. Quick. Close your Eyes and Listen You are still sitting in the classroom. However, you have been called to the counselor’s.
PROGRAM DEVELOPMENT CYCLE. Problem Statement: Problem Statement help diagnose the situation so that your focus is on the problem, helpful tools at this.
1 Program Planning and Design Important stages before actual program is written.
Fundamentals of Algorithms MCS - 2 Lecture # 5. Representation of Algorithms (continued) Flowcharts.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
Concepts of Algorithms CSC-244 Unit Zero Pseudo code, Flowchart and Algorithm Master Prince Computer College Qassim University K.S.A.
Problem, Problem Solving, Algorithm & Flow Charts –Part 1 Presented By Manesh T Course:101 CS 101CS Manesh T1.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
ALGORITHMS AND FLOWCHARTS. A typical programming task can be divided into two phases: Problem solving phase  produce an ordered sequence of steps that.
Introduction to Flowcharts
Introduction to Problem Solving Programming is a problem solving activity. When you write a program, you are actually writing an instruction for the computer.
Lecture 2: Introduction to Programming EEE2108: 공학프로그래밍 서강대학교 전자공학과 2011 학년도 2 학기 - Algorithms and Flowcharts -
CSE 110: Programming Language I Matin Saad Abdullah UB 404.
 Problem Analysis  Coding  Debugging  Testing.
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Program design Program Design Process has 2 phases:
Problem Solving & Computer Programming
ALGORITHMS AND FLOWCHARTS
GC101 Introduction to computers and programs
Problem Solving Concepts
Unit 3: ALGORITHMS AND FLOWCHARTS
Problem , Problem Solving, Algorithm & Flow Charts –Part 1
Algorithm & Programming
ALGORITHMS AND FLOWCHARTS
COVERED BASICS ABOUT ALGORITHMS AND FLOWCHARTS
CS111 Computer Programming
Algorithms and Flowcharts
Programming Fundamentals
ALGORITHMS AND FLOWCHARTS
Unit# 9: Computer Program Development
Problem Solving Techniques
ALGORITHMS AND FLOWCHARTS
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Flowcharting & Algorithms
Introduction to Programming
Basic Concepts of Algorithm
Structural Program Development: If, If-Else
Presentation transcript:

| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1

| Topic 1: Introduction to Structured Programming Concepts Agenda To describe basic problem-solving techniques. To develop algorithms through the process of top-down/stepwise refinement. To write a basic Pseudo code To describe the Syntax used in C Explain the Semantics used in C Describe the various Data types Differentiate between an expressions and a Statements Write a basic Input and output statements 2

| 3 Introduction Before writing a program: – Have a thorough understanding of the problem – Carefully plan an approach for solving it While writing a program: – Know what “building blocks” are available – Use good programming principles Carry out a problem analysis – This involves understanding the problem and clarifying: What data is given or input (available for use when the problem-solving takes place) What results are required What assumptions are safe to make What constraints must be obeyed

| Basic problem-solving techniques Top Down Design Model/Approach – In top-down model, an overview of the system is formulated, without going into detail for any part of it. – Each part of the system is then refined in more details. – Each new part may then be refined again, defining it in yet more details until the entire specification is detailed enough to validate the model. – It basically refers to successive refinement of the problem (task) into sub problems (subtasks). – Refinement is applied until we reach to the stage where the subtasks can be directly carried out. 15-4

| Top Down Design subtask1subtask2 subtask3 Main Task

| Basic problem-solving techniques Bottom-up Design Approach – In bottom-up design individual parts of the system are specified in details. – The parts are then linked together to form larger components, which are in turn linked until a complete system is formed. – Object-oriented languages such as C++ or JAVA use bottom-up approach where each object is identified first. 15-6

| Bottom up Design

| 8 Algorithms Computing problems – All can be solved by executing a series of actions in a specific order Algorithm: It is a finite set of instructions which, if followed accomplish a particular task. – It is basically used to describe a problem solving method suitable for implementation as a computer program. – Algorithm is independent of the machine and language used for implementation.

| 9 Characteristics of an Algorithm Input – Zero or more quantities are supplied externally Output – At least one quantity is produced Definiteness – Each instruction is clear & unambiguous Finiteness – It terminates after finite steps Effectiveness – Each instruction is simple to be carried out manually. An “unambiguous specification of a method” Is characterized by: – Ordered sequence of well-defined, effective operations that, when executed, will produce a result after “terminating” within a finite no of steps

| 10 Pseudocode – Artificial, informal language that helps us develop algorithms – Similar to everyday English – Not actually executed on computers – Helps us “think out” a program before writing it Easy to convert into a corresponding C++ program Consists only of executable statements

| Pseudocode & Algorithm Example 1: Write an algorithm to determine a student’s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

| Pseudocode & Algorithm Pseudocode: Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 60 Print “FAIL” else Print “PASS”

| Pseudocode & Algorithm Detailed Algorithm Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 60) then Print “FAIL” else Print “PASS” endif

| The Flowchart A Flowchart is another algorithm but graphical. – shows logic solution – emphasizes individual steps and their interconnections – A flowchart must have a start and stop – A steps in a flowchart must connect. Can’t leave a step “hanging” with no connection. e.g. control flow from one action to the next

| Flowchart Symbols General Used Symbols

| Example PRINT “PASS” Step 1: Input M1,M2,M3,M4 Step 2: GRADE  (M1+M2+M3+M4)/4 Step 3: if (GRADE < 60) then Print “FAIL” else Print “PASS” endif START Input M1,M2,M3,M4 GRADE  (M1+M2+M3+M4)/4 IS GRADE<6 0 PRINT “FAIL” STOP Y N

| Example 2 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudocode: Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)

| Example 2 Algorithm Step 1: Input Lft Step 2: Lcm  Lft x 30 Step 3: Print Lcm START Input Lft Lcm  Lft x 30 Print Lcm STOP Flowchart

| Example 3 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudocode Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

| Example 3 Algorithm Step 1: Input W,L Step 2: A  L x W Step 3: Print A START Input W, L A  L x W Print A STOP

| Example 4 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation Hint: d = sqrt ( ), and the roots are: x1 = (–b + d)/2a and x2 = (–b – d)/2a

| Example 4 Pseudocode: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2

| Example 4 Algorithm: Step 1: Input a, b, c Step 2: d  sqrt ( ) Step 3: x1  (–b + d) / (2 x a) Step 4: x2  (–b – d) / (2 x a) Step 5: Print x1, x2 START Input a, b, c d  sqrt(b x b – 4 x a x c) Print x 1,x 2 STOP x 1  (–b + d) / (2 x a) X 2  (–b – d) / (2 x a)