Tải bản đầy đủ (.pdf) (56 trang)

PRO102 A1 DISTINCTION FPT

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 (2.08 MB, 56 trang )

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

Tran Duc Long

Student ID

GCH210562

Class

GCH1106

Assessor name


Dinh Duc Manh

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 is a form of malpractice.
Student’s signature

Long

Grading grid
P1

1|Page

P2

P3

M1

M2

D1


❒ Summative Feedback:

❒ Resubmission Feedback:

2.1


Grade:
Lecturer Signature:

2|Page

Assessor Signature:

Date:


Table of Contents
A- INTRODUCTION. ................................................................................................................................................................................. 5
B- TASK 1....................................................................................................................................................................................................... 5
I. Programming Language. .................................................................................................................................................................... 5
1. What is Programming Language................................................................................................................................................ 5
2. Definition........................................................................................................................................................................................... 5
3. Features of Programming Language......................................................................................................................................... 6
4. Compile.............................................................................................................................................................................................. 8
5. Interpreter. ......................................................................................................................................................................................... 8
6. Types of programming language. .............................................................................................................................................. 9
II. Procedural Programming................................................................................................................................................................10
1. What is Procedural Programming. ..........................................................................................................................................10
2. Definition. .......................................................................................................................................................................................10
3. Functions. ........................................................................................................................................................................................10
4. Key Features of Procedural Programming............................................................................................................................11
5. Code examples...............................................................................................................................................................................13
6. Comparing with Object Oriented Programming(OOP). ..............................................................................................15
7. Problem statement. ....................................................................................................................................................................15
a. Business Problem:.......................................................................................................................................................................15

b. Discuss:............................................................................................................................................................................................16
C-TASK 2 ......................................................................................................................................................................................................18
I. Identify the Variables in the program. .........................................................................................................................................18
1. Variables and Declare the Variable. .......................................................................................................................................18
a. Variables: .........................................................................................................................................................................................18
b.Variable Declaration: ....................................................................................................................................................................18
2. Conclude..........................................................................................................................................................................................19
II. Identify and Describe Selection Structure. ...............................................................................................................................21
1. What is the Selection. ..................................................................................................................................................................21
2. Function. ..........................................................................................................................................................................................21
3. “if...else” statement. .....................................................................................................................................................................21
4. “if...else” ladder .............................................................................................................................................................................22
5. Switch case statement..................................................................................................................................................................24
6. Conclusion. ...............................................................................................................................................................................26
III. Identify and describe loop structs. .........................................................................................................................26
3|Page


1. loop: for ....................................................................................................................................................................................26
2. loop: do…while.....................................................................................................................................................................27
3. Loop While ................................................................................................................................................................................29
4. Conclusion.................................................................................................................................................................................31
C-TASK 3: ....................................................................................................................................................................................................31
I. WBS: .....................................................................................................................................................................................................31
II. A use case diagram for actions required. .................................................................................................................................35
III. Flowchart ...........................................................................................................................................................................................37
1. Program main:................................................................................................................................................................................37
2. UserLogin: ......................................................................................................................................................................................39
3. Check character is number or letter: .......................................................................................................................................41
4. integer and float check ................................................................................................................................................................43

5. Enter information student:..........................................................................................................................................................44
6. Add a new student and arrange student’s id in ascending order: ...................................................................................45
7. Search ID and Grade: ..................................................................................................................................................................47
8. Find students with the highest or lowest score: ...................................................................................................................48
9. Show student’s list: ......................................................................................................................................................................51
D-TASK 4: ....................................................................................................................................................................................................51
Evaluation:...............................................................................................................................................................................................51
Choice menu.......................................................................................................................................................................................52
Show id and grade, min and max ..............................................................................................................................................52
E-Conclusion: ...............................................................................................................................................................................................52
Quote: ..............................................................................................................................................................................................................52

4|Page


A- INTRODUCTION.


We are living in the 4.0 era. Thus, there is a lot of innovation happening every day, particularly
in technology. When it comes to technology, we undoubtedly consider laptops or phones that
have improved our lives. Procedural programming and programming languages also play
significant roles in the interaction between users and computers. Additionally, it is essential in
generating software applications from computers to work and manage in order to make people's
life simpler and easier. Additionally, this contributes to the modernization, advancement, and
development of life.
● In this assignment, I will write in detail about the programming language, procedural
programming, and some of the information I will use to write code, such as variables, conditional
statements, or loops, as well as its function and characteristics.
B- TASK 1
I. Programming Language.

1. What is Programming Language
● Programming Language are exceptional language and it is created to help programmers to write
instruction that allows a machine to perform one or more tasks. (Anon., 2019)
● The vocabulary of computers only includes 1 and 0 (binary).

2. Definition

5|Page




A programming language is a system of notation for writing computer programs. Most
programming languages are text-based formal languages, but they may also be graphical. They are
a kind of computer language.

3. Features of Programming Language.
● We all know that the popularity of a programming language base on the characteristic and utilities
that it is provides to programmer. The features that a programming language have to stand out are
the following.
➢ Simplicity: Language must offer clear and simple concepts that make learning and
application easier to understand and maintain. Simplicity doesn’t mean it can be
subtracted from the maximum working capacity. (Anon., n.d.)

➢ Efficiency: Programming languages must be quickly interpreted and implemented so
as not to take up too much memory space or take too much time. (Anon., n.d.)

6|Page



➢ Abstraction: This is the ability to define and use complicated structures or operations
while ignoring certain details which affect the ability to write. (Anon., n.d.)

➢ Compactness: Using this attribute, operations can be presented in a succinct manner,
without writing too many descriptions. (Anon., n.d.)

7|Page


4. Compile.


Compilers are computer programs that translate a high-level programming language to a low-level
programming language. The product of a compiler is an executable file, which is made of
instructions encoded in a specific machine code. Hence, an executable program is specific to a type
of computer architecture. Compilers designed for distinct programming languages might be quite
different; nevertheless, they all tend to have the overall macro-architecture described in the figure
below:

5. Interpreter.
● In computer science, an interpreter is a computer program that directly executes instructions
written in a programming or scripting language, without requiring them previously to have been
compiled into a machine language program.
● The interpreter converts the high-level program into an intermediate language it then executes, or it
can translate the source code at the high-level and then directly execute the commands, which is
done line by line or statement by statement. (Anon., n.d.)
8|Page


6. Types of programming language.

● There are many types of programming languages available in the market. All of these different
types of programming languages have their own functionalities and specialties. Depending on the
functions and abilities of these languages, they are classified into three main types.
+ Machine language.
+ Assembly language.
+ High-level language.

9|Page


● A high-level language is a programming language designed to streamline programming for
computers. It is called high-level because the central processing unit (CPU) of a computer is quite
a few steps away from the original code running on. High-level source code consists of easy-to –
read structures which are then translated into a low-level language which can only be perceived
and executed by a specific CPU.
● A low-level language is a programming language that deals with elements and limitations of a
computer’s hardware. It either has an insignificant level of abstraction when referring to a machine
or no level of abstraction at all, and it operates to manage the operational meaning of a machine.

II. Procedural Programming.
1. What is Procedural Programming.
● Procedural Programming may be the first programming paradigm that a new developer will learn.
Fundamentally, the procedural code is the one that directly instructs a device on how to finish a
task in logical steps. This paradigm uses a linear top-down approach and treats data and procedures
as two different entities. Based on the concept of a procedure call, Procedural Programming
divides the program into procedures, which are also known as routines or functions, simply
containing a series of steps to be carried out.
Simply put, Procedural Programming involves writing down a list of instructions to tell the
computer what it should do step-by-step to finish the task at hand.
2. Definition.

● Procedural programming is a programming paradigm using a linear approach or a top-down one.
To perform computations it relies on procedures or subroutines.
● Procedural programming is also known as imperative programming.
3. Functions.


Procedural programming is intuitive in the sense that the way you would expect a program to
work is very similar to that. If you want to do something to a computer, you should give step-by –
step instructions on how to do it. Moreover, most of the languages used to program early on are all
procedural. FORTRAN, COBOL, and C, which have been around since the 1960s and 70s, are
examples of procedural languages.
● It is also uses a list of instructions to tell the computer what to do step by step.

10 | P a g e


4. Key Features of Procedural Programming.
● 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 pre-defined
function is ‘charAt()’, which searches for a character position in 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’.

11 | P a g e


● Modularity: Is when two dissimilar systems have two different tasks at hand but are first grouped
to complete a larger task. Each group of systems would then have completed their own tasks one
after the other until all the tasks are complete.

On top of that, it is also the process of subdividing a computer program into separate subprograms.
• Programming paradigms: Is an approach to solving the problem using any programming
12 | P a g e


language or we may also conclude that it is a method of solving the problem using the tools
and techniques that are accessible to us in a certain way.

Imperative programming describes problem solving as a sequence of steps — do this first, then do
that, then do the next thing, and so on. The machine goes through each line of code, executes it and
continues to the next stage.
5. Code examples.
● Loop in program c:

output:

13 | P a g e



● Global Variable:

output:

● Parameter Passing:

output:

14 | P a g e


6. Comparing with Object Oriented Programming(OOP).
● POP is procedural programming while OOP is object oriented programming.
● The main focus of POP is on how the system does the task, it follows the flow chart to complete
the task. The main focus of OOP is data security because only objects of a class are allowed to
access properties or functions of a class.
● Functions are small units of large programs or a subroutine that executes to complete the main
task. In contrast, class properties and OOP functions are divided among.
● In POP , there is no specific access mode to access properties or functions in the program. In
contrast, in OOP there are three access modes, “public”, “private”, “protected” which are used as
an access method to access properties or functions.
● POP does not support the concept of Overloading/polymorphism . In contrast, OOP supports
Overloading/Polymorphism , that is, using the same function name to perform different functions.
We can Overload functions, constructors and operators in OOP.
● There is no concept of inheritance in POP whereas, OOP supports inheritance allowing to use
other class property and function by inheriting it.
● POP is less secure than OOP because in OOP the access specifier limits access to properties or
functions which increases security.
● In POP if some data is shared among all functions in the program, it is declared system-wide
outside of all functions. While in OOP , the data-member of the class can be accessed through the

member-functions of the class.
● There is no concept of virtual classes in POP while in OOP virtual functions support
polymorphism.
7. Problem statement.

a. Business Problem:


Scenario:
A math teacher wants to manage grades of a class. He asks you to help him to write a small
application to do that. He needs to enter student IDs, student’s grades and store these
information into 2 separate arrays (integer array for IDs and float array for grades). Then he
needs to print all student IDs together with their grades. Finally, he needs to know which
student has highest grade and lowest grade. Your program should be menu based with the

15 | P a g e


options above. When an option is done, the program should go back to the main menu so he
can choose another option. There should be an option to quit program.



Let's analyze the situation:
+Create a list Of students.
+Create a list Of student’s ID.
+Create a list of student's grades.
+Create a function that show all students info.
+Create a function that show student with the highest grade and lowest grade.
+Create a menu so that teacher can choose option.


b. Discuss:
● Today's programming languages are evolving swiftly and forcefully in the growth of science at the
end of the twentieth century and the beginning of the twenty-first century, taking an important
position in the disciplines of science and technology. Management is one of the domains where
computerization is being used extensively in our country. Management programming languages
have aided managers in conducting their work in a scientific manner. The use of information
technology in student administration is critical.
● As a result, programmers frequently write student management software in the C programming
language. We need to undertake a variety of duties and tasks in order to implement the student
management program. As a result, an object-oriented programming program can assist in the
design of this program. Functions and tasks can be readily implemented using functions (or
custom). Furthermore, the functional abstraction (or specialization) of procedural programming
makes it simple for programmers to create programs and simple for users to utilize.
● The usage of loops will assist users in rapidly and effectively locating student scores or searching
for personal information about students.
Example:

Output:

16 | P a g e


● Users can list the information of the students with the highest or lowest scores by using if else
statements. Years ago, we had to search each page of the paper for student results; now, just type
the student's name to see the results, and this will save a lot of time.
Example:

Output:


17 | P a g e


C-TASK 2
I. Identify the Variables in the program.
1. Variables and Declare the Variable.
a. Variables:
● A variable in simple terms is a storage place that has some memory allocated to it. Basically, a
variable is used to store some form of data. Different types of variables require different amounts
of memory, different type of memory locations, and some specific set of operations that can be
applied to them.
b.Variable Declaration:
● A typical variable declaration is of the form:



A variable name can consist of alphabets (both upper and lower case), numbers, and the
underscore ‘_’ character. However, the name must not start with a number.

Output:

18 | P a g e


2. Conclude.
● Depending on the circumstances, we can declare as many variables and we can assign values to
them as we like, because this is convenient for us in saving time.

It is obvious that in this case I declare two type of data, integer and float. According with that I
also declare 6 variable and that is : a,b,c,x,y,g . The special things here that I declare and assign x,y

with 4,10 at the same time.
I stored variables a,b,x, and y with date type as integer stored c with the character, and stored grade
with a float data type.

19 | P a g e


● In my project , I use variables the following:
Variable’s
name

Data type

1

data[80]

struct

-I declare “data" array to enter input data
-I use struct type because it can declare many variables inside.

2

n

int

-I declare “n” variable to enter students.
-I use int for this variable as total students is integer.


3

choice

int

-I declare “choice” variable because “choice” will need to be used
many times in different functions (with the aim of built option.)
-I use int for this variable because option need be
an integer. It cannot be an odd number.

4

id

int

-I declare “id” variable to search ID
-I used int for this variable because id need bean integer.

5

i

int

-I declare “i” variable because “i” will need to be used many times in
different functions (with the purpose is to loop)
-I use int for this variable because index need be

an integer.

6

name[40]

char

-I declare “name" array to enter student's name
-I use char because name is type characters

7

username[50]

char

-I declare “username" array to login program
-I use char because username is type characters

8

password[50]

char

-I declare “password" array to login program
-I use char because password is type characters

9


grade

float

-I declare “grade variable
-floats can help me enter student mark

10 max

float

-I declare “max” in local variable because it will need to be used in
one functions(find_max_min)
-When I use float I can print out the maximum mark with real number.

11 min

float

-I declare “min” in local variable because it will need to be used in
one functions(find_max_min)
-When I use float I can print out the minimum
mark with real number.

20 | P a g e

Explanation



II. Identify and Describe Selection Structure.
1. What is the Selection.
● Selection is often referred to as judgment. It is one of the three basic computer programming logic
assemblies. The other two logic assemblies are loop and chain.
● In the assembly of a selection, a question is asked, and based on the answer the program takes one
of two paths of action, after which the program moves on to the next event.
2. Function.
● A function is a block of code that performs a specific task.
Suppose, you need to create a program to create a circle and color it.
And the following are the selection constructs available in C:
- “ if ” statement
- “switch” statement
- Conditional / Ternary operator statement

3. “if...else” statement.
● The if statement may have an optional else block. The syntax of the if..else statement is:

In this image we can see the statement(s) in “if” is true and statement(s) in “else” is false.

21 | P a g e


Example code:

Output:

4. “if...else” ladder
● The if...else statement executes two different codes depending upon whether the test expression is
true or false. Sometimes, a choice has to be made from more than 2 possibilities.
● The syntax of if...else if...else:


22 | P a g e


● Each condition is evaluated in order and if any condition is true the corresponding statement is
executed and the remainder of the chain is skipped.

Example code:

23 | P a g e


Output:

5. Switch case statement.
● Instead of writing many if..else statements, you can use the switch statement.
The switch statement selects one of many code blocks to be executed:

● This is how it works:
The switch expression is evaluated once.
The value of the expression is compared with the values of each case.
If there is a match, the associated block of code is executed.
The break statement breaks out of the switch block and stops the execution.
24 | P a g e


The default statement is optional, and specifies some code to run if there is no
case match.

Example code:


25 | P a g e


Tài liệu bạn tìm kiếm đã sẵn sàng tải về

Tải bản đầy đủ ngay
×