Structured Programming PDF

Title Structured Programming
Author Daniel Nyagechi
Course Programming Fundamentals
Institution Monash University
Pages 71
File Size 1.2 MB
File Type PDF
Total Downloads 102
Total Views 135

Summary

Daniel Self Taught Module...


Description

Hardwares Hardware - Physical components that make up a computer system. Hardware is a comprehensive term for all of the physical parts of a computer, as distinguished from the data it contains or operates on, and the software that provides instructions for the hardware to accomplish tasks. Software Computer programs and related data that provide the instructions for telling computer hardware what to do and how to do it. Classification of computer soft wares The three main classifications of software that all programs fit under are: System software Application software Programming languages System software Software designed to operate the computer hardware and to provide a platform for running application software. System software will handle the smooth running of all the components of the computer as well as providing general functionality for other programs to use, tools to speed up the computer, tools to develop new software and programs to keep you safe from attacks. Types of system softwares Operating Systems are a collection of programs that make the computer hardware conveniently available to the user and also hide the complexities of the computer's operation such as Windows 7 or Linux, XP. The Operating System is also an interface between the application software and computer. Utility programs are small, powerful programs with a limited capability, they are usually operated by the user to maintain a smooth running of the computer system. Various examples include file management, diagnosing problems and finding out information 1

about the computer etc. Notable examples of utility programs include copy, paste, delete, file searching, disk defragmenter, disk cleanup. However, there are also other types that can be separately installable from the Operating System. Library programs are a compiled collection of subroutines Translator software (Compiler, Assembler, Interpreter) Application software Software designed to help the user to perform specific tasks. Application software is designed for people like me and you to perform tasks that we consider useful. This might be the ability of a scientist to work out statistical information using a set of results, or someone who wants to play the latest computer game. Categories of Application software Application packages(general purpose softwares) User programs(special purpose softwares) History of programming languages Machine languages (First generation languages) Programming language that can be directly understood and obeyed by a machine or computer without conversion or translation. Different for each type of CPU, it is the native binary language (comprised of only two characters: 0 and 1) of the computer and is difficult to be read and understood by humans. Programmers commonly use more English-like languages (called high level languages) such as Basic, C, Java, etc., to write programs which are then translated into machine language (called a low level language) by an assembler, compiler, or interpreter. Low level language A machine language or an assembly language. Low-level languages are closer to the hardware than are high-level programming languages, which are closer to human languages. Low-level language is a programming language that deals with a computer's hardware components and 2

constraints. It has no or a minute level of abstraction in reference to a computer and works to manage a computer's operational semantics. Low-level languages are considered to be closer to computers. In other words, their prime function is to operate, manage and manipulate the computing hardware and components. Programs and applications written in low-level language are directly executable on the computing hardware without any interpretation or translation. Examples of low level language Machine language Assembly language High level languages Usually machine-independent, sophisticated programming language that uses familiar English (or any human language) like syntax. In a HLL, each statement can represent several assembly language instructions that perform complex computing operations. It allows programmers to concentrate on application development without bothering with the underlying machine architecture. High-level language is any programming language that enables development of a program in much simpler programming context and is generally independent of the computer's hardware architecture. High-level language has a higher level of abstraction from the computer, and focuses more on the programming logic rather than the underlying hardware components such as memory addressing and registers utilization. Examples of HLL C Pascal Visual Basic C++ FORTRAN COBOL

3

4th generation language End-user friendly, high-level computer language. Provides the capability for non-programmers to write fairly short programs as queries to databases to generate custom reports. A fourth generation (programming) language (4GL) is a grouping of programming languages that attempt to get closer than 3GLs to human language, form of thinking and conceptualization. 4GLs are designed to reduce the overall time, effort and cost of software development. The main domains and families of 4GLs are: database queries, report generators, data manipulation, analysis and reporting, screen painters and generators, GUI creators, mathematical optimization, web development and general purpose languages. Examples of 4th Generation languages MSSQL MySQL Oracle Fifth Generation (Programming) Language (5GL) A fifth generation programming language (5GL) is a grouping of programming languages build on the premise that a problem can be solved, and an application built to solve it, by providing constraints to the

program

(constraint-based

programming),

rather

than

specifying

algorithmically how the problem is to be solved (imperative programming). In essence, the programming language is used to denote the properties, or logic, of a solution, rather than how it is reached. Most constraint-based and logic programming languages are 5GLs. A common misconception about 5GLs pertains to the practice of some 4GL vendors to denote their products as 5GLs, when in essence the products are evolved and enhanced 4GL tools. Examples of 5GLS Artificial intelligence Expert systems Programming techniques Structured programming A method of writing a program that uses top down analysis to solve a problem, modularization for a program structure and organization and structured code for individual modules. Techniques that impose a logical structure to the coding of a program in order to make it easy to 4

follow. Large routines are broken down into small modules that have to be methodically and carefully nested within each other. A programming language in which the entire logic of the program is written by dividing it into smaller units or modules. In C and Pascal, the smaller units are referred to as functions. A function is written separately to perform a specific task. Each function has a unique name. It is called for execution in the main body of program with reference to its name. Advantages Programs are more quickly and easily written Program have greater reliability Programs require less time to debug and test Programs are easy to maintain Easy to modify and to debug Limitations Time consuming In case of a problem it will require reprogramming Unstructured programming A programming language in which the entire logic of the program is written as a single continuous (nonstop or unbroken) block. Small and simple programs consisting only of one main program. A sequence of commands or statements which modify data (global) throughout the whole program Limitations Very difficult to modify Very difficult to debug Object oriented programming It consists of identifying objects and how to use these objects in the correct sequence to solve the problem. In other words, object oriented problem solving can consist of designing objects whose behavior solves a specific problem. A message to an object causes it to perform its operations and solve its part of the problem. Object oriented problem solving approach Identify the problem Identify the objects needed for the solution Identify messages to be sent to the objects Create a sequence of messages to the objects that solve the problem. Internet based programming Internet programming refers to the process of web development where programming procedures are designed and incorporated into internet websites to enable functionality of a website and all 5

other functions involved in the smooth running of the website. This involves attributes like website security, database management, online runtime mathematical functions and more. The typical programming languages are used to achieve this, but are used in small pieces and can be inserted into the html web pages or called from secured folders by a web page. These languages are Vbscripts, Javascripts, Perlscripts, and CGI. Database programming/development is also to be considered a part of internet programming. Internet based programming refers to the writing, markup and coding involved in Web development, which includes Web content, Web client and server scripting and network security. Visual programming Visual programming language is a programming language that uses graphical elements and figures to develop a program. Employs techniques to design a software program in two or more dimensions, and includes graphical elements, text, symbols and icons within its programming context. A programming language that uses a visual representation (such as graphics, drawings, animation or icons, partially or completely) A visual language manipulates visual information or supports visual interaction, or allows programming with visual expressions. A visual language is a set of spatial arrangements of text-graphic symbols with a semantic interpretation that is used in carrying out communication actions in the world. Visual programming language enables the development of software programs by eliminating textual software code with a series of visual graphics elements. Incorporates these graphical elements as the primary context of the language arranged in a systematic order. The graphics or icons included within a visual program serve as input, activities, connections and/or output of the program. Visual language has a few types, such as icon-based languages, diagramming languages and form-based language. Visual languages should not be confused with GUI-based programming language as they only provide graphical program authoring services. However, their code/context is completely textual. Computer hardware and software consideration Hardware requirements for structured programming Portability Compatibility User friendly Portability

Software considerations for visual programming Appropriate operating system Ease of learning Ease of understanding Speed of development Help with enforcement of correct code 6

Performance of compiled code Supported platform environments Portability Ease of Learning Clearly, the easier that the programming language is to learn, the quicker that programmers become productive. Java is a lot easier to learn than C++; C is probably even easier. But you learn once and program for a long time, so that ease of learning is of only limited value. Ease of Understanding Most code is written once and read many times usually, to focus on a particular point. Thus, it is important that the reader quickly grasp the essence of what’s happening. Speed of Development If you look at speed of development in the round, you must consider not only how long it takes you to write code, but also how long it takes you to find a solution to the problem at hand and find the bugs. Help with Enforcement of Correct Code The ideal programming language should turn logic errors into syntax errors. A powerful means to this end is type checking. Most standard languages, such as Java and COBOL, have good type checking. But some languages have an escape clause. Performance of Compiled Code Supported Platform Environments By platform environment, I mean not only the operating-system facilities, but also the middleware facilities, database facilities, and system-management facilities. Portability Programming development and design Program Computer program is a set of instructions for a computer to perform a specific task. Programs generally fall into these categories applications, utilities or services. Program development The process of formulating codes in a computer program. Program development involves coding a given task in a programming language 7

Program design The activity of progressing from a specification of some required program to a description of the program itself. The input to this phase is a specification of what the program is required to do. During the phase the design decisions are made as to how the program will meet these requirements, and the output of the phase is a description of the program in some form that provides a suitable basis for subsequent Characteristics of a good program Clarity Robustness Reliability Efficient Program development cycle a)

Problem solving phase i.

Analysis and specification Understand (define the problem and what the problem must be.

ii.

General solutions(program) Develop a logical sequence of steps to be used to solve the problem.

iii.

Verify Follow the steps exactly to see if the solution really does solve the problem.

b)

Implementation phase i.

specification solution Translate the algorithm into a programming language (code).

ii.

Test Have the computer follow instructions and then check the results. If you find errors, analyze the program and the algorithm to determine their source and then make corrections.

c)

Maintenance phase i.

Use the program. Let users use the program and see if it meets it needs.

ii.

Maintain

Modify the program to meet changing needs from end-users, or correct any routine errors that may show up in using it.

8

Program design tools Flow chart A flow chart is a graphical method of designing programs. A well-drawn flow chart is also very easy to read since it basically uses just two symbols, two decision constructs and two iteration constructs. Flow chart symbols Oval - The start/stop symbol. Start

The diamond

Decision

Rectangle - The input symbol. Process

Parallelogram – input/output. Input/output

The Line - connector

9

The process symbol represents a process, action, or function. It’s the most widely-used symbol in flowcharting.

The document symbol represents the input or output of a document. Examples of input are receiving a report, email, or order. Examples of output are generating a presentation, memo, or letter.

The decision symbol indicates a question to be answered—usually yes/no or true/false. The flowchart path may splinter into different branches depending on the answer.

The connector symbol connects separate elements across one page. It’s usually used within complex charts.

The off-page connector (also known as the off-page link) symbol connects separate elements across multiple pages. It is frequently used within complex charts. The page number is sometimes placed on the shape for easy reference.

The data symbol (also called the input/output symbol) represents data that is available for input or output. It may also represent resources used or generated. The paper tape symbol also 10

represents input/output, but is outdated and no longer in common usage. Another symbol used to represent data is the circle shape.

The comment symbol, or note symbol, adds needed explanation or comment. It may be connected by a dashed line to the relevant section of the flowchart.

The stored data symbol represents data housed on a storage device.

The summing junction symbol sums the input of several converging paths.

The terminator symbol represents the start points, end points, and potential outcomes of a path.

The predefined process symbol indicates a complicated process or operation that is well-known or defined elsewhere.

The internal storage symbol represents data stored in random-access memory (RAM).

11

The manual input symbol represents the manual input of data into a computer, usually through a keyboard.

The manual operation symbol indicates a step that must be done manually, not automatically.

The merge symbol combines multiple paths.

The multiple documents symbol represents multiple documents or reports.

The preparation symbol differentiates between steps that prepare for work and steps that actually do work.

12

Example 1 Construct a flow chart that can be used to get the sum of two numbers.

Start

Enter values x and y

Sum = x + y

Sum

Stop

Example 2

Example 3 13

Assignment Draw a flowchart to depict all steps that you do reach your college Algorithms This is a step by step process of solving a problem by executing a series of actions in a specific order. A procedure of solving a problem in terms of actions to be executed and the order in which they are to be executed. Algorithm is also an ordered sequence of unambiguous and well defined instructions that performs some task and halts in finite time. A sequence of activities to be processed for getting desired output from a given input. A formula or set of steps for solving a particular problem. To be an algorithm, a set of rules must be unambiguous and have a clear stopping point. An ordered sequence means that you can number the steps Unambiguous and well-defined instructions means that each instruction is clear, do-able, and can be done without difficulty Performs some task halts in finite time

Example 1 14

Problem 1: Find the area of a Circle of radius r. Inputs to the algorithm Radius r of the Circle Expected output Area of the Circle Algorithm Step1: Read input the Radius r of the Circle Step2: Area PI*r*r Step3: Print Area Step: stop Example 2 Write an algorithm to read two numbers and find their sum Inputs to the algorithm First number1 Second number2 Expected output Sum of the two numbers Algorithm Step1: Start Step2: Read //input the first number1 Step3: Read //input the second number2 Step4: Sum number1+number2 Step5: Print Sum Step6: End Example 3 Write algorithm to find the greater number between two numbers Step1: Start Step2: Read // input A and B Step3: If A greater than B then C=A Step4: if B greater than A then C=B Step5: Print C Step6: End Example 2 Step1: Start Step2: Read/input A, B and C Step3: If (A>=B) and (A>=C) then Max=A Step4: If (B>=A) and (B>=C) then Max=B Step5: If (C>=A) and (C>=B) then Max=C Step6: Print Max Step7: End 15

Pseudo code This is an artificial and informal language that helps programmers to develop algorithms. Pseudo code programs are not executed in the computer. They help a programmer to think out a problem/program before attempting to write on a computer programming language. PseudoCode is simply a numbered list of instructions to perform some task. Example 1 Write a pseudo-code to that allows input of three numbers from the keyboard and output the ir sum. Use variables: sum, number1, number2, number3 of type integer Accept number1, number2, number3 Sum = number1 + number2 + number3 Print sum End program Example 4 A pseudo-code describes an algorithm which will accept two numbers from the keyboard and calculate the sum and product displaying the answer on the monitor screen. start program Use variables sum, product, number1, number2 of type real display “Input two numbers” accept number1, number2 sum = number1 + number2 print “The sum is “, sum p...


Similar Free PDFs