Tải bản đầy đủ (.doc) (29 trang)

Assignment 1 PRO102 Greenwich

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.1 MB, 29 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

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



P2

P3

M1

M2

D1






Summative Feedback:

Resubmission Feedback:

2.1

Grade:
Lecturer Signature:

Assessor Signature:

Date:



ASSIGNMENT 1
Analysis and design a solution for
procedural programming problem

1


Contents
1. Introduction to programming language and procedural programming. ....................... 3
1.1. Programming language. ...............................................................................................

3

1.2. Procedural programming. .............................................................................................

3

1.3. Problem statement. .......................................................................................................

6

1.3.1. Problem and solution. ............................................................................................

6

1.3.2. Apply procedural programming for this problem. ..............................................

7

2. Analysis..................................................................................................................................


8

2.1.Data types and data structure. ....................................................................................

8

2.2.Conditional sentences. .................................................................................................

9

2.3. Loop. ..............................................................................................................................

10

2.4. Switch-Case .................................................................................................................

12

3. Design ..................................................................................................................................

13

3.1. Use-case .......................................................................................................................

13

3.2. WBS...............................................................................................................................

14


3.3. Flowcharts. ...................................................................................................................

15

3.4. Better solution. ................................................................................................................

24

4. Evaluation. ..............................................................................................................................

24

4.1. About my solution. ..........................................................................................................

24

4.2. Evaluate how procedural programming is applied to your problem. ......................

25

5. Conclusion. .............................................................................................................................

26

Reference list ..............................................................................................................................

26

2



1.

Introduction to programming language and procedural
programming.
1.1. Programming language.
Programming language is a type of language that is standardized
according to a system and has its own rules. It’s used to describe the
workings of machines, machines and humans can understand.

Currently we have a lot of programming language such as Java, C++,
JavaScript, but Python is a widely used langue, it can replace Java in the
future (Kumar and Dahiya, 2017).

1.2. Procedural programming.
Procedural programming is a programming paradigm, first appeared in
1957-1964, it works based on procedure which is a series of
computational steps to be performed, any procedure can be included
during program execution.
It has few key features:


Programming libraries: It’s a collection in which there are processes,
values and pre-existing code, we and the program can use it.

3


For example: <math.h> has calculation functions, <string.h> contains text

corrections. We also use many other things.



Local variable : Declared and used in the code that contains it in the
main body of the program.

For example:
int i, float a, double b,…
There are very common
and come in many forms.



Global variable: Declared outside a block(main) and can be used
throughout the program. It only ends when the program ends.

We can use variable
“all” anywhere, it’s
declared outside main.

4




Parameter: It is a type of variable passed to a function with a unique
value and a specified data type.

Parameter


For example: We pass the score parameter to the variable to calculate or
print out the information. I can also pass parameter in with keyboard input.
int score;
scanf(“%d”,&score);



Modularity: It is an operation where the system is broken down to make it
easier to perform when dealing with large, complex programs.



Procedure: Procedures are one-by-one instructions that are carried out in
programming. They flow from one to the next in a sequential manner, so
after the one above is finished, it will move on to the next unless the one
above tells it not to (Moore, 2014).



Programming paradigms: Procedural programming, object-oriented
programming, and flow programming.



There are many types of code samples: condition (if, if else), loop (for,
do while), data type (int, double, char).
For example:
Problem using comparison:
If (a>b) printf(“True”)

else printf(“false”);
Or import array from keyboard: It help us many difficult problems.
5


We can use many data type for data, int for integer, char for name,
characters, …

1.3. Problem statement.
1.3.1. Problem and solution.
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 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.
Problem: The problem of student information management is a difficult
problem. Manual management method has many disadvantages such as:





Time consuming, complicated.
Information may be wrong and difficult to correct.
If the time is long, the document may be damaged.
Difficult for searching, statistics. calculation.


We need to find a solution to this problem.

6


Solution: I think a student management program is a good choice.
Input information: name, ID, gender, score, …
Output information: Name, ID, age, gender, score of all students,
maximum score, minimum score, average score, result, grade, rank, …
Advantages:




Enter information quickly and accurately.
Information is stored for a long time.
Easy search, calculation, statistics.

1.3.2. Apply procedural programming for this problem.
Procedural programming is a good way to create this program.
To use many functions, I need to declare some necessary libraries such as
<stdio.h>, <conio.h>, <string.h>, <math.h>, … It helps me with calculations,
data entry, …
Next, I will declare a structure to collect all the required input information of a
student, type int, float, char will be used for name, ID, points.
An interface would be necessary for any program but I need to get the
number of students before I get started with the interface, initializing a
variable with printf and scan will do the job.
The while-do loop will be used, further initializing an array with the number of

elements as the number of students. Using multiple printf statement to print a
menu of functions and use switch-case to select them.
The functions will be written below the main part, then they will be declared
before the main section and used in each case to write the corresponding
function.
Import and export functions: using for loop in combination with scanf, printf,
gets statements.
Point functions: Using a for loop to “call” the combined values along with if, ifelse conditionals to compare, swap and printf to print the result.

7


2.

Analysis.
2.1. Data types and data structure.
To get around this, I used the data types:
Type

Data is used

Reason to use

Int

ID, number of students,
age, …

Float


Math, English, prog,
average, … of scores

Char

Name, gender

ID is an integer sequence and it
represents student (for example:
200064), number of students
(number of students to enter)
and age is any integer starting
from 1, age ranges from 1 to
100.
They are student scores, they
are not purely integers but real
numbers, because the input
score is a real number so the
printed score must also be a
real number.
The student's name and gender
are both a string of characters
such as “Tung” or “male”

Table 1: Data types
A specialized format for organizing, processing, retrieving, and storing data is
a data structure (Loshin and Lewis, 2021).
Array: It allows me to store many elements, many types in one variable,
these elements can be reference types.
Reason to use: Because my program has student information (ID, name,

age, ...) and has many students so need array to store them all in order. This
makes it easy to import and export information and use it for calculations.
Before calculating the GPA, I have to use the array to get them calculated. If I
don't use array, each variable will store 1 value, if there are 10 students, I
have to create 50 variables => This is terrible.

8


2.2. Conditional sentences.
It is often used in loop for comparison.
Conditional statements of type If and If else are used in this program.
If is used to compare 2 point values in max and min function. Compare the
max variable with the score, if the condition of the clause is true, the
program will assign max= score, if false then stop. It is an important
algorithm in this function.

If-else is used to print because it has a true and false comparison condition
so the program does not need to use many statements. In result of course
function, it is used to print FAILED or PASSED result. If the average score is
greater than or equal to 5, print PASSED, otherwise, print FAILED. If two If
statements are used, the program performance will decrease.

In addition, the ranking function also needs a conditional clause because it
also needs to apply a comparison algorithm like the function to find max,
min. If used otherwise, the program will be very long and affect
performance.
9



2.3. Loop.
Loop is an important and necessary thing in the program.
Types of loop
For

Do- while

Reason to use
Because it is necessary to interact with the
information of each student one by one, starting
with student number 1, completing the algorithm,
then the next student.
If the wrong number of students is entered, the
program will re-enter it, which helps the user to
redirect to the interface.
Table 2: Types of loop

The for loop structure is mainly used in my program with function like
input and output information.
Enter information: Use a loop to enter student information into the array,
after entering this student, go to the next student.

Show information of students: Use a loop to print out student information
(grades, name, ID, age, gender), printing the student information one by one
in the same order in the array as the input.

10


Compare and swap information in arrays (max, min, rank, …).

Using a loop to get the average score of each student in the array, it will
be compared with the max, min and find the max, min score in the function
to find the maximum and minimum scores.

Calculation function (average). Using a loop to get scores of students (math,
English, prog) to calculate the average score of each student.

For loop is used by me in many functions of the program, its benefits are huge.
I don't think there's anything that can replace it because I use arrays a lot.

11


The do-while loop is used once in the screen to enter the number of
students. When the user enters the number of students less than or equal
to 0, the loop will continue and the user re-enters the number, if it is
correct, it will go to the interface.

2.4. Switch-Case
The switch-case structure is also used in the program interface so that the
user can select functions or exit the program.

12


This structure is used for user to select function, these functions will be
assigned with numbers from 0 to 6. When user selects any function,
system will execute lines of code at case there. For example, if 0 is
selected, it will execute the code in the exit function and exit the program.


3.

Design
3.1. Use-case
I will demonstrate the functions and interactions for the program through a
use-case diagram.

Enter information of
students

Show information

Max, Min, Average of grade

Result of the course
Teacher
Rank of students

Rating

Exit

Student management system
13











Currently, the system is only available to teachers. They can use all the
main functions of the system.
The main functions are:
Enter information of students.
Show information.
Result of the course.
Max, Min, Average of grade.
Rank of students.
Rating.
Exit.

3.2. WBS




WBS is a concept to describe the division of work objects with the aim of
making work content transparent, identifying necessary tasks to achieve
goals. (Cohen, 2018).
I built a WBS for this problem:

WBS of my program
14





My WBS has a few parts:
- Enter information: Enter all the necessary student information such as
ID, name, age, gender, scores. For the functions to work properly, all
information must be entered.
- Show information: Print ID, name, age, gender, scores of students.
- Find min, max, average of scores: It consists of lines of code that
perform the main function of the program:
1. Find the highest and lowest scores -> Print them.
2. Calculate average of students -> Print them.
- Find result, rank, rating: Find and print them.

3.3. Flowcharts.
According to Ned Chapin, a graphical means of recording a sequence
of activities is called a flowchart (Chapin, 2003).
In IT, it is often called to rewrite the sequence and the way the program
works.
I will draw and analyze this program as a flowchart.

Flowchart 1- Program overview
15







Here, the program takes the input value n (number of students).
Next, get the input value o and array a[n] (used to select functions).

Using switch with o, If the value of o is 1,2,3,4,5,6 (True), the program
redirects to the corresponding function, if it receives False, it returns to
the input step o.
If the value of o is 0, program will finish. If o is others value, enter o.

We’ll get to each of the main functions:
Function 1: Enter Information of student.

Flowchart 2- Function 1

16








Start with the value i=0.
Compare iIf True is returned, go to the next step.
Enter information into a[i].
Increase the value of i by 1.
Return to the i
Function 2: Show all information of students.

Flowchart 3- Function 2
17









Start with the value i=0.
Compare iIf True is returned, go to the next step.
Print information of a[i].
Increase the value of i by 1.
Return to the i
Function 3: Max, Min, Average.

Flowchart 4- Function 3-Max

18








Start with i=0 and max=a[i].
Compare i

If ii by 1. If False, increase value i by 1.
Go back step : compare iIf i
Flowchart 5- Function 3 -Min






Start with i=0 and min=a[i].
Compare iIf i<n is True, compare min > a[i]. If True, min= a[i] and increase value i
by 1. If False, increase value i by 1.
Go back step: compare iIf i19


Flowchart 6 -Function 3- Average




Start with i=0, average=0 and sum=0.
Compare i- If True then sum=sum + a[i] and increase value i by 1. Go back step
i

- If False then average = sum/n and print average, program finishes.
20


Function 4: Result of course

Flowchart 7: Function 4








Initialize the value i=0.
Compare iIf True is returned, compare a[i] >=5.
If it returns False, then print FAILED.
If it returns True, then print PASSED.
Increase the value of i by 1.
Return to the i21


Function 5: Rank of students.

Flowchart 8- Function 5




Start with i=0, y=0, sum=0, value array HD.
Compare i- If True, compare y1. If True, compare a[i].average < a[y].average.
1.1.If True, perform HD=a[i], a[i]= a[y], a[y]=HD, increase value y
and i by 1 and go back step i22


1.2.

If False, increase value i and y by 1 and go back step
i2. If i2.1. If True, print rank of student is i+1 and the program
terminates.
2.2. If False, the program terminates.
Function 6: Rating.

Flowchart 9: Function 6
23


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

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