IO and Module Charts. 1.Input format. 2. Output format. 3. Exception handling. 4.Top-down design.

Slides:



Advertisements
Similar presentations
Topics Introduction Types of Errors Exceptions Exception Handling
Advertisements

Chapter 1 - An Introduction to Computers and Problem Solving
Control Structures, Arithmetic and Errors.
Chapter 2 - Problem Solving
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 2 - Problem Solving
ITEC113 Algorithms and Programming Techniques
CS 201 Functions Debzani Deb.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Introduction to Computers and Programming Lecture 8: More Loops New York University.
Introduction to Computers and Programming More Loops  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course.
1 Fall 2008ACS-1903 for Loop Reading files String conversions Random class.
Chapter 1 Program Design
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
Chapter 3 Planning Your Solution
CMSC 104, Version 8/061L18Functions1.ppt Functions, Part 1 of 4 Topics Using Predefined Functions Programmer-Defined Functions Using Input Parameters Function.
Fundamentals of Python: From First Programs Through Data Structures
By: Mr. Baha Hanene Chapter 3. Learning Outcomes We will cover the learning outcome 02 in this chapter i.e. Use basic data-types and input / output in.
COMP An Introduction to Computer Programming : University of the West Indies COMP6015 An Introduction to Computer Programming Lecture 02.
UNIT 3 TEMPLATE AND EXCEPTION HANDLING. Introduction  Program errors are also referred to as program bugs.  A C program may have one or more of four.
Simple Program Design Third Edition A Step-by-Step Approach
Intro to Architecture – Page 1 of 22CSCI 4717 – Computer Architecture CSCI 4717/5717 Computer Architecture Topic: Introduction Reading: Chapter 1.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 6 Value- Returning Functions and Modules.
Basic Java Programming CSCI 392 Week Two. Stuff that is the same as C++ for loops and while loops for (int i=0; i
First Steps in Modularization Simple Program Design Third Edition A Step-by-Step Approach 8.
Input, Output, and Processing
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Problem Solving using the Science of Computing MSE 2400 EaLiCaRA Spring 2015 Dr. Tom Way.
Making Good Code AKA: So, You Wrote Some Code. Now What? Ray Haggerty July 23, 2015.
CPS120: Introduction to Computer Science Operations Lecture 9.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Programming, an introduction to Pascal
Research Topics in Computational Science. Agenda Commenting Our Code Variable Review Button Program – Add Textbox Getting text from textbox Converting.
Chapter 8 First steps in modularisation. Objectives To introduce modularisation as a means of dividing a problem into subtasks To present hierarchy charts.
First Steps in Modularization. Simple Program Design, Fourth Edition Chapter 8 2 Objectives In this chapter you will be able to: Introduce modularization.
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.
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.
Modular Design Top-Down Design. Design is represented by a hierarchy chart. Break a problem into individual tasks or modules. If a module is too complex,
1 Programming Tools Flowcharts Pseudocode Hierarchy Chart Direction of Numbered NYC Streets Algorithm Class Average Algorithm.
FUNCTIONS. Topics Introduction to Functions Defining and Calling a Void Function Designing a Program to Use Functions Local Variables Passing Arguments.
CSC 1010 Programming for All Lecture 3 Useful Python Elements for Designing Programs Some material based on material from Marty Stepp, Instructor, University.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
 2006 Pearson Education, Inc. All rights reserved Control Statements: Part I.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
Chapter 2 - VB 2005 by Schneider- modified by S. Jane '081 Chapter 2 - Problem Solving 2.1 Program Development Cycle 2.2 Programming Tools.
Agenda  Take up homework  Loops - Continued –For loops Structure / Example involving a for loop  Storing Characters in variables  Introduction to Functions.
LESSON 1 Introduction to Programming Language. Computer  Comprised of various devices that are referred to as HARDWARE.  The computer programs that.
1 UMBC CMSC 104, Section Fall 2002 Functions, Part 1 of 3 Topics Top-down Design The Function Concept Using Predefined Functions Programmer-Defined.
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.
Chapter 2- Visual Basic Schneider1 Chapter 2 Problem Solving.
| MSC 8102:PROGRAMMING CONCEPTS By Vincent Omwenga, PhD. 1.
Victoria Ibarra Mat:  Generally, Computer hardware is divided into four main functional areas. These are:  Input devices Input devices  Output.
Computer Science: A Structured Programming Approach Using C1 Objectives ❏ To understand the structure of a C-language program. ❏ To write your first C.
Information and Computer Sciences University of Hawaii, Manoa
Topics Designing a Program Input, Processing, and Output
Introduction to the C Language
Chapter 4 C Program Control Part I
Value-Returning Functions
Algorithms An algorithm is a sequence of steps written in the form of English phrases that specific the tasks that are performed while solving the problem.It.
Lecture 2 Introduction to Programming
Introduction to the C Language
Topics Designing a Program Input, Processing, and Output
Topics Designing a Program Input, Processing, and Output
Basic Concepts of Algorithm
Module 3 Selection Structures 6/25/2019 CSE 1321 Module 3.
Presentation transcript:

IO and Module Charts. 1.Input format. 2. Output format. 3. Exception handling. 4.Top-down design.

1. Input format. §C# defaults to inputting all data in a string format. §This means that all data is represented simply as a series of characters (bytes). §Console.ReadLine () can be used “as is” if inputting to a string; §string Last_Name; Last_Name = Console.ReadLine ();

Input conversion. §In all other cases, the character string must be converted into the appropriate data type. using the methods in Convert, e.g. float Num1; Num1 = Convert.ToSingle (Console.ReadLine ()); double Num2; Num2 = Convert.ToDouble (Console.ReadLine ()); int Num3; Num3 = Convert.ToInt32 (Console.ReadLine ());

2. Output format. §When outputting complex data e.g. in table format, it is helpful to control the format so that there is a uniform left or right edge. §C# provides 2 main methods of formatting output: §(1) Place-holders (see Format1.cs) §(2) Display methods associated with each variable (see Format2.cs)

3. Exception handling. §This is an advanced topic, but the basic idea is simple. §If code is risky (e.g. there could be bad data, division by zero), then it is possible that an exception will be thrown (a run-time error). §If it is, and the exception isn’t handled, then either the program crashes or you may see bizarre output e.g. declaring you have an Infinite number of dollars!

Exception handling. §“I take exception to that remark….” §A programmer can prevent some problems by careful use of if else logic, e.g. §float Total, Count, Average; if (Count != 0) Average = Total / Count; else Console.Write (“Naughty person”);

Exception handling. §However, this is more difficult in some cases, especially if there is bad data. §In that case, it is recommended to enclose the risky code in a try { } and then handle exceptions in a catch (Exception) { } §See TryCatch.cs for a simple example.

4. Top-down design. §With simple projects, one can throw ideas out and hope one finds a solution (trial and error). §This is a bottom-up problem-solving approach, where we start at the bottom with individual ideas and hope that we can use them to build the complete solution (the top). §Compare: randomly pulling out legos, and assembling them blindfold. §Works for some projects, but….

Top-down design. §What is the limitation of this approach? §It cannot handle finely-tuned complexity. §E.g. what are the chances of assembling a replica of a Ferrari engine by randomly selecting engine parts and fitting them together, even with a large number of trials?

Top-down design. §A better approach is top-down design. We start at the top, with the whole problem, then gradually break it down into its main tasks, then analyze each of these into sub- tasks. E.g. §1) Build a computer desk. §2) Write a research paper. §3) Create a S/W application package.

Top-down design. §Remember our definition of “algorithm” emphasizes a step-by-step approach, so order matters. E.g. introduction before body before conclusion. §Top-down design generates a 3 rd form of algorithm representation, a module chart or hierarchy structure chart. See diagram.

Module charts. §What are the advantages? §A. Ensure solution consists of co-ordinated parts. §B.Avoid the sins of §(1) Omission, (2) Repetition, (3) Confusion. §C.Divide and Conquer.

Rules for module charts. §1.One well-defined function per module. §2.When a module is broken down into lower-level modules, the lower-level modules must be sub- problems of the original module. §3.Module chart lines can diverge, but unlike a flowchart, cannot converge. §4.On any given level, the order of tasks should be left to right. §5.Modules should be broken down gradually into lower-level modules e.g. from 1 to 3 or 4, but not 7 or 8.

In-class exercise. §See the specification for the actuarial program, “Financial Calculator,” which generates an amortization table for paying off a loan. §Without worrying about the detailed instructions, develop a module chart showing the main program tasks.