Вы находитесь на странице: 1из 25

Unit 18

Islamabad
Procedural
Programming
Unit 18
TABLE OF CONTENTS

INTRODUCTION 1

WHAT IS PROGRAMMING? 1

WHAT ARE CLASSIFICATION OF LANGUAGES? 1

CHRONOLOGY OF LANGUAGES 2

LEARNING OUTCOME NO.1 : UNDERSTAND THE PRINCIPLES OF PROCEDURAL PROGRAMMING. 3

WHAT IS PROCEDURAL PROGRAMMING? 3

|1.1|DISCUSS THE PRINCIPLES, CHARACTERISTICS AND FEATURES OF PROCEDURAL PROGRAMMING 4

HISTORY OF {C} LANGUAGE 4

PRINCIPLES OF {C} LANGUAGE 5

CHARACTERISTICS OF {C} LANGUAGE 5

FEATURES OF {C} LANGUAGE 6

LEARNING OUTCOME NO. 2 : BE ABLE TO DESIGN PROCEDURAL PROGRAMMING SOLUTIONS. 7

|2.1|IDENTIFY THE PROGRAM UNITS, DATA AND FILE STRUCTURES REQUIRED TO IMPLEMENT A GIVEN DESIGN. 7

|2.2|DESIGN A PROCEDURAL PROGRAMMING SOLUTION FOR THE GIVEN PROBLEM . 8

LEARNING OUTCOME NO.3 : BE ABLE TO IMPLEMENT PROCEDURAL PROGRAMMING SOLUTIONS. 9

|3.1|SELECT AND IMPLEMENT APPROPRIATE CONTROL STRUCTURES TO MEET THE DESIGN ALGORITHMS. 9

|3.2|CORRECTLY USE PARAMETER PASSING MECHANISMS OF C LANGUAGE IN YOUR SOLUTION. 10

|3.3|IMPLEMENT THE {C} LANGUAGE SOLUTION BASED ON THE PREPARED DESIGN. 11


LEARNING OUTCOME NO.4 : BE ABLE TO TEST PROCEDURAL PROGRAMMING SOLUTIONS. 13

|4.1|CRITICALLY REVIEW THE DEVELOPED CODE BY IDENTIFYING SYNTAX, LOGICAL AND RUNTIME ERRORS. 13

|4.2|ANALYSE ACTUAL TEST RESULTS AGAINST EXPECTED RESULTS TO IDENTIFY ANY DISCREPANCIES. 15

|4.3|EVALUATE FEEDBACK FOR ANALYSIS. MAKE RECOMMENDATIONS FOR IMPROVEMENTS IN SOLUTION. 17

|4.4|CREATE ONSCREEN HELP TO ASSIST THE USERS FOR YOUR PROGRAM. 17

|4.5|CREATE DOCUMENTATION TO PROVIDE SUPPORT FOR THE MAINTENANCE OF THIS C PROGRAM. 19


\\Introduction\>
Every computer system needs a basic input and output system, abbreviated as BIOS.

BIOS is a low level program which is written to function as a communicator and


mediator between the system and its operational devices that are attached to it,
such as memory or data storages and all Input output devices. Each device has
unique programming of its own that provides it with the possibility of communicating
with the system through the BIOS. Various layers of programming are required to
achieve complete synchronisation of hardware and software. Different layers require
different programming languages.

The three main layers of programming languages are\>

Low-Level (Machine) Language

Assembly (Interpreter) Language

High-Level Language

What is Programming?

The art of solving a program by breaking it down into various sets of instructions written
in a particular language that, when given to a machine, can be executed to perform
the desired task, also known as computation.

What are classification of Languages?

As mentioned above programming languages operate on various different layers.


Each layer utilises different languages, written in different styles, for different purposes.
All having different strengths and weaknesses, choosing the right one for any task is
very important.

Basic classification of language types is as below\>

1. Machine languages Interpreted directly in the hardware.


2. Assembly languages Layers over a corresponding machine language.
3. High-level languages Independent of any hardware.
4. System languages Low-level task handlers for memories or processes.
5. Scripting languages More independent than High-level languages.
6. Domain-specific languages Used for special purposes only.
7. Visual languages Non-text graphics based.
8. Esoteric languages Not intended to be utilised.

1
\\Chronology of Languages\>
There are numerous programming languages in today’s world. Each developed for its
own purpose. Some are unavailable or restricted. Some abandoned and some are
basically derived or compiled from other languages.

The most influential and renown languages are \>

 1957 ------------------------------------------------------------------------------- FORTRAN


|
 1958 ---------------------------------------------------------------------------------------- ALGOL
|
 1960 ------------------------------------------------------------------------------------ LISP, COBOL
|
 1962 ---------------------------------------------------------------------------------------- APL, SIMULA
|
 1964 ------------------------------------------------------------------------------------------ BASIC, PL/I
|
 1966 --------------------------------------------------------------------------------------------------- ISWIM
|
 1970 ---------------------------------------------------------------------------------------------------- Prolog
|
 1972 ------------------------------------------------------------------------------------------------------------ C
|
 1975 --------------------------------------------------------------------------------------- Pascal, Scheme
|
 1977 ------------------------------------------------------------------------------------------------------ OPS5
|
 1978 --------------------------------------------------------------------------------------------------- CSP, FP
|
 1980 -------------------------------------------------------------------------------------------------- dBase II
|
 1983 ------------------------------------------------------------------------ Smalltalk-80, Ada, Parlog
|
 1984 ---------------------------------------------------------------------------------------- Standard ML
|
 1986 ------------------------------------------------------------------------------- C++, CLP(R), Eiffel
|
 1988 ---------------------------------------------------------- CLOS, Mathematica, Oberon
|
 1989 ----------------------------------------------------------------------------------------- HTML
|
 1990 --------------------------------------------------------------------------------- Haskell

2
\\Learning Outcome No.1\>
Understand the principles of procedural
programming.

What is Procedural Programming?

\\Definition\>

A subclass of imperative programming, procedural programming is a method in which


a program is composed by specifying steps and procedures which are well-structured
and in series.

\\Explanation\>

Procedural programming is about well organising and predefining procedures,


functions and sub-routine calls in the program’s architecture by declaring all the
necessary steps and designing the paths that a system must follow to achieve the
desired results.

With one or several procedures in a program, the procedural language is splits into
variables, functions, statements and conditional operators. For performing tasks,
functions and procedures are implemented on the data and variables. Such
procedures are available anywhere within the program and can be invoked by other
operations as well.

Procedural programming contains statements, functions and commands in a


systematic order for any computations and calculations within a program.

\\Example\>

Common procedural language examples are\>

 C  Python  Ruby
 C++  Fortran  MATLAB
 C#  Pascal  ECMAScript
 Java  COBOL  Basic

3
|1.1|Discuss the principles, characteristics and features of
procedural Programming\>

Procedural programming, a subset of imperative programming, is an approach to


developing a program or application that focuses on the end results while keeping
the codes precise and passing through all steps that are provided within that code.

Before actually writing any program, a plan is developed in simple language that is
similar to a flowchart describing all the necessary arguments and statements.

All procedural languages have great differences between them based on how they
express, also, their range or extensibility of data types, facilities for modularity
implementation and run-time execution characteristics.

Thus, for convenience’s sake, the programming language chosen to be


implemented for describing all principles, characteristics and features of
procedural programming in this report is {C.}.

\\History of {C} Language\>

One of the descendants of ALGOL 60, the language C is actually a successor of a


language B which was the second attempt in developing a language for UNIX
powerful enough to handle the low-level programming combined and structured as
in high-level, in 1970.

Due to the availability of C on personal computers and because UNIX OS being


written almost totally in C, it has remained popular and stable over the years. C gives
the application and system developers command over their programs alike.

Several programming languages have descended based on C’s syntax such as C++,
Pearl, JavaScript, etc.

Timeline of the evolution of C\>

ALGOL BCPL B
INTERNATIONAL GROUP MARTIN RICHARDS KEN THOMPSON
1960 1967 1970

TRADITIONAL C K&R C ANSI C


DENNIS RITCHIE KERNIGHAN & RITCHIE ANSI COMMITTEE
1972 1978 1989

ANSI/ISO C C 99 C 11
ISO COMMITTEE STANDARDISATION COMMITTEE STANDARDISATION COMMITTEE
1990 1999 2011

4
\\Principles of {C} Language\>

The fundamental design principle for this procedural language is based on the
concept of “divide & conquer”, and is termed as the functional decomposition or
top-down design. The overall effort of the program is to separately disintegrate into
smaller logically subtasks, until each remaining sub task is adequately limited in scope
so as to permit employment within an operation of fittingly small size.

Every imperative procedural program consists of\>

 Declarative statements Values are given names.


 Imperative statements New variables are assigned values.
 Flow control statements Imperative statements evaluation order is defined.

\\Code Example\>

\\Characteristics of {C} Language\>

Following is a brief list of C’s characteristics that define this widely used professional
language.

 C language provides the fundamental control-flow structure that is required for


developing well-structured programs.

These control-flow constructions consist of\>

(if-else) For decision making and statement grouping.

(switch) To select a single set of possible values.

(for, while) Creating conditional loops and terminations at top.

(do) Creating terminations at the bottom.

(break) Exiting from the loops early.

5
 There is no input or output facility nor any read and write statement or file accessing
methods. All these are high level functions that are required to be explicitly called.

 This language has been superseded by other languages like C++, C#, Java.

 C programming language is supported by all modern compilers and it is easy to


write programs with because it is not tied to any distinct hardware or software.

 The size of the language is small and function calls are broadly used.

 Loose formatting is permissible and it has high-level constructs.

 Can handle low-level activities because low-level programming readily exists.

 Extensive pointer implementation use for memory, array, structures and functions.

 Programs produced in C language are efficient.

\\Features of {C} Language\>

The major features of this high-level language are\>

 Portability Independent of platforms; can be compiled on various systems


with multiple configurations without any change in code;
standard function libraries for all versions.

 Modularity Able to divide into multiple smaller modules; ease in debugging.

 Flexibility Control over the language with predefined reserved words and
access to low-level facilities.

 Speed Compiles and executes faster than other high-level languages


because it is closer to the hardware.

 Extensibility Language is extensible by allowing custom feature addition.

 Compactness Handful of reserved words with precise usage.

 Case Sensitivity Increasing more character input possibilities.

\\Code Example\>

6
\\Learning Outcome No. 2\>
Be able to design procedural
programming solutions.

|2.1|Identify the program units and data and file structures


required to implement a given design\>

\\Problem Definition\>

Design a Tic Tac Toe game program for two players. Allow them to place their marks
on the board. Determine and print the match result, with declaring the respective
player’s win or match being a tie. Additionally, it may offer a choice to play again.

\\Problem Analysis\>

Input Process Module Output

•Marks on the •Show Board •Print •Introduction


board
•Enter marks on •Read •Board
•Choice to play the board.
again •Marks
•Calculate Win or •Logic Operators
Draw
•Winner or Draw

•Repeat process •Logic Operators •Offer replay


until calculated

•Declare •Print
Winner or Draw

•Offer to play •Read


again.

•End

7
|2.2|Design a procedural programming solution for the given
problem \>

\\Design Solution\Pseudocode\>

Start: Game

Print: Introduction

Enter: Any Key to Continue

Clear: Screen

Print: Board

Enter: An Integer Between 1-9

Print: Respective Symbol On That Location

Check: Win or Tie

Switch: Player

Print: Result

Enter: Character Y to Replay, N to Exit

End: Game

8
\\Learning Outcome No. 3\>
Be able to implement procedural
programming solutions.

|3.1|Select and implement appropriate control structures to


meet the design algorithms in your solution\>

The control structures that are intended to be implemented to meet the design
algorithm in this problem are as follows.

 If \>

For creating the winning logic.

And printing conditions.

 While \>

To keep the game running until someone wins or match becomes a tie.

 Do While \>

For creating conditions in which a place cannot be replaced for the same round.

And to create a complete game loop if the user wants to play again.

9
 Goto \>

Necessary to break from within the loop if the match becomes a tie.

And to finish the game immediately if someone wins before the end of cycle.

|3.2|Correctly use parameter passing mechanisms of C


language in your solution\>

In programming, the parameters are passed from left to right direction.

The desired mechanism of passing an argument to function in current solution is\>

 Call by Value

Arrays will be used to declare spaces in the game board matrix.

And again, conditions used to develop game winning logic.

10
|3.3|Implement the {C} language solution based on the
prepared design\>

Following is the program developed in Dev C++

11
Program Complete.

12
\\Learning Outcome No.4\>
Be able to test procedural programming
solutions.

|4.1|Critically review and test the developed C code by


identifying the syntax, logical and run time errors in your
code\>

\\Syntax Error\>

Nominal syntax errors were located and resolved such as the following\>

Missing a semicolon; at the end of ‘Counter++’ statement.

\\compiler’s message\>

Missing a delimiter {} before closing the ‘do while’ statement.

\\compiler’s message\>

13
\\Logical Error\>

Program is failing to declare win for 2nd player but executes successfully for the 1st.

- - Player 1 - - - - Player 2 - -

Difference of missing brackets () found within the function declaration.

Another problem is that there is no input limit applied, so program can take any
input but if it is not within the defined space, it does not show on screen and skips to
the next player.

Resolved by adding the above conditional statement for each player.

\\Run-time Error\>

If ‘%s’ was chosen for storing variable character in the matrix ‘M [ ] ’, the following
run time error was displayed.

It was handled by changing the ‘%s’ to ‘%c’, and the program executed successfully.

14
|4.2|Analyse actual test results against expected results through
sample test data to identify any discrepancies\>

\1\Testing Phase\Launch\>

\2\Testing Phase\Input\>

15
\3\Testing Phase\Complete\>

\4\Testing Phase\Invalid String Input\>

Thus, this program will not be able to handle false string input instead of integers.

16
|4.3|Evaluate the feedback for the above analysis and make
recommendations for the improvements in your solution\>

Recommendations \>

 Display could further be aligned. Done

 Another option to play as a Single Player could be implemented. Done

 Text could be displayed in different colours. Done

 Effects could be generated to make it more interesting. Done

 End credits could be added to improve developer recognition. Done

|4.4|Create onscreen help to assist the users for your program\>

On Screen help has already been implemented\>

17
New menu has been created with the addition of more features\>

Turns and indicators are also included\>

18
|4.5|Create documentation which should provide support for
the maintenance of this C program\>

\\Code Maintenance\>

All support for code maintenance is given within the written code of the program\>

19
Program Complete.

20
\\Technical Support\>

Author \> AbdulRafay Moeen

Project \> Tic Tac Toe Console Game

Academic Class \> BTEC HND Computing and System Development

Development Date \> 31st December 2015

Application Name \> Tic Tac Toe

Application Category \> Entertainment \Game

Final Application Version \> 2. 5

Program Language \> ‘C’

IDE Environment \> Dev C ++

Testing Environment \> Microsoft Windows 10

Performance Evaluation \> N/A

Module \> N/A

Code Dependencies \> None

Application Interface \> Console Window

User Interface \> Users prompted for input of integers as values

Data Representation \> One-dimensional array input translated into X/O’s

21

Вам также может понравиться