Note: Nếu muốn support C, C#, Networking, Database, project web, 1633, security_zalo 0962.986.805 or fb https://www.facebook.com/profile.php?id=100080073517431. Assignment 1 môn Programing (PROG102) đại học Greenwich 2021. Bài luận đạt điểm chuẩn Merit với trích dẫn học thuật harvard. Dựa vào để hoàn thành điểm M là không khó. Giá tiền phải chăng, dành cho người không có thời gian để làm luận hoặc không có form hướng dẫn. Bạn cũng có thể tìm asm2 của môn này bởi vì mình có đăng trọn bộ. Goodluck
Trang 1ASSIGNMENT 1 FRONT SHEETQualification BTEC Level 5 HND Diploma in Computing
Unit number and title Prog102: Procedural Programming
Re-submission Date Date Received 2nd submission
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
Trang 3ASSIGNMENT 1 Analysis and design a solution for
procedural programming problem
Trang 41 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
Trang 51 Introduction to programming language and procedural
programming.
1.1 Programming language.
Programming language is a type of language that is standardizedaccording to a system and has its own rules It’s used to describe theworkings 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 thefuture (Kumar and Dahiya, 2017)
1.2 Procedural programming.
Procedural programming is a programming paradigm, first appeared in1957-1964, it works based on procedure which is a series ofcomputational steps to be performed, any procedure can be includedduring 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
Trang 6For 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
Trang 7• Parameter: It is a type of variable passed to a function with a unique
value and a specified data type
• 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, soafter the one above is finished, it will move on to the next unless the oneabove 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)
Trang 8We 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 enterstudent IDs, student’s grades and store these information into 2 separatearrays (integer array for IDs and float array for grades) Then he needs toprint all student IDs together with their grades Finally, he needs to knowwhich student has highest grade and lowest grade Your program should
be menu based with the options above When an option is done, theprogram should go back to the main menu so he can choose anotheroption 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
Trang 9Solution: 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 astudent, type int, float, char will be used for name, ID, points
An interface would be necessary for any program but I need to get thenumber of students before I get started with the interface, initializing avariable with printf and scan will do the job
The while-do loop will be used, further initializing an array with the number ofelements as the number of students Using multiple printf statement to print amenu of functions and use switch-case to select them
The functions will be written below the main part, then they will be declaredbefore the main section and used in each case to write the correspondingfunction
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, else conditionals to compare, swap and printf to print the result
Trang 10if-2 Analysis.
2.1 Data types and data structure.
To get around this, I used the data types:
Int ID, number of students, ID is an integer sequence and it
200064), number of students(number of students to enter)and age is any integer startingfrom 1, age ranges from 1 to
100
Float Math, English, prog, They are student scores, they
average, … of scores are not purely integers but real
numbers, because the inputscore is a real number so theprinted score must also be a
real number
are both a string of characterssuch 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 Thismakes 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 Idon't use array, each variable will store 1 value, if there are 10 students, Ihave to create 50 variables => This is terrible
Trang 112.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 themax variable with the score, if the condition of the clause is true, theprogram will assign max= score, if false then stop It is an importantalgorithm 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 coursefunction, it is used to print FAILED or PASSED result If the average score isgreater than or equal to 5, print PASSED, otherwise, print FAILED If two Ifstatements are used, the program performance will decrease
In addition, the ranking function also needs a conditional clause because italso needs to apply a comparison algorithm like the function to find max,min If used otherwise, the program will be very long and affectperformance
Trang 122.3 Loop.
Loop is an important and necessary thing in the program
information of each student one by one, startingwith student number 1, completing the algorithm,then the next student
Do- while If the wrong number of students is entered, the
program will re-enter it, which helps the user toredirect 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
after entering this student, go to the next student
(grades, name, ID, age, gender), printing the student information one by one
in the same order in the array as the input
Trang 13Compare 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
Trang 14The do-while loop is used once in the screen to enter the number ofstudents 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 iscorrect, it will go to the interface
2.4 Switch-Case
The switch-case structure is also used in the program interface so that theuser can select functions or exit the program
Trang 15This structure is used for user to select function, these functions will beassigned with numbers from 0 to 6 When user selects any function,system will execute lines of code at case there For example, if 0 isselected, it will execute the code in the exit function and exit the program.
Show information
Max, Min, Average of grade
Result of the course
Trang 16Currently, 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
• I built a WBS for this problem:
Trang 17• 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, allinformation 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
Trang 18• 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 programredirects to the corresponding function, if it receives False, it returns tothe 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
Trang 19• Start with the value i=0.
• Compare i<n If False is returned, the program terminates
If True is returned, go to the next step
• Enter information into a[i]
• Increase the value of i by 1
• Return to the i<n comparison step
Function 2: Show all information of students.
Flowchart 3- Function 2
Trang 20• Start with the value i=0.
• Compare i<n If False is returned, the program terminates
If True is returned, go to the next step
• Print information of a[i]
• Increase the value of i by 1
• Return to the i<n comparison step
Function 3: Max, Min, Average.
Flowchart 4- Function 3-Max
Trang 21• Start with i=0 and max=a[i].
• Compare i<n
i by 1 If False, increase value i by 1
• Go back step : compare i<n
Flowchart 5- Function 3 -Min
• Start with i=0 and min=a[i]
• Compare i<n
by 1 If False, increase value i by 1
• Go back step: compare i<n
Trang 22Flowchart 6 -Function 3- Average
• Start with i=0, average=0 and sum=0
• Compare i<n:
Trang 23Function 4: Result of course
Flowchart 7: Function 4
• Initialize the value i=0
• Compare i<n If False is returned, the program terminates
If 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 i<n comparison step
Trang 24Function 5: Rank of students.
Flowchart 8- Function 5
• Start with i=0, y=0, sum=0, value array HD
• Compare i<n-1:
- If True, compare y<n:
1 If True, compare a[i].average < a[y].average
Trang 251.2 If False, increase value i and y by 1 and go back step
i<n-1
2 If i<n-1 or y<n False, compare i<n:
2.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
Trang 26• Start with i=0, compare i<n:
- If True, compare average >=8:
1.1 If True, print “Good student”
1.2 If False, If average >=5, print “Normal student”, If False print
Increase value i by 1 and go back step i<n
If False, the program terminates
3.4 Better solution.
• Problem: About average scores.
The functions max, min, rank, rating, result all need an averagescore to run the function, but the average score function only runs
in the max min function, so if you haven’t used this function, youcan’t use that functions
• Solution: I have thought of 2 ways to solve it:
- Method 1: Take the average function out of min max, when you
need to run the function that needs the average score, call theaveraging function first
But it causes the average score to print out over and over again
- Method 2: Put the average function into the information input
function, when the input information is complete, the averagefunction will immediately run
Disadvantages: All its benefits have not been thoroughly analyzed
• About WBS:
Trang 27Disadvantages: 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 specificfunctions 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 likename, grades, … Gather all the necessary information in one placeusing a struct Loops, switch-case and conditional statement aresuitable for calculating, comparing and retrieving information inarrays Functions are in separate places but can come together toform 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 muchdifferent but have to reprogram a lot of commands => can’s inheritcommand line The entered parameter data is not cleared causingthe screen to fill up It takes many steps to implement a simplealgorithm like swapping positions
• Difficulties:
If there is more input, more variables and more complex algorithmsare needed If you want to optimize the algorithm, you have torevise the whole program because the functions have someassociation with each other => optimization is difficult