School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques.

Slides:



Advertisements
Similar presentations
The Software Lifecycle. Example Problem: Update a Checkbook Write a program that allows the user to enter a starting balance, a transaction type, D or.
Advertisements

P5, M1, D1.
1 Chapter 2 Introduction to Java Applications Introduction Java application programming Display ____________________ Obtain information from the.
Computer Programming and Basic Software Engineering 4. Basic Software Engineering 1 Writing a Good Program 4. Basic Software Engineering 3 October 2007.
Program Design and Development
Pseudocode and Algorithms
Chapter 2: Input, Processing, and Output
Computer Science 1620 Programming & Problem Solving.
Chapter 1 Program Design
Lecture Notes 8/30/05 Program Design & Intro to Algorithms.
Moving To Code 3 More on the Problem-Solving Process §The final step in the problem-solving process is to evaluate and modify (if necessary) the program.
BBS Yapısal Programlama (Structured Programming)1 From problem to program In “real world”… Problem in Natural language Top Down Design in pseudo-code.
BPC.1 Basic Programming Concepts
The Art of Programming Top-Down Design. The Art of Problem Solving The art of problem solving is the transformation of an English description of a problem.
Computer Science 101 Introduction to Programming.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
DCT 1123 PROBLEM SOLVING & ALGORITHMS INTRODUCTION TO PROGRAMMING.
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Shawlands Academy Higher Computing Software Development Unit.
Simple Program Design Third Edition A Step-by-Step Approach
General Programming Introduction to Computing Science and Programming I.
INTRODUCTION TO ALGORITHMS PROGRAMMING. Objectives Give a definition of the term algorithm Describe the various parts of the pseudocode algorithm or algorithm.
Goals of Course Introduction to the programming language C Learn how to program Learn ‘good’ programming practices.
© The McGraw-Hill Companies, 2006 Chapter 4 Implementing methods.
Computer Science 101 Introduction to Programming.
1 CSC 221: Introduction to Programming Fall 2012 Functions & Modules  standard modules: math, random  Python documentation, help  user-defined functions,
Programming Lifecycle
1 The Software Development Process  Systems analysis  Systems design  Implementation  Testing  Documentation  Evaluation  Maintenance.
Creating your first C++ program
Chapter 3 Developing an algorithm. Objectives To introduce methods of analysing a problem and developing a solution To develop simple algorithms using.
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 5: Software Design & Testing; Revision Session.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Developing an Algorithm
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Mr. Dave Clausen1 La Cañada High School Chapter 6: Repetition Statements.
C++ Programming Language Lecture 2 Problem Analysis and Solution Representation By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
I Power Higher Computing Software Development The Software Development Process.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
27/05/ Iteration Loops Nested Loops & The Step Parameter.
The Programming Process Define the problem* Make or buy software? Design the program * Code (write) the program Test (debug) the program Document the.
1 Ch. 1: Software Development (Read) 5 Phases of Software Life Cycle: Problem Analysis and Specification Design Implementation (Coding) Testing, Execution.
The Software Development Process
Lecture 5: Stopping with a Sentinel. Using a Sentinel Problem Develop a class-averaging program that will process an arbitrary number of grades each time.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Software Development Problem Analysis and Specification Design Implementation (Coding) Testing, Execution and Debugging Maintenance.
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
1 09/27/04CS150 Introduction to Computer Science 1 Let ’ s all Repeat Together.
The Hashemite University Computer Engineering Department
Chapter Topics 2.1 Designing a Program 2.2 Output, Input, and Variables 2.3 Variable Assignment and Calculations 2.4 Variable Declarations and Data Types.
1 The Software Development Process ► Systems analysis ► Systems design ► Implementation ► Testing ► Documentation ► Evaluation ► Maintenance.
Software Development Process CS 360 Lecture 3. Software Process The software process is a structured set of activities required to develop a software.
CMSC 2021 Software Development. CMSC 2022 Software Development Life Cycle Five phases: –Analysis –Design –Implementation –Testing –Maintenance.
Chapter 2: Algorithm Discovery and Design Invitation to Computer Science.
Lecture #1: Introduction to Algorithms and Problem Solving Dr. Hmood Al-Dossari King Saud University Department of Computer Science 6 February 2012.
Program Design. Simple Program Design, Fourth Edition Chapter 1 2 Objectives In this chapter you will be able to: Describe the steps in the program development.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
Introduction to Algorithmic Processes CMPSC 201C Fall 2000.
Intro. to Computer Programming Eng. Nehal A. Mohamed Spring Semester-2016.
Software Design and Development Development Methodoligies Computing Science.
Introduction to Computing Science and Programming I
2008/09/22: Lecture 6 CMSC 104, Section 0101 John Y. Park
Chapter 2: Input, Processing, and Output
Programming Problem steps must be able to be fully & unambiguously described Problem types; Can be clearly described Cannot be clearly described (e.g.
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Algorithm and Ambiguity
Problem Solving Techniques
Coding Concepts (Basics)
Algorithms, Part 2 of 3 Topics Problem Solving Examples Pseudocode
Problem Solving Skill Area 305.1
Algorithm and Ambiguity
Presentation transcript:

School of Computer Science & Information Technology G6DICP - Lecture 9 Software Development Techniques

2 Software Design There is a difference between program design and coding. There is a difference between program design and coding. Effective programming requires both. Effective programming requires both. Program design should be a formalised process: Program design should be a formalised process: Describe the problem in terms of the actions that the computer needs to perform. Describe the problem in terms of the actions that the computer needs to perform. Test the description. Test the description. Refine the description to provide more detail. Refine the description to provide more detail. Test the refinements... etc. Test the refinements... etc. Code the program. Code the program. Coding without design should always be avoided. Coding without design should always be avoided.

3 Top-Down Design The most widely favoured method of program development. The most widely favoured method of program development. The task is described as a problem. The task is described as a problem. This problem is divided into sub-problems. This problem is divided into sub-problems. Sub-problems are further divided, until the stages are easily represented by program code. Sub-problems are further divided, until the stages are easily represented by program code.

4 Program Description Sate the problem in hand. Sate the problem in hand. This statement must be clear and absolutely unambiguous. This statement must be clear and absolutely unambiguous. Clarification of the problem statement frequently requires iteration with the “client”. Clarification of the problem statement frequently requires iteration with the “client”. The problem statement can frequently be broken down into partly or completely autonomous components. The problem statement can frequently be broken down into partly or completely autonomous components. Functional Specification. Functional Specification. For any large programming project this must be a written document that is agreed by all parties (eg “programmers”, “clients” etc). For any large programming project this must be a written document that is agreed by all parties (eg “programmers”, “clients” etc).

5 Feasibility The functional specification can be tested for feasibility. The functional specification can be tested for feasibility. There are several possible problem areas: There are several possible problem areas: Completely infeasible problems (ie problems that have no solution - eg division by 0, calculating the square root of negative numbers etc). Completely infeasible problems (ie problems that have no solution - eg division by 0, calculating the square root of negative numbers etc). Practically infeasible problems Practically infeasible problems Infeasible in terms of hardware Infeasible in terms of hardware Infeasible in terms of time Infeasible in terms of time Infeasible in terms of cost Infeasible in terms of cost

6 Algorithms An algorithm is the solution for a problem. An algorithm is the solution for a problem. Algorithms must be: Algorithms must be: Finite There must be a measurable point at which the problem can be said to be solved. Finite There must be a measurable point at which the problem can be said to be solved. Ordered The algorithm must consist of a series of steps. Ordered The algorithm must consist of a series of steps. Unambiguous Each step must follow on from a previous step - if choices are made they must be based upon conditions determined earlier in the sequence. Unambiguous Each step must follow on from a previous step - if choices are made they must be based upon conditions determined earlier in the sequence.

7 Successive Refinement First - develop an initial solution First - develop an initial solution This does not need to go into much detail This does not need to go into much detail It does not need to be functional program code It does not need to be functional program code It must describe the solution correctly It must describe the solution correctly Secondly - refine this solution Secondly - refine this solution Each stage should be considered as a problem in its own right - a solution developed and described. Each stage should be considered as a problem in its own right - a solution developed and described. The description must again describe the solution correctly The description must again describe the solution correctly Continue until the problem is completely solved Continue until the problem is completely solved “Successive Refinements” “Successive Refinements” Pseudocode Pseudocode

8 Pseudocode A detailed description of a program A detailed description of a program Ignore the syntactic rigours of a formal language Ignore the syntactic rigours of a formal language Provide sufficient detail so that each part of the description will have a correspondence with real source code Provide sufficient detail so that each part of the description will have a correspondence with real source code For OO programming, try to design your pseudocode in an OO manner (ie use objects and methods) For OO programming, try to design your pseudocode in an OO manner (ie use objects and methods)

9 Example - 1. The Problem Problem Problem “Write a program to find and display the total of nine integers input by the user. The user should be prompted for input, and the integers should be entered in groups of 3 - with the subtotal displayed after the entry of each of these groups” Modified from Meyers, Example output Example output Enter the first 3 numbers : Subtotal : 15 Subtotal : 15 Enter the second 3 numbers : Subtotal : 24 Subtotal : 24 Enter the last 3 numbers : Total : 34 Total : 34

10 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Refinement of second action Refinement of second action Refinement of third action Refinement of third action

11 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Display prompt for user Display prompt for user Read in values for Int1, Int2 and Int3 Read in values for Int1, Int2 and Int3 Sum = Int1 + Int2 + Int3 Sum = Int1 + Int2 + Int3 Display the value of Sum Display the value of Sum Refinement of second action Refinement of second action Refinement of third action Refinement of third action

12 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Refinement of second action Refinement of second action Display prompt for user Display prompt for user Read in values for Int1, Int2 and Int3 Read in values for Int1, Int2 and Int3 Sum = Sum + Int1 + Int2 + Int3 Sum = Sum + Int1 + Int2 + Int3 Display the value of Sum Display the value of Sum Refinement of third action Refinement of third action

13 Example - 2. Successive Refinement Initial Description Initial Description Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display their sum Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read 3 input integers and display the sum of all 6 Prompt user, read in 3 input integers and display the sum of all 9 Prompt user, read in 3 input integers and display the sum of all 9 Refinement of first action Refinement of first action Refinement of second action Refinement of second action Refinement of third action Refinement of third action Display prompt for user Display prompt for user Read in values for Int1, Int2 and Int3 Read in values for Int1, Int2 and Int3 Sum = Sum + Int1 + Int2 + Int3 Sum = Sum + Int1 + Int2 + Int3 Display the value of Sum Display the value of Sum

14 Testing a Program Design Desk Tracing Desk Tracing  Data values are chosen, and the actions are carried out by hand- tracing the program steps using these values. NB this may be done on paper (with the aid of a calculator). Assertion Testing Assertion Testing Rather than using test data the logic of the algorithm is tested. Rather than using test data the logic of the algorithm is tested. The state of the program is described at any one point, and the effects of a step upon this is considered. This process is then repeated for the entire algorithm. The state of the program is described at any one point, and the effects of a step upon this is considered. This process is then repeated for the entire algorithm.

15 Example - Assertion Testing Assertion - when the first three numbers are entered the values of the 1st, 2nd and 3rd numbers are contained in Int1, Int2 and Int3. Assertion - when the first three numbers are entered the values of the 1st, 2nd and 3rd numbers are contained in Int1, Int2 and Int3. Assertion - when Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first group of numbers entered. Assertion - when Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first group of numbers entered. Assertion - when Sum is displayed, the sum of the first group of numbers to be entered is be displayed. Assertion - when Sum is displayed, the sum of the first group of numbers to be entered is be displayed. Assertion - when the second three numbers are entered the values of the 4th 5th and 6th numbers are contained in Int1, Int2 and Int3. Assertion - when the second three numbers are entered the values of the 4th 5th and 6th numbers are contained in Int1, Int2 and Int3. Assertion - when Sum+Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first two groups of numbers entered. Assertion - when Sum+Int1+Int2+Int3 is assigned to Sum, it will represent the sum of the first two groups of numbers entered. Etc. Etc.

16 Coding and Testing When the design is considered sound, the program is coded. When the design is considered sound, the program is coded. Each line of pseudocode is replaced by real code. Each line of pseudocode is replaced by real code. The code is compiled and syntax errors are fixed. The code is compiled and syntax errors are fixed. The program is run with as many different data sets as possible (including extreme ones). The program is run with as many different data sets as possible (including extreme ones).

17 State the problem Is it feasible? Plan and refine an action sequence Does it solve the problem? Write and compile the source code Is it free of syntax errors? Run the program Are the results correct? Run the program Does it do the job? YesYes NoNo YesYes NoNo YesYes NoNo YesYes NoNo YesYes NoNo Hooray!

18 Coding Hints Start coding with a template that you know works! Start coding with a template that you know works! Make very small additions/changes and test the partly finished code: Make very small additions/changes and test the partly finished code: Syntax errors - ie does it compile Syntax errors - ie does it compile Functionality - ie does it run correctly Functionality - ie does it run correctly Fix errors as they occur Fix errors as they occur Don’t write a complete program, and then expect it to work first time - it won’t!! Don’t write a complete program, and then expect it to work first time - it won’t!! Use a good coding style Use a good coding style

19 Coding Style Write code that is easy to understand Write code that is easy to understand Identifiers should be meaningful Identifiers should be meaningful eg LineCounter rather than n eg LineCounter rather than n The presentation of the code should reflect its structure The presentation of the code should reflect its structure eg indent code blocks, space lines etc. eg indent code blocks, space lines etc. Actions in the code should be commented Actions in the code should be commented Comments should add meaning, not repeat information already in the code Comments should add meaning, not repeat information already in the code eg n++; // increment n - This adds nothing n++; // count lines - This is a useful comment eg n++; // increment n - This adds nothing n++; // count lines - This is a useful comment

20 Bad Style public static String mc(int a, char b) {String c=""; while (a>0) { c=c+b; a--;} return (c);}

21 Good Style /** * multiChar - method to return a string containing any * one character repeated any number of times. */ public static String multiChar(int number, char character) // number - no. characters to be drawn // character - the character to be drawn { String str=""; // str will contain the multiple characters while (number>0) // character-writing loop - repeat // for each character to to be drawn { str=str+character; // add a single character to str number--; // reduce the number still to be // written by one } // end of character writing loop return (str); // return the multiple characters }

22 Java Naming Conventions The main method of an application should be in a class that is contained in a source file of the same name. The main method of an application should be in a class that is contained in a source file of the same name.  Eg class myprog in myprog.java (which will compile to myprog.class. Class identifiers should begin with an upper case letter Class identifiers should begin with an upper case letter eg Myclass, String, System etc. eg Myclass, String, System etc. Variable, and method identifiers should begin with a lower case letter (although a mixture of cases may make them more readable. Variable, and method identifiers should begin with a lower case letter (although a mixture of cases may make them more readable. Eg data1, myData, myObject, myMethod(), println() etc. Eg data1, myData, myObject, myMethod(), println() etc.