Introduction to C Programming CE00312-1 Lecture 5 Program Design in C.

Slides:



Advertisements
Similar presentations
Decision Structures - If / Else If / Else. Decisions Often we need to make decisions based on information that we receive. Often we need to make decisions.
Advertisements

SOFTWARE TESTING. INTRODUCTION  Software Testing is the process of executing a program or system with the intent of finding errors.  It involves any.
1 ICS102: Introduction To Computing King Fahd University of Petroleum & Minerals College of Computer Science & Engineering Information & Computer Science.
Chapter 1. The Phases of Software Development. Data Structure 2 Chapter outline  Objectives  Use Javadoc to write a method’s complete specification.
November 2005J. B. Wordsworth: J5DAMQVT1 Design and Method Quality, Verification, and Testing.
Steps in Program Development
0 Advanced Selection CE : Introduction to Software Development Week 3 Lecture 2.
Developing Software Applications Software Life Cycle Specification Design Implementation Testing Maintenance.
Testing an individual module
Making Decisions In Python
1 Arithmetic in C. 2 Type Casting: STOPPED You can change the data type of the variable in an expression by: (data_Type) Variable_Name Ex: int a = 15;
Programming Fundamentals (750113) Ch1. Problem Solving
Copyright © 2012 Pearson Education, Inc. Chapter 3 Control Structures: Selection.
Chapter 2: Algorithm Discovery and Design
BPC.1 Basic Programming Concepts
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
Invitation to Computer Science, Java Version, Second Edition.
Scott Marino MSMIS Kean University MSAS5104 Programming with Data Structures and Algorithms Week 5 Scott Marino.
Control Structures Week Introduction -Representation of the theory and principles of structured programming. Demonstration of for, while,do…whil.
Chapter 4 Selection Structures: Making Decisions.
© 2011 Pearson Addison-Wesley. All rights reserved. Addison Wesley is an imprint of Stewart Venit ~ Elizabeth Drake Developing a Program.
Flow of Control Part 1: Selection
Conditions. Objectives  Understanding what altering the flow of control does on programs and being able to apply thee to design code  Look at why indentation.
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.
Black-box Testing.
PROBLEM SOLVING & ALGORITHMS CHAPTER 5: CONTROL STRUCTURES - SELECTION.
Conditionals CS 103 February 16, Blast from the Past: C14 Dating Problem Statement: Calculate the age of a fossil from its C-14 radioactivity Problem.
Branches and Program Design
1 ELEC 206 Chapter 3 Control Structures 5-Step Problem Solving Methodology 1. State the problem clearly. 2. Describe the input and output. 3. Work a.
Lecture 13: 10/10/2002CS149D Fall CS149D Elements of Computer Science Ayman Abdel-Hamid Department of Computer Science Old Dominion University Lecture.
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.
More about Strings. String Formatting  So far we have used comma separators to print messages  This is fine until our messages become quite complex:
James Tam Making Decisions In Python In this section of notes you will learn how to have your programs choose between alternative courses of action.
CSC 1010 Programming for All Lecture 4 Loops Some material based on material from Marty Stepp, Instructor, University of Washington.
Chapter 3 Decisions Three control structures Algorithms Pseudocode Flowcharts If…then …else Nested if statements Code blocks { } multi statement blocks.
EGR 115 Introduction to Computing for Engineers Branching & Program Design – Part 3 Friday 03 Oct 2014 EGR 115 Introduction to Computing for Engineers.
Programming Fundamentals by Dr. Nadia Y. Yousif1 Control Structures (Selections) Topics to cover here: Selection statements in the algorithmic language:
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Tevfik Bultan Lecture 4: Introduction to C: Control Flow.
ALGORITHMS AND FLOWCHARTS. Why Algorithm is needed? 2 Computer Program ? Set of instructions to perform some specific task Is Program itself a Software.
STEP 3- DEVELOP AN ALGORITHM At this stage we break down the problem into simple manageable steps so that they can be handled easily.
Algorithms JPC and JWD © 2002 McGraw-Hill, Inc. 2 Algorithms 2 An Algorithm is a finite set of precise instructions for performing a computation or for.
Copyright 2006 Addison-Wesley Brief Version of Starting Out with C++ Chapter 5 Looping.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CMSC 104, Section 301, Fall Lecture 18, 11/11/02 Functions, Part 1 of 3 Topics Using Predefined Functions Programmer-Defined Functions Using Input.
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
 Problem Analysis  Coding  Debugging  Testing.
Decision making If.. else statement.
Lesson Objectives Aims To be able to write an algorithm in Pseudo Code
Software Testing.
ALGORITHMS AND FLOWCHARTS
Engineering Problem Solving with C++, Etter/Ingber
Lecture 2 Introduction to Programming
Introduction to Computer Programming
Programming Fundamentals
Algorithm and Ambiguity
ALGORITHMS AND FLOWCHARTS
Problem Solving Techniques
JSP (Jackson Structured Programming)
Chapter 14 Software Testing Techniques
Chapter 9 - Multimedia IDCS - Computer Technology.
Component-Level Design
Programming Fundamentals (750113) Ch1. Problem Solving
ALGORITHMS AND FLOWCHARTS
Introduction to Algorithms and Programming
Boolean Expressions to Make Comparisons
CHAPTER 4 Iterative Structure.
Flowcharts and Pseudo Code
Basic Concepts of Algorithm
Presentation transcript:

Introduction to C Programming CE Lecture 5 Program Design in C

Design theory Difference between functional and object- oriented programming paradigm and design of resulting code. Top-down design Stepwise refinement Functional decomposition

Design of Processes functional analysis used to design resulting code Break down design into logical blocks  Stepwise refinement  Functional decomposition

Functional Analysis Get up Go to University For as long as there is a lecture to attend Go to lecture Take notes attentively and enthusiastically! Eat tea Go to town For as long as you have money and are thirsty Buy a drink Go home If you have spare money go by taxi Else walk Go Function College Function Food Function Go out Function Go home Function

Design Notation Top Down design Problem decomposition expressed as combinations of sequence, selection, iteration both Inter-function and intra- function Level of abstraction or degree of modularity determined by complexity of problem and design notation used Object Design Uses object modeling to determine level of abstraction Problem decomposition determined by object definition Processes expressed as behaviour of objects

Top-Down design Take main functions Systematically break into smaller chunks Use a method to ‘represent’ solution Stop when resulting modules are small enough to be easily implemented (but not too cumbersome) ‘Clever’ chunking results in reusable modules

Top Down design notation Representative of problem Diagrammatic notation; sequence, selection, iteration JSP Nassi-Scneidermann Pseudo Code/ Structured English Embeds descriptive language into basic construct syntax

Pseudocode/Structured English While valid input If mark entry enter name enter mark Case {mark “refer” mark 40 – 59 “pass” mark 60 – 79 “merit” mark 80 – 100 “Distinction”} else “Error” output name and grade Else Clear

Jackson Structured Design Inputs Output

Nassi-Schneidermann Enter details While user input If Not Clear Clear R P M DE Output mark & name

Testing Purpose of testing Designing test cases and test case data with corresponding input and expected output Black and White box testing Difference between these two categories of test; when test data can be designed and purpose.

Black Box testing Black Box testing consists of Categories Functional Tests Invalid Tests Boundary Tests Special Tests

White Box testing Categories Path Analysis Complex Conditions

Testing Example Consider the example used as one of the week 2 practical exercises; reading in percentage scores greater than 0 and printing out the corresponding letter grade. This is repeated until a negative value is read in. At this stage, the total number of values in each grade range is printed. An error message is printed for any input value greater than 100.

Black Box Tests 1. Functional Tests F1: Read in a percentage score and print the corresponding letter grade F2: Produce an error message if a positive number greater than 100 is input F3: Print out the number of input values in each of the letter grade ranges F4: Terminate input when a negative value is read in.

2. Invalid Tests I1: A positive number greater than 100 should produce an error message

3. Boundary Tests B1: Input largest valid value B2: Input smallest invalid positive value B3: Input lowest valid positive value B4: Input largest invalid negative value B5: Input lowest value in ‘A’ range B6: Input highest value in ‘B’ range B7: Input lowest value in ‘B’ range B8: Input highest value in ‘C’ range B9: Input lowest value in ‘C’ range B10: Input highest value in ‘D’ range B11: Input lowest value in ‘D’ range B12: Input highest value in ‘F’ range

4. Special Test Cases S1: First input value is negative S2: No values are input in a particular letter grade range

White Box Tests Can only be designed after the code has been written. Complex Conditions None in this example Path Analysis

P7 P1 Not P2 P5 P3 Not P3 P4 Not P4 Not P6 Not P5 P6 P2 Path Analysis

P1: Initial sequence P2: Value greater than 100 Not P2: Positive value less than or equal to 100 P3: A’ grade Not P3: value below an ‘A’ grade P4: ‘B’ grade Not P4: value below a ‘B’ grade P5: ‘C’ grade Not P5: value below a ‘C’ grade P6: ‘D’ grade Not P6: ‘F’ grade P7: Print out total number of values in each grade range

Test Data F1: F2: 110 –2 F3: F4: As for F1 I1: As for F2 B1: B2: B3: 0 -1 B4: -1 B5: As for F1 B6: B7: B8: B9: B10: B11: B12: 59 –1 S1: As for B4 S2: P1: As for F1 P2: As for F2 P3: As for F1 Not P3: As for B12 P4: As for B7 Not P4: As for B12 P5: As for B9 Not P5: As for B12 P6: As for B12 Not P6: As for F3 P7: As for F1

Complex Conditions Consider the following if condition if (age =65) Resulting complex conditions: age =65 C1:TrueTrue C2:TrueFalse C3:FalseTrue C4:FalseFalse C1: impossible C2: age = 16 C3: age = 70 C4: age = 21

The number of complex conditions is equal to 2 N, where N is the number of parts to the condition. e.g. if ( age =65) && (gender==’m’ || gender==’f’)  2 4 = 16 conditions

Truth Table age =65 gender==’m’gender==’f’ FalseFalseFalseFalse FalseFalseFalseTrue False FalseTrueFalse FalseFalseTrueTrue FalseTrueFalseFalse FalseTrueFalseTrue False TrueTrueFalse False True TrueTrue Repeated with column 1 containing True and columns 2, 3 and 4 unchanged. e.g. C3: age=21, gender=’m’ C4: impossible (gender can’t be both ‘f’ and ‘m’) C6: age = 70, gender=’f’ C9: age = 16 gender =’z’