Programming Fundamentals (750113) Ch1. Problem Solving

Slides:



Advertisements
Similar presentations
CHAPTER 2 GC101 Program’s algorithm 1. COMMUNICATING WITH A COMPUTER  Programming languages bridge the gap between human thought processes and computer.
Advertisements

Programming Types of Testing.
Chapter 1 - An Introduction to Computers and Problem Solving
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
Algorithms and Problem Solving-1 Algorithms and Problem Solving.
Algorithms and Problem Solving. Learn about problem solving skills Explore the algorithmic approach for problem solving Learn about algorithm development.
Chapter 1: An Overview of Computers and Programming Languages
Programming Fundamentals (750113) Ch1. Problem Solving
1 Chapter 2 Problem Solving Techniques INTRODUCTION 2.2 PROBLEM SOLVING 2.3 USING COMPUTERS IN PROBLEM SOLVING : THE SOFTWARE DEVELOPMENT METHOD.
BPC.1 Basic Programming Concepts
PRE-PROGRAMMING PHASE
Introduction 01_intro.ppt
© Janice Regan, CMPT 128, Jan CMPT 128 Introduction to Computing Science for Engineering Students Creating a program.
สาขาวิชาเทคโนโลยี สารสนเทศ คณะเทคโนโลยีสารสนเทศ และการสื่อสาร.
CS001 Introduction to Programming Day 5 Sujana Jyothi
CSC141 Introduction to Computer Programming
หลักการโปรแกรม เพื่อแก้ปัญหาโดยใช้คอมพิวเตอร์
Chapter 3: Completing the Problem- Solving Process and Getting Started with C++ Introduction to Programming with C++ Fourth Edition.
Programming Concepts Chapter 3.
Describe the Program Development Cycle. Program Development Cycle The program development cycle is a series of steps programmers use to build computer.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Slide 1- 1 October 20, October 20, 2015October 20, 2015October 20,
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.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
IXA 1234 : C++ PROGRAMMING CHAPTER 1. PROGRAMMING LANGUAGE Programming language is a computer program that can solve certain problem / task Keyword: Computer.
INTRODUCTION TO COMPUTING CHAPTER NO. 04. Programming Languages Program Algorithms and Pseudo Code Properties and Advantages of Algorithms Flowchart (Symbols.
Chapter 1 Introduction Chapter 1 Introduction 1 st Semester 2015 CSC 1101 Computer Programming-1.
Definition of Terms Software/Programs Programs that directs the operation of a computer system Set of instructions Codes Programming Process of planning,
The basics of the programming process The development of programming languages to improve software development Programming languages that the average user.
1 Program Planning and Design Important stages before actual program is written.
How Are Computers Programmed? CPS120: Introduction to Computer Science Lecture 5.
The Hashemite University Computer Engineering Department
Principles of Programming CSEB134 : BS/ CHAPTER Fundamentals of the C Programming Language.
CSCI 161 Lecture 3 Martin van Bommel. Operating System Program that acts as interface to other software and the underlying hardware Operating System Utilities.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
PROGRAMMING FUNDAMENTALS INTRODUCTION TO PROGRAMMING. Computer Programming Concepts. Flowchart. Structured Programming Design. Implementation Documentation.
Lecture 3 Computer Programming -1-. The main steps of program development to solve the problem: 1- problem definition : The problem must be defined into.
Software Engineering Algorithms, Compilers, & Lifecycle.
 Problem Analysis  Coding  Debugging  Testing.
1-1 The Python IDE.
Algorithms and Problem Solving
Algorithms, Part 1 of 3 The First step in the programming process
CSCI-235 Micro-Computer Applications
Computer Programming.
Completing the Problem-Solving Process
DDC 1023 – Programming Technique
CS1001 Programming Fundamentals 3(3-0) Lecture 2
The Selection Structure
Lecture 2 Introduction to Programming
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Programming Logic n Techniques
Algorithm and Ambiguity
Unit# 9: Computer Program Development
Problem Solving Techniques
Programming Fundamentals (750113) Ch1. Problem Solving
1) C program development 2) Selection structure
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
Problem Solving Skill Area 305.1
Algorithm and Ambiguity
Algorithms and Problem Solving
King Saud University College Of Applied Studies and Community Services CSC 1101 Computer Programming-1 Done By: Asmal Alosaimi Edited By: Fatimah Alakeel.
Programming Fundamentals (750113) Ch1. Problem Solving
Software Development Process
Programming Fundamentals (750113) Ch1. Problem Solving
Basic Concepts of Algorithm
Programming Logic and Design Eighth Edition
Presentation transcript:

Programming Fundamentals (750113) Ch1. Problem Solving

Programming Fundamentals --> Ch1. Problem solving Programming is a process of problem solving (Problem Solution by computer) Algorithm ? Step-by-step problem-solving process Solution achieved in finite amount of time Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 2

Problem Solving Process Phase 1 - Analyze the problem Outline the problem and its requirements Design (algorithm) to solve the problem ( Flow chart, pseudo code) Algorithm tracing Phase 2 - Implement the algorithm Implement the algorithm in code (in Programming Language  Program) Verify that the algorithm works Phase 3 - Maintenance Use and modify the program if the requirements changes Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 3

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (1) Outline the problem and its requirements Understand the problem Understand problem requirements Does program require user interaction? Does program manipulate data? What is the output? are all possible circumstances handled? If the problem is complex, divide it into subproblems Analyze each subproblem as above Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 4

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (1) Design Algorithm Flowcharts pseudo-code Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 5

Programming Fundamentals --> Ch1. Problem solving A Flowchart is An algorithm graphical representation. Written as a combination of the following graphical notations: Flow Chart Symbols Start and End Selection Data Flow Input / output Calculation Programming Fundamentals --> Ch1. Problem solving

Programming Fundamentals --> Ch1. Problem solving Pseudo-code: <Algorithm name> // input ? The comment lines “//” // function? // Output? Begin <data definition> <actions> End Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 7

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (1) Algorithm Tracing Draw flowchart Find all possible paths Check each path with appropriate input data Observed Outputs not conform to the expected ones  error in the algorithm. Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 8

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (2) Problem Example. Convert a student mark from decimal mode to ABC mode. Understand problem requirements Is the problem statement complete and unambiguous? Does program require user interaction? Input the mark Does program manipulate data?  covert mark Control Requirements (IF statement) What is the output? The mark converted to A or B or C or error Is there subproblem? No Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 9

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (2) Efficiency: - an algorithm may work correctly but be inefficient – by taking more time and using more resources than required to solve the problem. - becomes more important for larger programs. Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 10

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (3) Design Algorithm  Algorithm Discovery To discover an algorithm is to solve the problem! Working backwards (modification of an old solution) Example: Min of a and b is known. Deduce Max a and b. Look for a related problem that has been solved before (similar solutions reuse) The precedent algorithm of mark conversion is for single student. It may be generalized to many students Stepwise Refinement (new solution) Break the problem into several sub-problems Solve each subproblem separately Produces a modular structure Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 11

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem (3) Example. Making tea. Suppose we have a robot which carries out household tasks. We wish to program the robot to make a cup of tea. An initial attempt at an algorithm might be: 1. Put tea leaves in pot 2. Boil water 3. Add water to pot 4. Wait 5 minutes 5. Pour tea into cup Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 12

Design Algorithm  Algorithm Discovery Strategies  Stepwise Refinement

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem(3) the designer must know when to stop refining. In this example the instruction Switch on kettle is directly executable by the robot, but that Fill kettle with water is not. Experience will tell us when a step is directly implementable or not. The above algorithm consists of a sequence of steps, executed exactly once and in order Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 14

Programming Fundamentals --> Ch1. Problem solving Analyze the Problem(3) Control requirements: while Another common requirement is the need for iteration. — Example. Repeat the mark conversion for a class room of 30 students. Each student having a unique student number from 1 to 30. Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 15

Implement the algorithm (Coding) After testing your algorithm, you can code it in any programming language. In our lab, we are going to use C++ language. Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 16

Programming Fundamentals --> Ch1. Problem solving C++ Language Elements The general form of a C++ program // File: filename // Program description # include compiler directives void main ( ) { declarations section executable statement section } Programming Fundamentals --> Ch1. Problem solving

Programming Fundamentals --> Ch1. Problem solving Computer Stage: after completing the program, the computer must do the following: Compilation: Execution: Programming Fundamentals --> Ch1. Problem solving

Programming Fundamentals --> Ch1. Problem solving Stages of Compilation Performed by a program called the compiler Translates the preprocessor-modified source code into object code (machine code) Checks for syntax errors and warnings Saves the object code to a disk file If any compiler errors are received, no object code file will be generated. An object code file will be generated if only warnings, not errors, are received. Programming Fundamentals --> Ch1. Problem solving

Examples of C/C++ compilers of today: Compiler converts human readable language to a language which is understandable by the operating system/hardware Examples of C/C++ compilers of today: Visual C++ GCC/G++ DJGPP (open source for windows like GCC) Borland C Turbo (obsolete and not recommended)

Programming Fundamentals --> Ch1. Problem solving Execution when the program become don’t has errors, the computer execute it to produce the ……output. Programming Fundamentals --> Ch1. Problem solving

Implement the algorithm Verify that the algorithm works  source of errors Many errors made in: analyzing the problem, developing an algorithm, and/or coding the algorithm Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 22

Implement the algorithm • Errors are of three types: . syntax errors . run-time errors . logic errors • Syntax errors: detected by the C compiler . source code does not conform to one or more of C’s grammar rules . examples of syntax errors: undeclared variable, … • Often one mistake leads to multiple error messages – can be confusing Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 23

Implement the algorithm • Run-time errors. detected and displayed by computer during execution. - Occur when program directs computer to perform illegal operation. Example: int x=y/0; - will stop program execution and display message • Logic errors. - caused by faulty algorithm - sign of error: incorrect program output cure: thorough testing and comparison with expected results A logic error is referred to as a bug, so finding logic errors is called debugging. Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 24

Programming Fundamentals --> Ch1. Problem solving Conclusions (Cont’d) Programming Fundamentals --> Ch1. Problem solving Programming Fundamentals Ch1 --> Problem Solving 25