C++ Programming Language Lecture 2 Problem Analysis and Solution Representation

Similar documents
Outline. Program development cycle. Algorithms development and representation. Examples.

CS110D: PROGRAMMING LANGUAGE I

Chapter 3 Structured Program Development

C++ Programming Language Lecture 1 Introduction

Computer System and programming in C

C++ Programming Lecture 7 Control Structure I (Repetition) Part I

CSc 10200! Introduction to Computing. Lecture 1 Edgardo Molina Fall 2013 City College of New York

Chapter 8 Algorithms 1

Structured Program Development in C

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #13. Loops: Do - While

Programming Languages and Program Development Life Cycle Fall Introduction to Information and Communication Technologies CSD 102

Digital Logic Lecture 2 Number Systems

int n = 10; int sum = 10; while (n > 1) { sum = sum + n; n--; } cout << "The sum of the integers 1 to 10 is " << sum << endl;

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

Chapter 2. Designing a Program. Input, Processing, and Output Fall 2016, CSUS. Chapter 2.1

8 Algorithms 8.1. Foundations of Computer Science Cengage Learning

Laboratory 2: Programming Basics and Variables. Lecture notes: 1. A quick review of hello_comment.c 2. Some useful information

Introduction to C Programming

Chapter 1 Lab Algorithms, Errors, and Testing

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

Lecture 01 & 02 Computer Programming

III. Check if the divisors add up to the number. Now we may consider each of these tasks separately, assuming the others will be taken care of

C H A P T E R 1. Introduction to Computers and Programming

Introduction to C++ Programming. Adhi Harmoko S, M.Komp

BIL101E: Introduction to Computers and Information systems Lecture 8

Chapter 2 - Problem Solving

1. Introduction to Programming

SNS COLLEGE OF ENGINEERING,

Computer Fundamentals

Introduction to Programming

Computers and FORTRAN Language Fortran 95/2003. Dr. Isaac Gang Tuesday March 1, 2011 Lecture 3 notes. Topics:

Dr. Iyad Jafar. Adapted from the publisher slides

S/W Programming & Languages

4. The is a diagram that graphically depicts the steps that take place in a program. a. Program b. Flowchart c. Algorithm d. Code e.

Chapter 3. More Flow of Control. Copyright 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley

Constructing Algorithms and Pseudocoding This document was originally developed by Professor John P. Russo

Algorithms. Chapter 8. Objectives After studying this chapter, students should be able to:

Fundamentals of Programming (Python) Getting Started with Programming

COP 1220 Introduction to Programming in C++ Course Justification

Introduction to Computer Science Midterm 3 Fall, Points

Information Science 1

FLOW CHART AND PSEUDO CODE

Unit II. (i) Computer Programming Languages

Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Pseudo Code and Flow Charts. Chapter 1 Lesson 2

Repetition Structures

How to approach a computational problem

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Organisation. Assessment

Chapter 1 - An Introduction to Computers and Problem Solving

Higher Computing Science Software Design and Development - Programming Summary Notes

Fundamental of Programming (C)

Arithmetic Operators. Binary Arithmetic Operators. Arithmetic Operators. A Closer Look at the / Operator. A Closer Look at the % Operator

Chapter 4 Introduction to Control Statements

Java Programming Unit 3: Variables and Arithmetic Operations

Python - Week 1. Mohammad Shokoohi-Yekta

Chapter Two: Program Design Process and Logic

Fundamentals of Programming

Individual research task. You should all have completed the research task set last week. Please make sure you hand it in today.

Programming Logic and Design Sixth Edition Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

LECTURE 0: Introduction and Background

The births of the generations are as follow. First generation, 1945 machine language Second generation, mid 1950s assembly language.

LESSON 13 OVERVIEW OF PROGRAM DEVELOPMENT PHASES

Java How to Program, 9/e. Copyright by Pearson Education, Inc. All Rights Reserved.

Visual Basic. Chapter 3

CS125 : Introduction to Computer Science. Lecture Notes #4 Type Checking, Input/Output, and Programming Style

Add Subtract Multiply Divide

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #16 Loops: Matrix Using Nested for Loop

Chapter Twelve. Systems Design and Development

Introduction to C++ Programming Pearson Education, Inc. All rights reserved.

Programming Logic and Design Seventh Edition Chapter 2 Elements of High-Quality Programs

PROBLEM SOLVING AND PYTHON PROGRAMMING

Chapter 1 INTRODUCTION TO COMPUTER AND PROGRAMMING

Fundamentals of Computing and Digital Literacy. Sample. Assignment title: Develop a Wiki. Marking Scheme

Fundamentals of Programming. Lecture 6: Structured Development (part one)

CS61C Machine Structures. Lecture 4 C Pointers and Arrays. 1/25/2006 John Wawrzynek. www-inst.eecs.berkeley.edu/~cs61c/

TOPIC 2 INTRODUCTION TO JAVA AND DR JAVA

IS 0020 Program Design and Software Tools

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

CS112 Lecture: Repetition Statements

SNS COLLEGE OF ENGINEERING

Assessment of Programming Skills of First Year CS Students: Problem Set

CHAPTER 2.1 CONTROL STRUCTURES (SELECTION) Dr. Shady Yehia Elmashad

Activity 1: Introduction

Syllabus of Diploma Engineering. Computer Engineering. Semester: II. Subject Name: Computer Programming. Subject Code: 09CE1104

A Beginner s Guide to Programming Logic, Introductory. Chapter 2 Working with Data, Creating Modules, and Designing High-Quality Programs

Errors and Exceptions. EECS 230 Winter 2018

EKT 120/4 Computer Programming KOLEJ UNIVERSITI KEJURUTERAAN UTARA MALAYSIA

Fundamentals of Structured Programming

TABLE OF CONTENTS 2 CHAPTER 1 3 CHAPTER 2 4 CHAPTER 3 5 CHAPTER 4. Algorithm Design & Problem Solving. Data Representation.

INFS 214: Introduction to Computing

Structure Array 1 / 50

Chapter 6 Programming the LC-3

GRADE 7 MATH LEARNING GUIDE

Numerical Methods in Scientific Computation

Lecture Notes for Chapter 2: Getting Started

Lecture 1 Contracts. 1 A Mysterious Program : Principles of Imperative Computation (Spring 2018) Frank Pfenning

Steps to program development

Topics. Hardware and Software. Introduction. Main Memory. The CPU 9/21/2014. Introduction to Computers and Programming

Introduction to Computer Programming/Handout 01 Page 1 of 13

Transcription:

C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department

Program Development Cycle Program development cycle steps: Problem definition. Problem analysis (understanding). Algorithm development: Ways for algorithm representation: Human language Pseudocode. Flowcharts (also called UML activity diagram). Coding. Execution and testing. Maintenance. Recall that such cycle and all the techniques presented in this lecture are the same for any programming language you want to use not only for C++.

Problem Definition To understand the problem is half the solution. Describe it by precise, up to the point statements that will make both analyzing and solving the problem easier and clearer.

Problem Analysis Determine the inputs, outputs, and the required operations. Explore all possible solutions. Pick the easiest, in terms of implementation cost (space, time) one.

Algorithm Development Algorithm is a procedure that determines the: Actions to be executed. Order in which these actions are to be executed (which is called program control and in industry it is called work flow). So, it is a plan for solving the given problem. You must validate the developed algorithm, i.e. make sure that it solves the correct problem. You must verify the developed algorithm, i.e. make sure that it produces correct results. You must check the feasibility (in terms of the needed resources, ease of implementation, ease of understanding and debugging, its expected execution time, etc.) of the developed algorithm.

Algorithm Representation Human Language Use your own language to represent the steps of the developed algorithm. Example: adding two integers: 1. Prompt the user to enter two numbers. 2. Add them and store the result. 3. Display the sum to the user on the screen.

Algorithm Representation Pseudocode Artificial, informal language used to develop algorithms. kind of structured English for describing algorithms. Middle approach between human language and C++ code. It is convenient and user friendly. Not actually executed on computers Allows us to think out a program before writing the code for it Usually easy to convert into a corresponding C++ program Consists only of executable statements, i.e. no definitions or declarations.

Pseudocode Notations Input: Input from keyboard: Get. Input from file or memory location: Read. Output: Output to printer: Print. Output to file: Write. Output to screen: Display, Prompt (usually followed by Get). Values assignment: Initial values: Initialize, Set. Results of computation: =,. Keeping variables for later use: Save, Store. Arithmetic computation: Either use exact operators (+, *, /, -) or equivalent words of them (add, multiply, divide, subtract). Computations: either use Compute or represent the actual operation mathematically. E.g. Compute average or avg = sum/count. Control structures: Use the actual words as it is: If, If then Else, While, do While, For to --,... Relational operators: Write them as words: greater then, less than or equal, etc. Or you can use their symbols: >, <=, etc.

Pseudocode Examples Adding two numbers: 1. Prompt user for number1 2. Get number1 3. Prompt user for number2 4. Get number2 5. Add number1 and number2 6. Set sum to the result 7. Display sum Other examples: on board: Deciding the grade (A-F) of a student.

Algorithm Representation Flowcharts Represent the algorithms or computer programs execution steps graphically. The American National Standards Institute (ANSI) published a standard for flowcharts that includes a definition of their symbols (see next slide). Pseudocode is preferred over flowcharts since: More readable. Can be converted into C++ code easier. Flow charts are very similar to the UML (Unified Modeling Language) activity diagram with some differences in the used symbols. UML is an industry standard for modeling software systems. We will study flowcharts not activity diagrams in this course.

Flowcharts Symbols

Flowchart Examples Numbers addition example. Other examples (on board): Deciding the grade (A-F) of a student.

Coding Writing the source code of your solution that is to convert the developed algorithm into code statements of the used language, i.e. C++. Some useful tips: Make sure of using correct syntax. Use meaningful identifiers to make your code more readable. Add suitable documentation and comments. Make your code modular or structured as possible.

Execution and Testing Compilation and debugging. Types of errors: Syntax errors (Compile time errors): Errors caught by compiler Logic errors (Runtime errors): Errors which have their effect at execution time Non-fatal logic errors program runs, but has incorrect output Fatal logic errors program exits prematurely Tracing to verify your program with different sets of inputs.

Maintenance Not always applicable in education, i.e. highly required in real world jobs. Update your code based on: Discovered and reported bugs. Customer feedback to make your application more efficient and flexible. Upgrade the code.

Additional Notes This lecture covers the following material from the textbook: Sections 2.1 2.3.