Tải bản đầy đủ (.docx) (16 trang)

Assignment1 Procedural Programming

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (374.27 KB, 16 trang )

TABLE OF CONTENTS

Contents
Assignment Brief 1 (RQF).........................................................................................5
Higher National Certificate/Diploma in Computing.................................................5
1.

Introduction to procedural programming (P1, M1)........................................7

1.1. Introduction (P1).................................................................................................7
1.2. Key features of procedural programming (M1)...................................................7
1.3. Characteristics of procedural programming (M1)...............................................8
2.

Analysis (P2).........................................................................................................8

2.1

Data types and data structure............................................................................8

2.2

Conditional sentences........................................................................................9

2.3

Loop................................................................................................................... 9

2.4

Switch - Case................................................................................................... 10



3.

Design diagrams for the program (P3).........................................................12

3.1

Use-case diagram............................................................................................ 12

3.2

WBS (Work Breakdown Structure)...................................................................12

3.3

Flowcharts........................................................................................................ 13

4.

Review the design of procedural programming solution (M2)...................17

5.

Evaluate the design of my solution (D1)......................................................18

References................................................................................................................19


ASSIGNMENT 1 FRONT
SHEET

Qualification

BTEC Level 5 HND Diploma in Computing

Unit number and
title

PROG102 : Procedural Programming

Submission date

Date Received 1st
submission

Re-submission
Date

Date Received 2nd
submission

Student Name

Student ID

Class

Assessor name

Student declaration
I certify that the assignment submission is entirely my own work and I fully understand the

consequences of plagiarism. I understand that making a false declaration of malpractice.

Student’s signature

Grading grid
P1

P2

P3

M1

M2

D1


 Summative Feedback:

Grade:

 Resubmission Feedback:

Assessor Signature:

Date:

Lecturer Signature:


1. Introduction to procedural programming (P1, M1)
1.1. Introduction (P1)
- A programming language is a vocabulary and set of grammatical rules for
instructing a computer or computing device to perform specific tasks.
Each programming language has a unique set of keywords (words that it
understands) and a special syntax for organizing program instructions.
 There are two main types of programming languages: low level
languages (closeness to machine code (0s and 1s). Such as:
machine language, assembly language,.) and high level languages
(closeness to the human-language. Such as: C, FORTRAN, or
Pascal, ...).
- Procedural programming is a programming paradigm built around
the idea that programs are sequences of instructions to be
executed.
- Procedural programming focus heavily on splitting up programs into
named sets of instructions called procedures, analogous to
functions. The basic idea is to have a program specify the
sequence of steps that implements a particular algorithm.
1.2. Key features of procedural programming (M1)
-

Predefined functions: A predefined function is typically an instruction
identified by a name. Usually, the predefined functions are built into
higher- level programming languages, but they are derived from the
library or the registry, rather than the program. One example of a predefined function is ‘charAt()’, which searches for a character position in


-

-


-

1.3.

2.

a string.
Local Variable: A local variable is a variable that is declared in the
main structure of a method and is limited to the local scope it is given.
The local variable can only be used in the method it is defined in, and if
it were to be used outside the defined method, the code will cease to
work.
Global Variable: A global variable is a variable which is declared outside
every other function defined in the code. Due to this, global variables can
be used in all functions, unlike a local variable.
Modularity: Modularity is when two dissimilar systems have two
different tasks at hand but are grouped together to conclude a larger
task first. Every group of systems then would have its own tasks finished
one after the other until all tasks are complete.
Parameter Passing: Parameter Passing is a mechanism used to pass
parameters to functions, subroutines, or procedures. Parameter Passing
can be done through ‘pass by value’, ‘pass by reference’, ‘pass by result’,
‘pass by value-result’ and ‘pass by the name’.

Characteristics of procedural programming (M1)
The characteristics of procedural programming are:

Procedural programming follows a top-down approach.


The program is divided into blocks of codes called functions, where
each function performs a specific task.

Procedural programs model real-world processes as 'procedures'
operating on 'data'.

The data and functions are detached from each other.

The data moves freely in a program.

It is easy to follow the logic of a program.

A function can access other function's data by calling that function.

2 The analysis for the program (P2)

2.1 Explain wants to manage grades of a class problem:
- A function enters student IDs, student’s grades and store these
information into 2 separate arrays (integer array for IDs and float array
for grades).
-A function to print all student IDs together with their grades.
-A function to know which student has highest grade and lowest grade.
-A menu creation function for the user to choose from.
-A function to make a loop back to the menu for the user to choose
from other options, there is an exit option so the user can exit the loop.
2.2 Variables and data types required in the program

❒ 2 arrays:

 studentID (type integer): store ID of the student(s).

 studentGrade (type float): store grade of the student(s).

❒ choice (type integer): store option of the teacher’s choice.
❒ total (type integer): store number of students in the class.
❒ min (type float): store the lowest grade of the class.


❒ max (type float): store the highest grade of the class.
2.3 Selection structures in the program (if, else, switch...)
 If: use for comparison between numbers to figure out the highest and the
lowest grade. In the context of the scenario, if statements use in 3 functions in
the program: Find the highest grade, and find the lowest grade.
 Find the highest and the lowest grade function: if statements use to
compare numbers in the array of grade. Thus, program can figure out
the highest grade and the lowest grade of the class.
 The position of these if statements can be used in the iteration
constructs.


Switch: use to control statement that allows some group of statements to be
chosen from several available functions.
 In the context of the scenario, switch statements use to allow function
variable to be compared with several possible case labels, which are
represented by constant values. If the function variable matches with
one of the constants, then an execution jump is made to that point. A
case label cannot appear more than once and there can only be one
default expression.
 The position of switch statement can be used in the menu part.

2.4 Iteration constructs in the program (for, while, do... while)

 Iteration constructs used to repeat a statement or a set of statements for a
specified number of times or until a condition satisfied.
• In the program, for statements used to:
 Get the value of ID(s) or grade(s) and print to the screen.
 Repeat if statements to check the value which is higher or lower
grade.
• In the program, the do… while construct executes its sequence at least
once and continues executing it as long as the test condition is true.
do… while statement used in the menu section to repeat checking the
value which is enter from user and collaborate with switch statement to
choose the function that user wants.


In the program, the while construct executes its sequence as long as the
test condition is true. While statements used in input function in order to
check the number of student in class (make sure it is greater than 0),
check ID (make sure it is greater than 0), and check grade (make sure it
is in the range 0-10).


2.5 Split the program into functions (sub-functions) and hierarchy diagram
Functions:
 main(): To print menu to the screen and controls program execution by
directing the calls to other functions in the program.
 inputStudentID(): To enter ID of student(s) from user keyboard.
 InputStudentGrade(): To enter grade of student(s) from user keyboard.
 max(): To find the student ID which has the highest grade from the ID list.
 min(): To find the student ID which has the lowest grade from the ID list.



2.6 Testing and Debugging
- Testing is the process of verifying and validating that a software or application
is bug free, meets the technical requirements as guided by its design and
development and meets the user requirements effectively and efficiently with
handling all the exceptional and boundary cases.
- Debugging is the process of fixing a bug in the software. It can be defined as
the identifying, analyzing and removing errors. This activity begins after the
software fails to execute properly and concludes by solving the problem and
successfully testing the software. It is considered to be an extremely complex and
tedious task because errors need to be resolved at all stages of debugging.
2.7 Maintenance
 Program maintenance is the process of modifying a software or program after
delivery to achieve any of these outcomes:





Correct errors
Improve performance
Add functionalities
Remove obsolete portions


3. Design
3.1. Use-case
3.1 Use-case diagram

Explain:
There are four function that user (exactly is teacher) can approach to do in the

program. In the program, input student ID(s), input student name(s), and input
grade(s) function will be used for storing the values that user input. Coupled with that,
first-two functions will be used to linked with two other functions to get the value from
these functions and show the results that user want.
3.2 WBS (Work Breakdown Structure)
 The Work Breakdown Structure (WBS) is the tool that utilizes this technique and
is one of the most important project management documents. It singlehandedly
integrates scope, cost and schedule baselines ensuring that project plans are in
alignment. A Deliverable-Based Work Breakdown Structure clearly demonstrates the
relationship between the project deliverables) and the scope.


3.3. Flowcharts.
⚫ Menu operation

Explain:
The user will choose one of these choices, after that, the program will read the
value that user input to “choice” variable, if the choice - variable of selection - equal
with a number that link to a function, the user will get their expected.


Input ID(s), Grade(s)


Explain:


Start with the value i=0.




Compare iterminates. If True is returned, go to the next step.



Enter information into ID, grade[i].



Increase the value of i by 1.



Return to the i

Printing ID(s), and grade(s)

Explain:


In function printing, the program will get data from input of user, run a loop depends
on i – count variable – if it lower than num (amount of student) the program will print
the ID, grade. If i greater than num, the function will stop.

⚫ Finding max grade

Explain:



In function finding max, the program will get the data from input of user, declare a
count variable i start from 0 and assign max equal grade[0]. The program will run
a loop (by i – count variable) and in the loop, program will compare grade[i] with




max variable, if grade[i] greater than max, max will be assigned as grade[i].
If i less than num, the program will print max to the screen and stop the program.

⚫ Finding min grade

Explain:
In function finding min, the program will get the data from input of user, declare a
count variable i start from 0 and assign min equal grade[0]. The program will run a
loop (by i – count variable) and in the loop, program will compare grade[i] with min


variable, if grade[i] less than min, min will be assigned as grade[i]. If i less than num,
the program will print min to the screen and stop the program.

4.Evaluation.
4.1. About my solution.
About analysis:
Advantages: I have used a table to describe the data type, the loop in the most
intuitive way, making it easy for the reader to understand the definition and why I
use it. I also added illustrations for the explanation. Each
individual function will have a different picture.


Disadvantages: All its benefits have not been thoroughly analyzed.
About WBS:
Advantages: Defined, draw WBS with full main functions of the program. All
functions explained below.
Disadvantages: Lack of extra function is Exit.
Flowchart:
Advantages: Defined, draw flowcharts for all program functions and main interface,
explain in detail the steps.
Disadvantages: Flowchart drawn is not intuitive, the size is not uniform.

4.2. Evaluate how procedural programming is applied to your
problem.
Advantages:
Procedural programming has optimal statements for specific functions. There are
built-in functions for printing and importing. There are library declarations needed
for calculations or arrays.
Data types like int, float, char are for the specific objects I need like name, grades,
… Gather all the necessary information in one place using a struct. Loops, switchcase and conditional statement are suitable for calculating, comparing and
retrieving information in arrays. Functions are in separate places but can come
together to form a perfect function. All are broken down, so it’s easy to check,
repair, optimize the program.
Disadvantages:
Must use a lot of functions: min, max functions are not much different but have to
reprogram a lot of commands => can’s inherit command line. The entered
parameter data is not cleared causing the screen to fill up. It takes many steps to
implement a simple algorithm like swapping positions.


Difficulties:
If there is more input, more variables and more complex algorithms are needed. If you

want to optimize the algorithm, you have to revise the whole program because the
functions have some association with each other => optimization is difficult.

5. Conclusion.
After completing this exercise, I have grasped the basic theoretical knowledge
about procedural programming along with the effects of statements and functions
in the program, explaining the reasons for using statements, structures, etc. that
bamboo. I already know how to build flowcharts, use cases, WBS, I also know how
to divide them by functions and clear analysis on how it works, conditions of
occurrence, return values, ...

Besides In addition, some better solutions for the program are given by me, which
will help the program work better. The assessment is carefully analyzed on the
advantages, disadvantages, difficulties encountered. Finally, the assignment was
combined with full information and citations. I think it will help me to complete my
next assignments in the future.

Reference list
1.
Kumar, K. and Dahiya, S., 2017. Programming languages: A survey. International
Journal on Recent and Innovation Trends in Computing and Communication, 5(5),
pp.307-313.
2.
Moore, S., 2014. Key Features Of Procedural Programming. [online] Available at:
< [Accessed 8 July 2021].
3.
Cohen, E., 2018. What is WBS (Work Breakdown Structure) in Project
Management?. [online] Workamajjg blog. Available at:
< />[Accessed 2 July 2021
4.

Loshin, D. and Lewis, S., 2021. data structures. [online] Techtarget. Available at:
< [Accessed 4 July
2021].
5.
Chapin, N., 2003. Flowchart. Encyclopedia of Computer Science, pp.714– 716.




×