7388 - GCD1105 - ASM1 - Pham Thi Thanh Thien - GCD210520

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

lOMoAR cPSD| 10095830

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 Pham Thi Thanh Thien Student ID GCD210520

GCD1105
Class Assessor name Pham Thanh Son

Student declaration

I certify that the assignment submission is entirely my 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
lOMoAR cPSD| 10095830
lOMoAR cPSD| 10095830

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
lOMoAR cPSD| 10095830

Contents
Table of Contents
1. Task 1 - State your simple business problems to be solved (P1). ......................................................................................... 5
1.1. Overview of Algorithm.................................................................................................................................................... 5
Advantages of Algorithms: ..................................................................................................................................................... 6
Disadvantages of Algorithms: ................................................................................................................................................ 6
1.2. State a small problem, input, and output. ..................................................................................................................... 7
2. Task 2 - Analyse the problem and design the solutions by the use of suitable methods (P1). .......................................... 7
2.1. Analyse the problem. ....................................................................................................................................................... 7
2.2. Flowchart. ........................................................................................................................................................................ 7
3. Task 3 - Demonstrate the compilation and running of a program (P2 – ............................................................................ 9
3.1. Source code and screenshots of the final result. ........................................................................................................... 9
3.2. Explain code. .................................................................................................................................................................. 10
3.2.1. Input number needs to check. ...................................................................................................................................... 10
3.2.2. Check inputted whether > 0 or not. ............................................................................................................................. 11
3.2.3. After inputting number > 0, check if it is divisible for 2 or not. ................................................................................ 12
3.2.4. Further function: Ask users if they want to continue to check another number and Clear screen. ...................... 13
3.3. Explain briefly what is Software Development Life Cycle. ....................................................................................... 14
3.3.1. Identify the Current Problems. .................................................................................................................................... 14
3.3.2. Plan. ................................................................................................................................................................................ 14
3.3.3. Architechture Design..................................................................................................................................................... 15
3.3.4. Software Development. ................................................................................................................................................. 15
3.3.5. Testing. ........................................................................................................................................................................... 15
3.3.6. Deployment. ................................................................................................................................................................... 15
3.4. Explain how the source code is compiled. ................................................................................................................... 15
4. Procedural, object-oriented, and event-driven models, their characteristics, and the relationship between them.(P3)
................................................................................................................................................................................................. 18
4.1 Procedural programing......................................................................................................................................................... 18
4.2 Object-oriented programming (OOP) ................................................................................................................................. 18
4.3 Event-driven programming .................................................................................................................................................. 20
4.4 The relationship between procedural, object-oriented and event-oriented programming........................................... 25
5. Reference list. ......................................................................................................................................................................... 26
lOMoAR cPSD| 10095830

1. Task 1 - State your simple business problems to be solved (P1).


1.1. Overview of Algorithm.
The word Algorithm means “a process or set of rules to be followed in calculations or other
problem-solving operations”. As Consequently, an algorithm is a set of rules/instructions that
govern how a work is to be conducted step-by-step to achieve the desired results. (RishabhPrabhu,
2022)
As an efficient method, an algorithm can be represented in a finite amount of space and time,
and in a well-defined formal language to compute a function. Starting from an initial state and an
initial (possibly empty) input, instructions describe a calculation that, when executed, will
proceed through a finite number of well-defined successive states, finally produces "output" and
terminates in the final terminated state. The transition from one state to the next is not necessarily
deterministic. (Wipipedia_ Algorithm)

Figure 1: Algorithm.

To make the recipe, one would not follow any written directions, but simply the customary
ones. Similarly, not all written computer instructions are algorithms. For a set of instructions to be
considered an algorithm, it must meet the following criteria:

 Clear and Unambiguous: The algorithm should be simple and straightforward. Each of
its phases should be distinct in every way and lead to a single conclusion.
 Well-Defined Inputs: If an algorithm requires inputs, they should be well-defined.

 Well-Defined Outputs: The algorithm must clearly specify and well-define the output
lOMoAR cPSD| 10095830

that will be produced.


 Finite-ness: The algorithm must be finite because clearly it should not lead to infinite
loops or similar situations.
 Feasible: The method must be simple, general, and practical, and it must be able to be
implemented with the resources available. It can't contain any futuristic technologies or
anything like that.

Figure 2: Characteristics.

Advantages of Algorithms:

 It is simple to comprehend.
 he description of the solution to a problem is called an algorithm.
 The problem is broken down into smaller bits or stages in an algorithm, making it easier
for the programmer to turn it into a program.

Disadvantages of Algorithms:

 Writing algorithms takes a long time, so it takes a long time to complete the program and there
will be a lot of errors.
 Algorithms make it harder to demonstrate branching and looping statements.
lOMoAR cPSD| 10095830

Figure 3: Advantages and Disadvantages of Algorithm.

1.2. State a small problem, input, and output.


Problem: Check whether an positive input number is divisible by 2.

Input Output
77 77 not divisible by 2
Solve: In this issue, we will use the if function, there is one more if function inside. Also, use
some simple syntax like import and export.

2. Task 2 - Analyse the problem and design the solutions by the use of
suitable methods (P1).
2.1. Analyse the problem.
To solve this problem, we need the syntax to be able to enter the number to be checked. Then
there will be another syntax to see if it is bigger than zero. After checking that the number is not
negative, we will have 2 small cases. Divisible by 2 and not divisible by 2. To do this, we use the
remainder "%" division sign. For example: 8 % 2 = 0. That means that 8 is divisible by 2.

2.2. Flowchart.
lOMoAR cPSD| 10095830

Figure 4: Flowchart.
lOMoAR cPSD| 10095830

3. Task 3 - Demonstrate the compilation and running of a program (P2).

3.1. Source code and screenshots of the final result.

Figure 5: Source Code.


lOMoAR cPSD| 10095830

3.2. Explain code.

3.2.1. Input number needs to check.

Figure 6: Input number.

* First, we need to enter a number that needs to be checked.


* We will use the Readline function for input.
lOMoAR cPSD| 10095830

3.2.2. Check inputted whether > 0 or not.

Figure 7: Check if it > 0 or not.

 Next, we will check the numbers we just entered whether they are bigger than 0. There will
be 2 cases:
* If it is greater than 0, they run another if loop.
* If it is less than 0, we will say that the number is not valid.
lOMoAR cPSD| 10095830

3.2.3. After inputting number > 0, check if it is divisible for 2 or not.

Figure 8: Check if it divisible for 2 or not.


 When it is bigger than 0, we check if they are divisible by 2. There is a % sign that will
check it:
* If it's divisible by 2, we'll output the message that they're divisible by 2 and
their result.
* If not, we will say that they are not divisible by 2. And if we do, how much will it
be and remainder of 1.
lOMoAR cPSD| 10095830

3.2.4. Further function: Ask users if they want to continue to check another number
and Clear screen.

Figure 9: Extra function.

 We will use the Do-while function to ask the user if they want to continue.
 This Do-while function will run once before checking the condition, so it will run the
program.
 Towards the end of the program, we will ask if they want to continue:
* If yes, enter 'y' to continue. When the variable ='y' true to the condition, it
will continue to run.
* Otherwise, the program will stop and complete.
 I also add function clear screen: Console.Clear(). In order to easy to see and tangle
free.
lOMoAR cPSD| 10095830

3.3. Explain briefly what is Software Development Life Cycle.


SDLC or the Software Development Life Cycle is a systematic and orderly approach to solving
problems related to software systems or in other words it is a structure towards the development
of a software product. Depending on different types of software development models, the
following phases can be arranged and organized differently.

Figure 10: What is SDLC?

3.3.1. Identify the Current Problems.


 At this step of the SDLC, all stakeholders, including consumers, salespeople, industry experts,
and programmers, must provide feedback. Learn the present system's strengths and faults with the
purpose of improving it.
3.3.2. Plan.
 The team calculates the cost and resources needed to implement the studied requirements at this
level of the SDLC. It also describes the hazards and proposes sub-plans for mitigating such risks.
 In other words, the team should establish the project's viability and how to properly
implement the project while minimizing risk.
lOMoAR cPSD| 10095830

3.3.3. Architechture Design.


 This stage of the SDLC begins with converting the software specifications into a design plan
known as the Design Specification. The strategy is then reviewed by all stakeholders, who
provide input and ideas. It is critical to have a strategy in place for gathering and incorporating
stakeholder feedback into this document. Failure at this point will almost surely result in cost
overruns at best and the project's utter collapse at worst.
3.3.4. Software Development.
 The true development begins at this point. It is critical that each developer adheres to the
agreed-upon plan. Also, make certain that you have adequate rules in place about coding style
and processes.
3.3.5. Testing.
 At this point, we look for flaws and inadequacies. We work to resolve any concerns until the
product fulfills the original standards. In a nutshell, we want to see if the code fits the criteria.
3.3.6. Deployment.
 The purpose at this step is to deploy the software to the production environment so that users can
begin utilizing the product. Many firms, however, prefer to move the product via several
deployment environments, such as testing or staging.
 This permits any stakeholders to test the product in a safe environment before releasing it to the
market. Furthermore, this permits any last flaws to be identified before the product is released.

3.4. Explain how the source code is compiled.


 When you run the C# compiler, it takes your code as an input, does some processing, and
then outputs your program in intermediate language (IL) code which is saved in *.exe or
*.dll files. (Codeasy, n.d.)

Figure 11: Compile time.

 After the IL code is generated, we still don't have anything for our processor to read. After
lOMoAR cPSD| 10095830

that, it will convert the IL code to machine codes. The name for that something is
the Common Language Runtime or CLR.
 CLR is a program running on your computer that manages the execution of IL code. It uses
a just-in-time, or JIT, a compiler to translate the IL code into machine code (sometimes
called "native" code). (Codeasy, n.d.)

Figure 12: Compile and Runtime.

 To boil it down, let's take a look at the path your code takes from being written to being
run:
lOMoAR cPSD| 10095830

Figure 13: Flowchart about how C# is compiled and run.


lOMoAR cPSD| 10095830

4. Procedural, object-oriented and event-driven models, their characteristics, and


the relationship between them. (P3)
4.1 Procedural programing
 Procedural programming can be understood as the first programming paradigm that a new programmer will
learn. The set-up procedure is where the main focus is on completing tasks in sequence. Flow control
organization chart of the program. If the program is extensible, it is structured in a number of small units
called functions, which share data system-wide. In basic theory, this model uses a top-down data approach
and treats data and procedures as two different entities. Based on the concept of procedure call, Procedural
Programming divides the program into procedures, also known as procedures or functions, which simply
contain a set of steps to be performed.

 Advantages
• The programmed simplicity, as well as the ease of implementation of compilers and interpreters,
make procedural programming ideal for general-purpose programming.
• A wide range of books and online course materials on tested algorithms are available, making it easy
to study as you go.
• Because the source code is portable, it can also be used to target a different CPU.
• The code can be reused without having to copy it in different portions of the software.
• The memory required is also reduced using the Procedural Programming technique.
• The program flow can be simply followed. (Bhatia,
2021)
lOMoAR cPSD| 10095830

 Disadvantages
• The main disadvantage of procedural programming is that it does not run as fast compared to code
written in a lower level language. For applications that require a lot of processing power, this can limit the
efficiency of procedural programming.
• Relationships with real-world objects are difficult.
• Activity takes precedence over data, which can cause problems in data-sensitive situations.

* Example of Procedural programming:

4.2 Object-oriented programming (OOP)

 Object-oriented programming (OOP) is a programming paradigm based on the concept of


"objects", which can contain data and code. The data is in the form of fields (often known as
attributes or properties), and the code is in the form of procedures (often known as methods).
 A common feature of objects is that procedures (or methods) are attached to them and can access
and modify the object's data fields. In this brand of OOP, there is usually a special name such as
this or self used to refer to the current object. In OOP, computer programs are designed by making
them out of objects that interact with one another.
* Object-oriented programming is a programming method that has four main properties:
lOMoAR cPSD| 10095830

Figure 14: Main properties of OOP.

 Abstraction: This is the ability of the program to ignore or ignore some aspects of the information
it is directly working on, i.e. it's ability to focus on the core needs set. Each object serves as an
"animal" that can internally complete tasks, report, change its state, and communicate with other
objects without telling how the object is handled. can perform operations. This property is often
referred to as data abstraction.
 Encapsulation and information hiding: This property does not allow the user of the object to
change the internal state of an object. Only the internal methods of the object allow to change its
state. How the external environment is allowed to affect an object's internal data is entirely up to
the coder. This property ensures the integrity of the object.
 Polymorphism: Expressed through sending messages (message). Sending these messages is
comparable to calling the internal functions of an object. The methods used to respond to a
message will respond differently depending on the object to which the message is sent. The
programmer can define a property (for example, by method names) for a series of close objects,
but when implementing the same name, the implementation of each object will be automatic.
occurs according to the characteristics of each object without confusion.
 Inheritance: This property allows an object to have properties that another object already has
through inheritance. This allows objects to share or extend existing properties without having to
redefine them. However, not all object-oriented languages have this property.
* Features of object-oriented programming:
 Easily manage code when there are program changes.
 Ease of project expansion.
 Significant resource savings for the system.
 Has high security.
 Highly reusable.
 It has the ability to chart objects.
 Allows to classify objects into different classes.

* Example of Object-oriented programming:


lOMoAR cPSD| 10095830

 Class and Object:


lOMoAR cPSD| 10095830

 Encapsulation:
lOMoAR cPSD| 10095830

 Inheritance:

 Polymorphism

 Abstraction:
lOMoAR cPSD| 10095830

 Constructor:

4.2 Event-driven programming

 Event-driven programming is a programming paradigm in which the flow of the program is


determined by events such as user actions (mouse clicks, key presses), sensor outputs, or message
passing from other programs or threads. Event-driven programming is the dominant paradigm
used in graphical user interfaces and other applications that are centered on performing certain
actions in response to user input. This is also true of programming for device drivers .
 In an event-driven application, there is generally a main loop that listens for events and then
triggers a callback function when one of those events is detected. In embedded systems, the same
may be achieved using hardware interrupts instead of a constantly running main loop. Event-
driven programs can be written in any programming language, although the task is easier in
languages that provide high-level abstractions, such as await and closures.

* Example of Event-driven programming:


lOMoAR cPSD| 10095830

4.3 The relationship between procedural, object-oriented and event-oriented programming.

 Procedural programing, Object-oriented programming and Event-oriented programming are three


very important programming methods when learning programming. If learning a programming
language is like learning the alphabet, learning programming methods is like learning to write or
write poetry.
 On the other hand, Procedural Programming, unlike OOP, sheds focus on the steps which will be
performed to complete a task, rather than the interaction between the objects. The tasks are broken
down into subroutines, variables and data structures. At any point in time, these procedures can
be called within the program execution.
 Combining Procedural, Object-Oriented Programming with Event-Oriented Programming would
be an incomplete program, but enough to make it important in large programs. While there is no
perfect programming paradigm, it is important to understand that the correct paradigm will always
depend on the type of language you use and the program you wish to create. It is advised that for
maximum results and a strong portfolio, one should have proficiency in all three major
programming paradigms. The best way to try to get better at programming paradigms is to try.
Each programming mode is geared towards solving different problems.
 Good application of programming methods will make a Pro programmer.
lOMoAR cPSD| 10095830

5. Reference list.

Bibliography
* Wikipedia: https://en.wikipedia.org/wiki/Algorithm

https://en.wikipedia.org/wiki/Object-oriented_programming

https://en.wikipedia.org/wiki/Event-driven_programming

https://www.geeksforgeeks.org/introduction-to-algorithms/

https://viblo.asia/p/vong-doi-va-quy-trinh-phat-trien-phan-mem-phan-1-07LKXmwrZV4

https://freecontent.manning.com/how-is-c-compiled/

https://hackr.io/blog/procedural-programming

* ALTVATER, A. (2020, 5 8). Retrieved 4 9, 2022, from Stackify: https://stackify.com/what-is-


sdlc/#:~:text=The%20Software%20Development%20Life%20Cycle%20%28SDLC%29%20refers%20to,analy
sis.%20Planning.%20Software%20design%20such%20as%20architectural%20design.

* Codeasy. (n.d.). Retrieved 4 9, 2022, from Codeasy: https://codeasy.net/lesson/c_sharp_compilation_process

* RishabhPrabhu. (2022, 1 13). geeksforgeeks. Retrieved 4 8, 2022,


from *

You might also like