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

information technology assignment 2 unit programming

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.17 MB, 71 trang )

<span class="text_page_counter">Trang 1</span><div class="page_container" data-page="1">

BTEC FPT INTERNATIONAL COLLEGE

INFORMATION TECHNOLOGYASSIGNMENT 2

</div><span class="text_page_counter">Trang 2</span><div class="page_container" data-page="2">

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit: Programming

Re-submission date <sup>Date received (2nd </sup>submission)

Student declaration

I certify that the assignment submission is entirely my own work and I fully understand theconsequences of plagiarism. I understand that making a false declaration is a form of malpractice.

Student’s signature: Nguyen Van PhiGrading grid

</div><span class="text_page_counter">Trang 3</span><div class="page_container" data-page="3">

Summative Feedbacks: Resubmission Feedbacks:

Grade: Assessor Signature: Date:Internal Verifier’s Comments:

Signature & Date:

</div><span class="text_page_counter">Trang 4</span><div class="page_container" data-page="4">

OBJECT-2.1. Give explanations of what procedural, object-oriented and event-drivenparadigms are; their characteristics and the relationship between them. (P2)...10

2.1.1. Procedural programming system (POP)...10

2.1.2. Oject-oriented programming system (OOPs)...15

2.1.3. Event driven programming (EDP)...18

2.1.4. Relationship between Procedural, Object-oriented, Event-driven...22

2.2 Analyze the common features that a developer has access to in an IDE. (M2).242.2.1. Introduction to IDE and its uses:...24

2.2.2. Common features of the IDE:...25

Chapter 3: IMPLEMENT BASIC ALGORITHMS IN CODE USING AN IDE (LO3)...29

3.1. Write a program that implements an algorithm using an IDE. (P3)...29

3.2. Use the IDE to manage the development process of the program. (M3)...37

Chapter 4: DETERMINE THE DEBUGGING PROCESS AND EXPLAIN THEIMPORTANCE OF A CODING STANDARD. (LO4)...51

4.1. Explain the debugging process and explain the debugging facilities available inthe IDE. (P4)...51

4.2. Integrates many programs such as code completion, compiler, editor Outlinethe coding standard you have used in your code. (P5)...55

</div><span class="text_page_counter">Trang 5</span><div class="page_container" data-page="5">

4.3. Evaluate how the debugging process can be used to help develop more

secure, robust applications. (M4)...61

CRITICAL EVALUATION...65

REFERENCES...67

</div><span class="text_page_counter">Trang 6</span><div class="page_container" data-page="6">

LIST OF TABLES AND FIGUR

Figure 2-1: Procedural programming system...10

Figure 2-2: Example of Procedural programming system...12

Figure 2-3: Example of Procedural programming system...13

Figure 2-4: The equation has two distinct solutions...13

Figure 2-5: The equation has two double solutions...14

Figure 2-6: Equation has no solution...14

Figure 2-7: Oject-oriented programming system (OOPs)...15

Figure 2-8: Code (1)...17

Figure 2-9: Code (2)...17

Figure 2-10: Result...18

Figure 2-11: Event driven programming (EDP)...18

Figure 2-12: Form account login...20

Figure 2-13: The code part of the login form...21

Figure 2-14: Result logged in successfully...21

Figure 2-15: Result wrong username or password...22

Figure 2-16: Visual Studio...24

Figure 2-17: Example about text editor in Visual studio...26

Figure 2-18: This is a debugger in Visual studio...26

Figure 2-19: Debugging in Visual studio. (1)...27

Figure 2-20: Debugging in Visual studio. (2)...27

Figure 2-21: Several languages are supported in Visual Studio...28

Figure 2-22: Integrated Development Environment...28

Figure 3-1: Form login...30

Figure 3-2: Code program of login...30

</div><span class="text_page_counter">Trang 7</span><div class="page_container" data-page="7">

Figure 3-3: Code login...31

Figure 3-4: Solve the equations...31

Figure 3-5: Source code (1)...32

Figure 3-6: Source code (2)...32

Figure 3-7: Source code (3)...33

Figure 3-8: Source code (4)...33

Figure 3-9: Fix code error...34

Figure 3-10: Result after fix code error...34

Figure 3-11: Valid equation...35

Figure 3-12: The equation has no solution...35

Figure 3-13: The equation has two distinct solutions...36

Figure 3-14: The equation has two double solutions...36

Figure 3-15: Equation has no solution...37

Figure 3-0-16: Select Options...37

Figure 3-17: Main interface...39

Figure 3-18: Create new project (1)...39

Figure 3-19: Create new project (2)...40

Figure 3-20: Create new project (3)...40

Figure 3-21: Main Form...41

Figure 3-22: Adding elements to form. (Tabcontrol 1)...41

Figure 3-23: Adding elements to form. (Tabcontrol 2)...42

Figure 3-24: Code (1)...42

Figure 3-25: Code (2)...43

Figure 3-26: Code (3)...43

Figure 3-27: Code (4)...44

</div><span class="text_page_counter">Trang 8</span><div class="page_container" data-page="8">

Figure 3-36: Before debugging...48

Figure 3-37: Result after error correction...49

Figure 3-38: program results. (1)...49

Figure 3-39: program results. (2)...50

Figure 3-40: program results. (3)...50

Figure 4-1: Definition Debugging...51

Figure 4-2: Syntax error...52

Figure 4-3: Invalid variable error...53

Figure 4-4: Syntax error of Form...53

Figure 4-5: Incorrect variable format error of Form. (1)...54

Figure 4-6: Incorrect variable format error of Form. (2)...54

Figure 4-7: Form design...57

Figure 4-8: Code Form (1)...58

Figure 4-9: Code Form (2)...58

Figure 4-10: Result Max 2...59

Figure 4-11: Result Max3...59

Figure 4-12: Code console...60

</div><span class="text_page_counter">Trang 9</span><div class="page_container" data-page="9">

Figure 4-13: Result console...60

Figure 4-14: Debuging...61

Figure 4-15: Code...63

Figure 4-16: Star the debugger...63

Figure 4-17: Making a breakpoint...64

Figure 4-18: Stop the debugger...64

YTable 2-1: Differences between procedural, object-oriented and event-driven programming...23

Table 4-1: Some coding standard of Form...55

Table 4-2: Some coding standard of Console...56

</div><span class="text_page_counter">Trang 10</span><div class="page_container" data-page="10">

LIST OF ACRONYMS

Procedural programmingOject-oriented programmingEvent driven programmingIntegrated Development Environment

</div><span class="text_page_counter">Trang 11</span><div class="page_container" data-page="11">

Programming introduces students to the IDE, its features, and the IDE's featureswhile acquiring the basics of programming paradigms such as procedural programming,object-oriented programming, and programming. event-driven programming, programstructure, data, and data collection. This is one of the subjects. Some standards andnaming conventions in the code. It also provides students with the necessary knowledge tocreate basic applications.

This report includes the following:

Chapter 2: Explain the characteristics of procedural, object-oriented and driven programming, conduct an analysis of a suitable Integrated DevelopmentEnvironment (IDE) (Lo2)

event-Chapter 3: Implement basic algorithms in code using an IDE (Lo3)

Chapter 4: Determine the debugging process and explain the importance of acoding standard (Lo4)

</div><span class="text_page_counter">Trang 12</span><div class="page_container" data-page="12">

Chapter 2: EXPLAIN THE CHARACTERISTICS OF PROCEDURAL,OBJECT-OTIENTED AND EVENT-DRIVEN PROGRAMMING,

CONDUCT AN ANALYSIS OF A SUITABLE INTEGRATEDDEVELOPMENT ENVIRONMENT (LO2)

2.1. Give explanations of what procedural, object-oriented and event-drivenparadigms are; their characteristics and the relationship between them. (P2)

2.1.1. Procedural programming system (POP) Definition POP:

Procedural programming is a programming paradigm that focuses on defining asequence of procedures or a set of instructions to be executed to solve a problem orperform a specific task. It is based on the concept of breaking down a problem intosmaller, manageable pieces called procedures or functions.

<small>Figure 2-1: Procedural programming system</small>

The characteristics of POP:

- Linearity: Procedural programming is usually done in a linear flow, i.e. top to bottomand left to right, each piece of code is executed in top to bottom order.

</div><span class="text_page_counter">Trang 20</span><div class="page_container" data-page="20">

An example of OOP : This is an example of calculating the circumference andarea of a circle:

<small>Figure 2-8: Code (1)</small>

<small>Figure 2-9: Code (2)</small>

</div><span class="text_page_counter">Trang 21</span><div class="page_container" data-page="21">

2.1.3. Event driven programming (EDP)Definition EDP:

Event-driven programming is a programming method in which a program is builtbased on events occurring in the system or from the user. Instead of executing code lineby line sequentially, event-driven programming focuses on reacting to and handling eventssuch as button clicks, mouse movements, keyboard input, or system notifications.

<small>Figure 2-11: Event driven programming (EDP)</small>

</div><span class="text_page_counter">Trang 22</span><div class="page_container" data-page="22">

The characteristics of EDP:

- Event handling: Event-driven programming focuses on handling events like mouseclick, keyboard input, mouse click, object state change, etc. When the event occurs,the related code will be executed.

- Multi-threading: Event-driven programming allows for multi-threading, i.e. canhandle multiple events at the same time. When one event occurs, other events cancontinue to be processed without being paused.

- Separation of objects and event handling: In event-driven programming, objects aredecoupled from event handling code. This ensures code reuse and flexibility inapplication development.

- Asynchronous handling: Event-driven programming often uses asynchronousmechanisms to handle events. This allows simultaneous execution of different taskswithout having to wait for the results of the previous task.

- Interactivity: Event-driven programming creates interactive applications in whichusers can interact with components, change their state, and send interactions orrequests to the system.

Advantages, disadvantages EDP:Advantages of event-driven programming:

- Reliability: Event-driven programming allows detecting and handling events causedin the system automatically and quickly, helping to ensure the reliability of theapplication.

- Scalability: Event-driven programming allows the organization and management ofsource code in an organized manner, making it easy to extend and reuse thesource code.

- Interactivity: Event-driven programming allows an application to interact with usersand other system components, such as buttons, mouse clicks, or events from anexternal application.

- Flexibility: Event-driven programming allows programmers to easily change the flowof event handlers, add or omit event handlers flexibly and easily.

Disadvantages of event-driven programming:

</div><span class="text_page_counter">Trang 23</span><div class="page_container" data-page="23">

- Difficulty in understanding and following logical flow: Since events occur in a linear sequence, understanding and following logical flow in a program can becomecomplicated. This can make debugging and maintaining the source code difficult.- Security risk: Event-driven programming often relies on events and state changes in

non-the application. This can make non-the application vulnerable to techniques such asbuffer overflows or event transfer attacks.

- Depends on libraries and frameworks: Event-driven programming often depends onlibraries and frameworks to manage and handle events. This can increasecomplexity and reliance on external technologies.

- Difficult to debug: When an error occurs in a program, it can become difficult to findthe specific cause. Since events can be fired in many different places andpropagated through multiple methods, tracking and debugging events can be time-consuming and labor-intensive.

An example of EDP:

Example of an event-driven programmer's account login form.

</div><span class="text_page_counter">Trang 24</span><div class="page_container" data-page="24">

<small>Figure 2-13: The code part of the login form</small>

</div><span class="text_page_counter">Trang 25</span><div class="page_container" data-page="25">

<small>Figure 2-15: Result wrong username or password</small>2.1.4. Relationship between Procedural, Object-oriented, Event-driven.

There are several similarities between procedural, object-oriented, and event-drivenprogramming, including:

- They are all programming methods used to develop computer programs andapplications.

- All three methods focus on breaking down tasks into smaller pieces that are easierto manage and handle.

- They can both use variables and control statements to perform tasks andoperations.

- All three methods use code blocks to group related statements together.- They can all interact with the user through the user interface.

</div><span class="text_page_counter">Trang 26</span><div class="page_container" data-page="26">

However, there are also some differences between procedural, object-oriented and driven programming. Below is a table of differences between procedural, object-orientedand event-driven programming:

<small>event-Table 2-1: Differences between procedural, object-oriented and event-driven programming</small>Characteristic Procedural

Programming <sup>Object Oriented</sup>Programming Programming<sup>Event Driven</sup>

programs asprocedures(functions).

Focus on modeling thereal world into objectswith properties and

Focuses on handlingevents triggered bythe user or the

usually kept separate. packaged together in<sup>Data and code are</sup>objects.

Separate event andevent handler, no data

messages andresponses.

Interaction betweencomponents throughsending and receiving

events.For example Weather prediction

program: Functions tocalculate temperature,

humidity, ...

Student managementapplication: There is a

SinhVien class withmethods such asentering grades,calculating average

scores, ...

Application handlingmouse click events,

keystrokes: Handleclick events, handlekeystroke events, ...

The relationship between procedural, object-oriented, and event-driven programming aredifferent methods for organizing and managing source code in programming:

Procedural programming focuses on individual functions and procedures, each ofwhich does a specific job. The code is organized into sequential command lines and

</div><span class="text_page_counter">Trang 27</span><div class="page_container" data-page="27">

follows the principles of normalization. The user interface is represented bywindows, buttons and other elements.

Object-oriented focuses on creating accessible objects and performing actions inthe program. Each object has properties (data) and methods (behavior). Objectscan interact with each other by sending and receiving messages. Object orientationprovides easier reusability, scalability, and maintainability than proceduralprogramming.

Event driven focuses on event handling and corresponding response. When theuser interacts with the UI, events will be fired and the program will react accordinglyaccording to the event handlers. Event-driven separates program components andallows parallel processing of events.

To summarize, procedural, object-oriented, and event-driven programming are differentapproaches to programming, but can also be combined to create complex and flexibleapplications. Each method has its own advantages and limitations and is suitable fordifferent cases and requirements.

2.2 Analyze the common features that a developer has access to in an IDE. (M2)2.2.1. Introduction to IDE and its uses:

Introduction to Visual Studio:

Visual Studio is an Integrated Development Environment (IDE) developed byMicrosoft. It provides a wide range of tools and features for software developers to build,test, deploy, and manage applications. Visual Studio supports many programminglanguages, including C++, C#, Visual Basic, F#, JavaScript, TypeScript, Python and manymore.

<small>Figure 2-16: Visual Studio</small>The main uses of Visual Studio include:

</div><span class="text_page_counter">Trang 28</span><div class="page_container" data-page="28">

- Easy application development: Visual Studio provides an intuitive and user-friendlygraphical interface that helps developers create applications quickly and efficiently.

- Smart code editing: Visual Studio has built-in IntelliSense functionality, whichpredicts and suggests code, helping to reduce errors and increase code efficiency.

- Debug and review code: The IDE provides a powerful set of debugging tools thatmake it easy to find and fix errors. It also supports code review among developmentteam members.

- Source code version management: Visual Studio integrates with versionmanagement systems like Git and TFS (Team Foundation Server), allowingdevelopers to work together on the same project without overwriting each other.

- Mobile and cross-platform application development: Visual Studio supports mobileapplication development for platforms such as Android, iOS, and Windows Mobile,as well as cross-platform application development using technologies such as .NETand Xamarin.

- Web and Cloud Application Development: Visual Studio supports web applicationdevelopment using ASP.NET and other web technologies. It also easily integrateswith Microsoft cloud services like Azure for cloud application deployment andmanagement.

- Build and manage databases: Visual Studio provides built-in tools for creating,querying, and managing databases, including SQL Server databases and others.

- Game development: Visual Studio supports game development in a variety ofprogramming languages and technologies, including DirectX, Unity, and Cocos2d.

2.2.2. Common features of the IDE:

Common features of the Integrated Development Environment (IDE) include:Text editor: Provides a text editor interface, allowing developers to convenientlyenter source code and edit code. There is support for syntax highlighting to highlightkeywords, variables, and other elements in the code for clarity and readability.

</div><span class="text_page_counter">Trang 29</span><div class="page_container" data-page="29">

Debugger, Compiler: Integrated compiler and debugger allows error codechecking and debugging when developing applications. Error messages andwarnings during compilation help detect and correct syntax and logic errors.

<small>Figure 2-18: This is a debugger in Visual studio</small>

</div><span class="text_page_counter">Trang 30</span><div class="page_container" data-page="30">

Completion code: Provides code completion feature that predicts and suggestscode as developers enter code, saving time and minimizing errors. This is a nicefeature when working with complex libraries and frameworks.

<small>Figure 2-19: Debugging in Visual studio. (1)</small>

<small>Figure 2-20: Debugging in Visual studio. (2)</small>

</div><span class="text_page_counter">Trang 31</span><div class="page_container" data-page="31">

Supported programming languages: The IDE supports many differentprogramming languages like C++, C#, Java, Python, JavaScript, Ruby, PHP, andmany more. Provides the right tools and features for each language, helpingdevelopers be productive.

<small>Figure 2-21: Several languages are supported in Visual Studio</small>

Integrated Development Environment: IDE provides a working environment thatintegrates all the necessary tools for software development such as editor,debugger, compiler, source code manager, and project manager. Support for theintegration of third-party toolkits and plugins that extend the IDE's functionalityaccording to user needs.

<small>Figure 2-22: Integrated Development Environment</small>

</div><span class="text_page_counter">Trang 32</span><div class="page_container" data-page="32">

Chapter 3: IMPLEMENT BASIC ALGORITHMS IN CODE USINGAN IDE (LO3)

3.1. Write a program that implements an algorithm using an IDE. (P3)We will code a basic computer software: Solve first and quadratic equations.We will create the interface as follows: create 3 groups:

- Input group- Output group

- The group chose to solve first and quadratic equationsPrepare:

- Use winform and C# language to code this software.- 3 buttons solve, delete, exit.

- 3 buttons, 2 radiobuttons, 6 labels and 5 textboxes to enter numbers and displayresults

- 3 group boxes to group them togetherAlgorithms:

Equation First Degree Algorithm:

- First, ask the user to enter two numbers a and b in order of importance.

- Then check if a is equal to 0. If so, the result is - b/a. If not, prompt the user to enter.

re-Quadratic Equation Algorithm:

- Input: Enter three coefficients a, b and c from the user.- Calculate the value of delta (Δ): Δ = b^2 - 4ac- Check the value of delta:

o If Δ < 0: The equation has no real solution, it only has a complex solution.o If Δ = 0: The equation has a double solution.

o If Δ > 0: The equation has two real and distinct roots.- Calculate the value of the variable x (the solution of the equation):

o If Δ < 0: There is no real solution.

o If Δ = 0: Use the formula x = -b / (2a) to calculate the value of x.

o If Δ > 0: Use the formula x = (-b ± √Δ) / (2a) to calculate two real roots of x.

</div><span class="text_page_counter">Trang 33</span><div class="page_container" data-page="33">

I'll log into my login and go to the first and second quadratic calculator.Below is a picture of the login form:

<small>Figure 3-23: Form login</small>

<small>Figure 3-24: Code program of login</small>

</div><span class="text_page_counter">Trang 34</span><div class="page_container" data-page="34">

<small>Figure 3-26: Solve the equations.</small>These are source codes:

</div><span class="text_page_counter">Trang 35</span><div class="page_container" data-page="35">

Here is the code of Solve the Equation:

<small>Figure 3-27: Source code (1)</small>

<small>Figure 3-28: Source code (2)</small>

</div>

×