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

ASM 1 C# programming 1619 FPT Greenwich (Distinction Super Sale)

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, 22 trang )

ASSIGNMENT 1 FRONT SHEET
Qualification

BTEC Level 5 HND Diploma in Computing

Unit number and title

Unit 1: Programming

Submission date

Date Received 1st submission

Re-submission Date

Date Received 2nd submission

Student Name

Nguyen Huy Hoang

Student ID

GCH200739

Class

GCH0908

Assessor name


Lai Manh Dung

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

M1

D1

Hoang`


 Summative Feedback:

Grade:
Lecturer Signature:

 Resubmission Feedback:

Assessor Signature:

Date:


Table of Contents
Table of Contents .....................................................................................................................................................................................................................................2

STATE THE PROBLEM AND ALGORITHM OVERVIEW ..........................................................................................................................................................3

I.

STATE THE PROBLEM ......................................................................................................................................................................................................3

¥
Ԓ

Problem: .................................................................................................................................................................................................................................3
ALGORITHM OVERVIEW ..................................................................................................................................................................................................3

¥
Ԓ

Definition of Algorithm: .................................................................................................................................................................................................4

Ԓ

Charateristics of an Algorithm: ..................................................................................................................................................................................4

Ԓ

The vital roles of algorithm: ..............................................................................................................................................................................................4

II.

Analysis and design a solution for this problem .............................................................................................................................................................5

III.


DEMONSTRATION THE COMPILATION(HOW SOURCE CODE IS COMPLIED) AND EVALUATION THIS SOLUTION ...................................7

¥

Variables and data types: ......................................................................................................................................................................................................7

¥

Input the total number of members: ................................................................................................................................................................................8

¥

Menu based program: ............................................................................................................................................................................................................8
Ԓ

Menu: ..................................................................................................................................................................................................................................... 10

Ԓ

EXTRA EXPLANATION ABOUT MENU BUILDING(REASON WHY “SWITCH_CASE” BE USED INSTEAD OF “IF-ELSE”) 12
FUNCTIONS AND SELECTIONS IN THIS PROGRAM: ................................................................................................................................ 13

¥
1.

ENTER ALL INFORMATION: ....................................................................................................................................................................................... 13

2.


PRINTING ALL INFORMATION ................................................................................................................................................................................. 15

3.

FINDING THE HIGHEST TRAINING ACHIEVEMENT(Apply Comparing Algorithm) .................................................................... 16

4.

CALCULATE THE CALORIES CONSUMED ............................................................................................................................................................ 18

¥

Explanation How Source Code is complied: .............................................................................................................................................................. 19

¥

Software Development Life Cycle................................................................................................................................................................................... 20
Ԓ

Definition of Software Development Life Cycle: ................................................................................................................................................. 20

References ............................................................................................................................................................................................................................................... 21


I. STATE THE PROBLEM AND ALGORITHM OVERVIEW
¥ STATE THE PROBLEM
Ԓ Problem:
A boy who loves cycling need to store and manage the personal information and daily training stat of the
members in his cycling club. He told me to help him make an small app that can regulate information includes:
name, age, email, phone number, training parameter through the training process of each member in the club

and print out on screen contemporarily, from which to find out who has the highest practical achievement to
award weekly as well as calculate the calories consumed of each one.
 After considering and overviewing this problem, this one be found as a problem not too complicated to
solve.
 These requirements and ways to operate of the app that the boy gives can be solved through Searching
algorithm and Comparing algorithm. Programs and algorithms of this problem could also can be built
via C# language.
 For a deeper understanding, the next section will be an overview of the algorithm.

¥ ALGORITHM OVERVIEW

1: ALgorithm image illustration


Ԓ Definition of Algorithm:




Informally, algorithm is any well defined computational procedure that gets some value, or set of datas, as
input and fabricates some value, or set of datas, as output. Consequently, each algorithm is a sequence of
computational steps that alter and adjust the input into the output properly and appropriately.
An algorithm also may be defined as a tool for solving a well-determined computational problem. The
statement of the problem specifies in general allocations the desired input/output relationship. The
algorithm describes a specific computational procedure for achieving that input/output relation ship.
(Warner Ave, 25 Nov, 2020.)

Ԓ Charateristics of an Algorithm:










Well-Defined Inputs: Each algorithm all needs input values from a specified set.
Well-Defined Outputs: From any set of input values an algorithm makes up output values from a specific
set. The output values also are the solution to the problem.
Definiteness: The steps of each algorithm have to be described precisely and appropriately.
Correctness: Producing the accurate output values for each set of input values by each algorithm is
necessary.
Finiteness: Algorithm ought to make up the desired output after a finite (but maybe big) number of steps
for every inputs in the set. It ought to not finish in an infinite loops or the same.
Effectiveness: This has to be feasible to operate each step of an algorithm accurately and in a finite
amount of time. The algorithm also should be simple, generic and actual, such that it could be executed on
will the available methods. It must not contain few high-tech technologies, or anything.
Generality: The procedure need to be applicable of the desired form, not just for a particular set of input
values. It's also important to be clear and unambiguous. (Thomas H. Cormen, 2015)

Ԓ The vital roles of algorithm:




It is quite difficult to imagine when using internet or computer without intelligent and effective algorithms.
With the support of these algorithms, various sites on the Internet and computer are able to adjust and
manipulate a tons of data.
An algorithm also help people to manipulate data in diverse ways, such as sorting, inserting data, searching

particular data processing, calculating and other relative computer and mathematical operations.


Ԓ Example of algorithm: Sorting a sequence of numbers input by Sorting algorithm
 To sort a sequence of numbers into increasing order. This problem aries frequently in practice and provides
fertile ground for introducing many standard design techniques and analysis tools. Here is how it define the
sorting problem. Given the input sequence(51, 4, 5, 31, 9), a sorting algorithm returns as ouput the
sequence (4, 5, 9, 31, 51). Such an input sequence is called an illustration of the sorting algorithm.

2: Example to illustrate the Sorting algorithm

II.

Analysis and design a solution for this problem
¥ Analyze the problem.
Ԓ To solve this proplem, I need to review and consider its requirements and data input and output. The above
problem mainly revolves around managing stats of boys his cycling club. The inputs inculde:
Information(Name, Age, Mobile, Email) and specific training data(Distance: Km) of each member has cycled
during a week. The output must consist printing out these input informations to the screen to observing
training process and assessing, finding out the member who achive the highest parameter(the longest distance)
and calculate the calories consumed(specifically 1km/70calories).
Summarize:
 Input: Information(Name, Age, Mobile, Email) and specific training data(Distance: Km).
 Output: Printing these input informations, finding the highest achievement, the calories consumed.


Ԓ Solving this problem will be operated by building an app based on C# Language and the app will be complied
by VISUAL STUDIO IDE and to help understand how this app executing, these is the use-case which describe
it.


3: Use-case the app interact to user.

Ԓ Two significant algorithms which are the most suitable for solving this problem are Searching algorithm and
Comparing algorithm, especially Comparing algorithm play a huge role in that. Particularly, in the main
function of this problem which is finding out the highest parameter, Comparing algorithm will be utilizied
through structures of C# language implicitly carry out the program to compare each data input (distance


cycling) of each member and find the highest result. And then, the only thing searching a need to do is search
this result to print if the boy select its choice.
Ԓ To make an app for this problem, building and compliating it in VISUAL STUDIO 2019 IDE is considered as a
good high-tech IDE to build and apply the high-level language C# to make solution for this problem.

III.

DEMONSTRATION THE COMPILATION(HOW SOURCE CODE IS COMPLIED) AND
EVALUATION THIS SOLUTION
It comes to the central main task of this problem and it is the compilation and running of this program which has been
built as an app to solve this problem. All paths of the app also have been build and complie in VISUAL STUDIO 2019 IDE
with high-level language C#.

¥ Variables and data types:

4: Variables and data types in this program.

Ԓ Before it comes to the explanation of how the program be complied and run in this app, these variables and
datatypes include Integer total(represent for the total number of members) and choice(represent for the
number of selection), Boolean isTotal(this type to make the condition to be sure that the input of total always
is integer), array type string name(to be used for storing name of members), array type integer age(declare to



be used for storing age of members), array type string email(for storing email of members), array type long
mobile(to be used for store phone number of members) and the last one is array integer type distance(to be
used for store training achievement of members)

¥ Input the total number of members:

5:Input total number of member screenshot

Ԓ First of all, the program should receive the total of member number in his club. 2 variables have been declared
to get the total. They are integer and boolean datatypes, Int total is Where total Number of Students is Located
and Bool isTotal to make an condition that if total is beyond bound, user must enter again with valid input.‘dowhile’ loop is used to make sure that the value input of the boy is valid. If input is wrong, the program will
display “Invalid Input!!!” with the red color. The ‘do-while’ loop will rerun constantly until the boy enter the
appropriate valid, the ‘do-while’ will end to continue other tasks.

¥ Menu based program:


Ԓ Firstly, there is the list of selection in app’s menu:

6: List menu

This list has all selections which also meet the boy need. It simply has been built with Console.WriteLine.

Ԓ Before it comes to the menu based program, there is the Input choice program.

7: Input choice

It has been built as same as the input total program, declare boolean
isChoice to make an condition that if choice is beyond bound, user

must enter again with valid input.‘do-while’ loop is used to make sure
that the value choice of the boy is valid. If choice is wrong, the program
will display “Invalid Input!!!” with the red color. The ‘do-while’ loop

ScreenShot


will rerun constantly until the boy enter the appropriate valid, the ‘do-while’ will end to continue other
tasks.
Ԓ Menu:
Based on these above analysis of this problem, creating a menu based program is necessary. It not only help
this app have multi choices, but it also make the program more flexible. The boy can select the option that he
wantand skip options he don’t use yet. When an option is done, the program could go back to the main menu
so he can choose another option. There also be an option to quit program.

8: Menu


This program is built based on “Switch-case” statement and “for” loop. To explain it clearly and concisely, there
is the flow-chart below which will present all mechanism.

Flow-chart of how switch-case executing


Ԓ EXTRA EXPLANATION ABOUT MENU BUILDING(REASON WHY “SWITCH_CASE” BE USED
INSTEAD OF “IF-ELSE”)


Based on the knowledge I have learned plus references from different sources, I would like to present my
personal view and reasons for using “switch-case” statment instead of using "if-else" statment to build main

menu for the program:
o Firstly, I think creating menu by "switch-case" statement is more dynamic and efficient than by "if-else".
Instead of having to type the condition over and over again to gain access to the program, "switch-case" simply
enters the case and the case label, it also help program look much clearly.
o According to some theory I have consulted from different sources about C# language, when compiler of this
app's program gets start compiling a "switch-case" statement, it will inspect each of the case constants and
create a “jump table” that it will use for selecting the path of execution depending on the value of "choice"
variable(especially 1-5) in menu. Therefore, if the boy(user) need to select among a large group of values, a
switch statement will run much faster than the equivalent coded using a sequence of “if-else”. The program
could operate this because it knows that the case constants are all the same type and simply have to be
compared for equality with the "switch-case" expression, while in case of “if-else” expressions, the compiler
of this program may not be able to perform.
o Not only that, I saw "switch-case" are better for fixed data conditions such as 1 -> 5(selections in menu). A
"switch-case" statement may be able to prove to be faster than "if-else" statement provided number of cases
are good. To solve this problem of the boy, i has made the program app with 5 selection. Therefore, I prefer
using "switch-case" because the number of cases are quite much. "if-else" also takes more times to get into
the condition. Adding and removing labels in this app is also easier with a "switch-case".
o From these reason, I find “switch-case” statement more suitable to build menu than “If-else” in C# language.


¥ FUNCTIONS AND SELECTIONS IN THIS PROGRAM:
1. ENTER ALL INFORMATION:
Ԓ First selection in the program is the getting information, which has a role that accept, check the infor of each

member and store these information into storage of program.

9: ENTER INFORMATION

Ԓ “for” loop is utilized and located to cover almost all algorithms and other structures inside. It plays a role as a
the machine that makes the statements run from the initial value to the limit value, incrementing and repeating

the whole function. The terminatin condition of ‘for’ loop is set that the index must be less than ‘total’variables
and loop increment to get enough infor. Distance input has been located in “do-while” and “if” statement to
make the complitaing program checks and makes sure that the input in the range(0-500km).


Ԓ To explain it clearly and concise, I have drawn a simple flow-chart to describe it, and it’s below:

10: FLOW_CHART DESCRIBES ENTERING ALL INFORMATION

After explaining this selection, there is the screen shot when the program running:

ScreenShot


2. PRINTING ALL INFORMATION
Ԓ To be easier when using and calling this function, I have built the printing all information as a method.

11: PRINTING METHOD

Ԓ This method has been built quite simple, it just have “for” loop to operate and perform priting all information
which be entered in the first selection.
Ԓ There is the screen shot when program running:

SCREENSHOT


3. FINDING THE HIGHEST TRAINING ACHIEVEMENT(Apply Comparing Algorithm)
Ԓ This is one of main selections in menu that meets requirements of the boy in problem. As well as the printing
information, this one also has been built as a method. finding highest distance training parameter has been
designed as a program base on comparing algorithm that compares each parameter with a virtual variable

assigned to 0.

12: FINDING THE HIGHEST TRAINING

Ԓ To explain how Comparing Algorithm is applied and the fuction executing more clear, there are the list of
structures, functions,..:
 “for” loop is used in this function. It is utilized and located to cover ‘if-else’ structure. It plays a role as a the
machine that makes the statements “if-else” run from the initial value to the limit value, incrementing and
repeating the whole function. Particularly, It be initialized counter with index “i” variable that be set up be equal
to 0 and it just be executed once at the beginning. The terminal condition of ‘for’ loop is set less than or equal to
‘total’variables( the variables that be entered in first function) If the condition be met, statements inside the loop
is executed. If not, the program will exit the loop. Last but not least there is the loop variant. It is the increment
value: i++. It also is evaluated at the end of every iteration for assure that the loop will be run incrementally
according to the value of the 'total' variable.


2 variables have been declared what are integer Sbd(which represent for the index of member who has the
highest training stat) and Max(which assign to distance[0] used to make an agurment to compare by if and
operator “<” ). They will automatically compare follow the theory which based on Comparing algorithm.


Ԓ When declaring is done, Comparing Algorithm has been applied in “if”statement.‘if’ structure now is used
with “(max < distance[i]…distance[i] == max)”condition located inside the condition of ‘if’ is used together to
set the condition that check the whether any value can greater than ‘max’ and based on that, the max variable
will assign to equal to them.
Ԓ To clarify it more clearly and easier to understand, I have drawn a flow-chart describe how it’s complied and
how the comparing algorithm applied in this.

SCREEN SHOT


13:Flow-chart to describe Finding the highest


4. CALCULATE THE CALORIES CONSUMED
Ԓ The last function as well as the last selection in menu is calculate the calories consumed, It also has been built
as a method.

14: CALCULATE THE CALORIES CONSUMED

The way it complie is quite simple. It just simply is declare a array “calo” with integer datatype. Then using
“for” loop to help this program can automatically assign all array “calo” to multiplicate between each parameter
input in array” distance” with 70(it’s based on Calorie Calculation Formula) and save the results into storage
of program and print it out.
“For” loop has been used one more time to fill the name[i] of member in the result to make it particular for the
boy can easy take a look at list of calories consumed on screen.

SCREENSHOT


¥ Explanation How Source Code is complied:
 In this part after designing all source code in VISUAL STUDIO IDE, doing complie is the job of complier in C#
and there is the process its complied:
 In C#, programs which i have designed before are not compiled into executation; they are just compiled
into Intermediate Language (IL), which the CLR then executes. The IL files which are produced by C#
language are similar to the other IL files. The platform is language-agnostic.
 When my source code is compiled into IL, the IL is saved in a file on disk. When i try running my program,
the IL is compiled again by C# complier, using the Just In Time (JIT/CLR) compiler. As a conclusion is
machine(native) code, executed by the machine’s processor.
 The CLR compiler carrys out on requisition of my program. When a method is called in main function, the
CLR compiler does analyze the IL and create effective native code, which runs pretty rapid. CLR compiler

is intelligent enough to realize what code has already been compiled by C# complier. So whenever the
source code executes, compilation happens only as required. As Source code runs again and again, it tend
to become faster than before because the already compiled code is reused.

15: Image illustraion the complete C# compilation process


¥ Software Development Life Cycle

IMAGE ILLUSTRAION

Ԓ Definition of Software Development Life Cycle:
Software Development Life Cycle (SDLC) can be understood as a making process aims to create a high-quality
system that meets or exceeds user expectations, operates much effectively and efficiently in the topical and
planned IT infrastructure, and is more economical to maintain and cost-effective to improve. Software
Development Life Cycle’s commonly divided into six to eight steps: Planning, Requirements, Design, Build,
Document, Test, Deploy, Maintain.
(Anon., n.d.)


References
Anon., n.d. SDLC INTRODUCE. [Online]
Available at: />[Accessed 8 2021].
Thomas H. Cormen, C. E. L. R. L. R. C. S., 2015. ntroduction to Algorithms. 3nd ed. s.l.:THE MIT PRESS.
Warner Ave, n. S., 25 Nov, 2020.. GeeksForGeeks.. [Online]
Available at: />[Accessed 8 2021].

Ghj

asdasda sd




×