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

Assignment 1 Programming (1618 Distinction)

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 (3.84 MB, 36 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

Bui Quang Minh

Student ID

GCD210325

Class

GCD1104

Assessor name


Ly Quynh Tran

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


 Summative Feedback:

Grade:
Lecturer Signature:

Assessor Signature:

 Resubmission Feedback:

Date:


Table of Contents
CHAPTER 1: STATE SIMPLE BUSINESS PROBLEMS ..................................................................................... 7
I. INTRODUCTION ....................................................................................................................................... 7
II. ALGORITHM ............................................................................................................................................ 7

1. Definition ............................................................................................................................................ 7
2. Explaination ........................................................................................................................................ 8
2.1 Characteristics of an algorithm ...................................................................................................... 8
2.2 Properties of algorithm .................................................................................................................. 9
2.3 Types of an algorithm ..................................................................................................................... 9
3. Examples of algorithms ...................................................................................................................... 10
III. REPRESENT PROBLEM .......................................................................................................................... 12
1. Sorting algorithm ............................................................................................................................... 12
2. Searching algorithm ........................................................................................................................... 13
CHAPTER 2: ANALYSE PROBLEM AND DESIGN SOLUTIONS ...................................................................... 14
I. ANALYSE BUSINESS PROBLEM ............................................................................................................... 14
1. Analysing ............................................................................................................................................ 14
2. Library ................................................................................................................................................ 14
3. Data types and properties ................................................................................................................. 14
II. USE-CASE DIAGRAM............................................................................................................................... 15
III. FLOWCHART ......................................................................................................................................... 16
1. Function of selecting menu function ................................................................................................. 16
2. Function of showing all books............................................................................................................ 17
3. Function of importing a new book .................................................................................................... 18
4. Function of searching books .............................................................................................................. 19
5. Function of borrowing a book ........................................................................................................... 21


6. Function of showing all clients .......................................................................................................... 22
CHAPTER 3: DEMONSTRATE AND RUNNING A PROGRAM ...................................................................... 23
I. CODING STANDARD ............................................................................................................................. 23
1. Show all books ................................................................................................................................. 23
2. Import a new book ............................................................................................................................. 24
3. Search books ...................................................................................................................................... 25
4. Borrow a book ................................................................................................................................... 27

5. Show all clients .................................................................................................................................. 28
6. Close the library ................................................................................................................................. 28
II. RESULTS OF PROGRAM ......................................................................................................................... 29
1. Show all books ................................................................................................................................... 29
2. Import a new book ............................................................................................................................ 29
3. Search books ..................................................................................................................................... 30
4. Borrow a book ................................................................................................................................... 31
5. Show all clients .................................................................................................................................. 31
6. Close the library.................................................................................................................................. 32
III. SOFTWARE DEVELOPMENT LIFE CYCLE (SDLC) .................................................................................... 32
1. Definition............................................................................................................................................ 32
2. The entire SDLC process .................................................................................................................... 32
CHAPTER 4: EVALUATION ......................................................................................................................... 35
I. TEST CASE ............................................................................................................................................... 35
II. EVALUATION ……...............................................………............................................................................. 36
REFERENCE LIST ………………………………………………………………………………………………………………………………….. 37


CHAPTER 1: STATE SIMPLE BUSINESS PROBLEMS (P1)
I. INTRODUCTION
A software development business invited me for an interview after I applied for a position as a trainee
there. I've been asked to display my skills and ability for solving issues and for simple programming.
I must first write a report on employing algorithms to solve problems in order to do this. I must clarify,
with the help of examples, how algorithms are used to resolve straightforward business issues as well as
the procedures that must be followed in order to create software that solves the issue. I should clarify
the idea I have about your software. Input, output, and assignment statements, loops, and conditional
statements are all fundamental procedural programming constructs that will be used to solve the issues.
Utilizing flowcharts and modules, problems should be analyzed, created, and shown.

II. ALGORITHM

1. Definition
The word Algorithm means ”A set of finite rules or instructions to be followed in calculations or
other problem-solving operations ” Or ” A procedure for solving a mathematical problem in a
finite number of steps that frequently involves recursive operations”.
An algorithm is a procedure used for solving a problem or performing a computation. Algorithms
act as an exact list of instructions that conduct specified actions step by step in either hardwareor software-based routines.
Algorithms are widely used throughout all areas of IT. In mathematics and computer science, an
algorithm usually refers to a small procedure that solves a recurrent problem. Algorithms are also
used as specifications for performing data processing and play a major role in automated
systems.

Figure 1. What is algorithm


2. Explaination
2.1 Characteristics of an algorithm

Figure 2. Characteristics of an algorithm
Clear and Unambiguous:
The algorithm should be clear and unambiguous. Each of its steps should be clear in all aspects
and must lead to only one meaning.
Well-Defined Inputs:
If an algorithm says to take inputs, it should be well-defined inputs. It may or may not take input.
Well-Defined Outputs:
The algorithm must clearly define what output will be yielded and it should be well-defined as
well. It should produce at least 1 output.
Finite-ness:
The algorithm must be finite, i.e. it should terminate after a finite time.
Feasible:



The algorithm must be simple, generic, and practical, such that it can be executed with the
available resources. It must not contain some future technology or anything.
Language Independent:
The Algorithm designed must be language-independent, i.e. it must be just plain instructions that
can be implemented in any language, and yet the output will be the same, as expected.
2.2 Properties of algorithm






It should terminate after a finite time.
It should produce at least one output.
It should take zero or more input.
It should be deterministic means giving the same output for the same input case.
Every step in the algorithm must be effective i.e. every step should do some work.

2.3 Types of an algorithm
There are several types of algorithms available. Some important algorithms are:
1. Brute Force Algorithm: It is the simplest approach for a problem. A brute force algorithm
is the first approach that comes to finding when we see a problem.
2. Recursive Algorithm: A recursive algorithm is based on recursion. In this case, a problem is
broken into several sub-parts and called the same function again and again.
3. Backtracking Algorithm: The backtracking algorithm basically builds the solution by
searching among all possible solutions. Using this algorithm, we keep on building the
solution following criteria. Whenever a solution fails we trace back to the failure point and
build on the next solution and continue this process till we find the solution or all possible
solutions are looked after.

4. Searching Algorithm: Searching algorithms are the ones that are used for searching
elements or groups of elements from a particular data structure. They can be of different
types based on their approach or the data structure in which the element should be
found.
5. Sorting Algorithm: Sorting is arranging a group of data in a particular manner according to
the requirement. The algorithms which help in performing this function are called sorting
algorithms. Generally sorting algorithms are used to sort groups of data in an increasing or
decreasing manner.
6. Hashing Algorithm: Hashing algorithms work similarly to the searching algorithm. But they
contain an index with a key ID. In hashing, a key is assigned to specific data.


7. Divide and Conquer Algorithm: This algorithm breaks a problem into sub-problems, solves
a single sub-problem and merges the solutions together to get the final solution. It
consists of the following three steps:
• Divide
• Solve
• Combine
8. Greedy Algorithm: In this type of algorithm the solution is built part by part. The solution
of the next part is built based on the immediate benefit of the next part. The one solution
giving the most benefit will be chosen as the solution for the next part.
9. Dynamic Programming Algorithm: This algorithm uses the concept of using the already
found solution to avoid repetitive calculation of the same part of the problem. It divides
the problem into smaller overlapping subproblems and solves them.
10. Randomized Algorithm: In the randomized algorithm we use a random number so it gives
immediate benefit. The random number helps in deciding the expected outcome.

3. Examples of algorithms
Real-life examples that define the use of algorithms:



Sorting Papers:

A simple task and yet it uses algorithmic thinking. When you are sorting office files or your
personal documents you are implementing an algorithm. In its most basic sense, you are
following a set of tasks to achieve an outcome. The reason why sorting papers is a great example,
is because it shows the variety of tasks and specifications algorithms can use. For instance, you
can sort your files alphabetically, by word count, by date, and countless others. The goal is to
simplify the organizational process by using small tasks.


Traffic Signals:

The programming implemented in traffic signals considers real-time traffic flow and groups
general sets of movements into phases. For instance, traveling through a lane and turning right
would be grouped into one phase.
In order to maintain safety, traffic lights need a smart algorithm that detects the phases and
times the movement correctly. Every time you pull up to a red light, the traffic signal is cycling
through phases. It is using an algorithm to determine the best time for you to continue through
the intersection based on traffic volume.


“Algorithm to print all books in library”
Algorithm solving process:
Step 1: Start
Step 2: Declare new class “Book”
1. String Title
2. String Author
3. String Category
4. String PublicationDate

Step 3: Declare new List
Step 4: Set all books’ information
Step 5: Create first loop to print
1. If true, print info of every
single books
2. if false, end the command
Step 6: Create second loop to print
the book’s status
1. If true, print the person
borrowing book
2. if false, print this book is
available
Figure 3. Flowchart of printing all books in library


III. REPRESENT PROLEM
Today, the data of books and clients are increasing dramatically; therefore, having a library
management application is really necessary. The program requires a main menu based on
requirements such as: Entering the book's information including title, author, category, and
publication date, printing all books or clients, and other excellent functions. this application will
help the librarian increase work efficiency, and reduce time wasted. This session will be
mentioned next in chapter 2.

1. Sorting algorithm
For Example, there are many algorithms for arranging a sequence of random numbers but still
giving the same output.
1. The selection sort algorithm sorts an array by repeatedly finding the minimum element
(considering ascending order) from the unsorted part and putting it at the beginning.

Figure 4. Selection Sort illustration



2. Bubble Sort is the simplest sorting algorithm that works by repeatedly swapping the
adjacent elements if they are in the wrong order. This algorithm is not suitable for large
data sets as its average and worst-case time complexity is quite high.

Figure 4. Bubble Sorting illustration
3. Insertion sort is a simple sorting algorithm that works similar to the way you sort playing
cards in your hands. The array is virtually split into a sorted and an unsorted part. Values
from the unsorted part are picked and placed at the correct position in the sorted part.

Figure 5. Insertion Sorting illustration


2. Searching algorithm
1. Linear Search is defined as a sequential search algorithm that starts at one end and goes
through each element of a list until the desired element is found, otherwise the search
continues till the end of the data set. It is the easiest searching algorithm

Figure 6. Linear Search illustration
2. Binary Search is a searching algorithm used in a sorted array by repeatedly dividing the
search interval in half. The idea of binary search is to use the information that the array
is sorted and reduce the time complexity to O (Log n).

Figure 7. Binaryr Search illustration


CHAPTER 2: ANALYSE PROBLEM AND DESIGN SOLUTIONS (P1)
I. ANALYSE BUSINESS PROBLEM
1. ANALYSING

Continue from previous session as I mentioned in “Represent problem”
To address the problem, I will use the C# programming language to make a program that can meet all
needs of a library manager. In addition, I will apply my experience in "Procedural Programming", and use
libraries, variables, expressions, loop statements, and conditional statements, to solve this problem.
First, we need to define the Input and Output of this algorithm
Input: information of books to enter such as book's title, author, category, and publication date, and the
information's client
Output: Includes information on imported books, information's clients with their books borrowed.

2. LIBRARY
In the above project, it is necessary to use libraries to meet the need to solve the algorithm. That is:
Contains fundamental classes and base classes that define commonly-used
value and reference data types, events and event handlers, interfaces,
attributes, and processing exceptions.
Contains interfaces and classes that
define generic collections, which allow
users to create strongly typed collections that provide better type safety and performance than nongeneric strongly typed collections.

3. DATA TYPES and PROPERTIES
In the project above, I used 3 data types including integer, string, double.
Here are declared data for the properties that I will use in this program to solve the problem

Data types
String

Properties
Title, Author, Category, PublicationDate
NameOfClient
TitleOfBookBorrowed
DueDate


Integer

PhoneNumber


Day, Month, Year

II. USE-CASE DIAGRAM

Figure 8. Use case diagram


III. FLOWCHART
1. Selecting menu function
 Explain:
Step 1: Start
Step 2: Declare variable option
Step 3: Display menu
1. Show all books in library
2. Import a new book
3. Search books
4. Borrow a book
5. Show all clients
6. Close library
Step 4: Input a option
Step 5: Check option is 6 or not.
+ If it is 6, the program will be end
+ if it is not 6, the program goes into the case and then
back to display menu

Step 6: End
Figure 9. Flowchart of the choices


2. Function of showing all books



Explain:

Step 1: Start
Step 2: Declare new class “Book”
1.
2.
3.
4.

String Title
String Author
String Category
String PublicationDate

Step 3: Declare new List
Step 4: Set all books’ information
Step 5: Create first loop to print
1.
If true, print info of every
single books
2.
if false, end the command

Step 6: Create second loop to print
the book’s status
1.
If true, print the person
borrowing book
2.
if false, print this book is
available
Figure 10. Flowchart of choice 1


3. Function of importing a new book
 Explain:
Step 1: Start
Step 2: Enter Title and save it to new
variable title
Step 3: Enter Author and save it to new
variable author
Step 4: Enter Category and save it to new
variable category
Step 5: Enter PublicationDate and save it
to new variable publicationDate
Step 6: Declare a newBook in class Book
Step 7: Assign all new variables to
properties in class Book
Step 8: Add them to a listOfBooks
Step 9: End

Figure 11. Flowchart of choice 2



4. Function of searching book

Figure 12. Flowchart of choice 3

 Explain:
Step 1: Start
Step 2: Enter the choice
 If choice == 5, end the program
 If false, come to the next loop
Step 3: check if choice = 1
 If true, Enter the title you want to search
The title entered will be compared to the title of all books and print if it true


 If false run the next command
Step 3: check if choice = 2
 If true, Enter the author you want to search
The author entered will be compared to the author of all books and print if it true
 If false, run the next command
Step 3: check if choice = 3
 If true, Enter the category you want to search
The title entered will be compared to the category of all books and print if it true
 If false run the next command
Step 3: choice = 4
 Enter the day, month, or year you want to search
 Split PublicationDate in ListOfBook and compare it to the thing you entered


5. Function of borrowing a book


 Explain:
Step 1: Enter name and save it to variable name
Step 2: Enter phone number and save it to varible
phoneNumber
Step 3: Enter title and save it to variable title
Step 4: Enter dueDate and save it to variable
duaDate
Step 5: Create a new varible named newClient to
Step 6: Assign
1. name to Name in newClient
2. phoneNumber to PhoneNumber in newClient
3. title to Title in newClient
2. dueDate to DueDate in newClient
Step 7: Add newClient to ListOfClients
Step 8: End
Figure 13. Flowchart of choice 4



×