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

Một phần của tài liệu Information technology assignment 2 unit programing (Trang 24 - 51)

CHAPTER 2 PROBLEMS RELATED TO PROGRAMMING METHODS AND IDE

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

- Solve the equation of max 2 , max3, find the largest number.

Preparation

-We use windown forms and C# language to code this software.

- I designed a problem with 3 buttons search, delete, and exit - 4 labels and 4 textboxes to input number and show result.

- 2 radio buttons and a group box to group them together.

Algorithms:

-First I created 3 textboxes to enter the results in to enter the numbers to find the largest number.

-Next will select the radio buttons to choose 2 values or 3 values.

-Finally select search to display the results in the lable output.

Solve the first order algorithms of the equation:

-First, in order of importance, we ask the user to enter any 3 numbers such as 6, 8, 9 at the button number1,number2,number3.

- then the user will choose either max2 or max3 to select the value

if the user chooses max2, then number1 and number 2 will display number 6 and 8.

- if the user chooses max3, it will show 3 numbers 6, 8, 9 in lable

number1,number2,number3. When the user clicks search, the lable output will display the largest number of 9.

So the problem was run successfully and met the requirements.

I will write a program for the problem max2,max3 to find the largest number and use windows forms to design the interface of the problem.

Step1: First, we create a project file and then choose Windown Forms Application (.Net Frame Work)

24 Figure :windows Forms app. NET Framework 15

Step2: We have a pattern like the picture. Next, we select the toolbox create the IDE to

Figure : Windows forms 16

Step3: We design the main interface of the program as shown below:

The main interface of the program.

Figure : Designs windows forms 17 Step 4 Next, we write the code for the program :

Figure :code 18

26 Figure :code 19

Figure : Code to run the program 20

Step5 : Give results:

- we choose max 2 then we will give the result like this.

Figure : Result Choose max 2 21 Conversely, if you choose max3, the input will display 3 number values.

Figure : Result choose max 3 22

28 in the IDE. (P4)

o Definition Debugging.

Debugging, in computer programming and engineering, is a multistep process that involves identifying a problem, isolating the source of the problem, and then either correcting the problem or determining a way to work around it. The final step of debugging is to test the correction or workaround and make sure it works.

o Debug process.

Identify errors: Save time and avoid errors at the user's site. Identifying errors at an earlier stage reduces the numbr errors and wasted time of

Locate Errors: It is recommended to find the exact location of the error to fix the error and execute the code faster.

Error Analysis: To understand the type of error or failure and reduce the number of errors, we need to analyze the error. Resolves one error that may lead to another that stops the application process.

Analytical Proof: Once we have finished analyzing the error, we need prove the to analysis. It uses a test automation process to write test cases through the test framework.

Covering up side damages: Bugs can be resolved by making the appropriate changes and moving on to the next phases of the code or program to correct other errors.

Fix and Validate: This the final stage check all new bugs, changes software is to in or program and execute the application.

Example about debugging in IDE

I wrote a problem about finding the greatest common divisor and it has errors and I will correct it to make it work.

The errors of the problem below are:

- Method error - Data type error - Syntax error

Here is the code that shows all the errors of the problem:

Figure 23: Error in the program

30 The image below shows us that the problem is wrong on lines 21, 17, 11.

Figure :Line show Error 24

In line 11 the declaration is missing a sign ; so the report is false and we have to add a ; ] [

Figure : debugging Syntax 25

The 17th line, the data type declared is wrong, we have to fix it as shown below:

Float => Return

Figure : debugging Float = return 26

In line 21 the main method is declared wrong, so the problem is faulty. We fix the error as follows:

class void => static void

Figure : Debugging class = static 27

After fixing the errors, we proceed to run and check if the problem has been completely corrected.

And this is the result after we successfully fix the error, the result is as shown below:

Figure : Result program 28

3.3 Integrates many programs such as code completion, compiler, editor Outline the coding standard you have used in your code. (P5) Indent:

- The opening braces must a straight column with the closing brace. be in - Each sub-instruction a block must indented. in be

- Makes the source code easier to read - Avoid using confusing coding.

- The length the functions should not of be too large.

Variable:

- Avoid using naming numbers for variables

- Global variable names begin using capital letters the beginning each word at of - The constants should capitalized be

32 small letter.

- Limit the use global variables of

- Use comments to explain each function, each variable.

- The naming convention for variables - Naming meaningful and easy to understand The name of the function:

- The first letters need to capitalized. be - Need to describe its function so that concise it is Some example set name for winform:

OBJECT NAME SET NAME FOR OBJECT EXAMPLE

Button btn btnHome

Check Box chk chkGender

Data View dvw dvwInforStudent

Form frm frmLogIn

Label lbl lblNameUser

Link Label llbl llblFacebook

List View lsvw lsvwInforStudent

Numeric Up Down nud nudHour

Picture Box pic picLogo

Scroll Bar sbr sbrTable

Tab Control tab tabDesign

Textbox txt txtPassword

Timer tmr tmrDeadline

ToolTip tip tipCopy

Tree View tre treBooks

Situations:

- You have applied for an intern position of a software development company and been invited for an interview. You passed the presentation demonstrating your problem solving and basic programming skills.

- You are now given a more challenging task to create a fully functional, secure application that has been developed with an IDE and adheres to coding standards for a detailed business problem.

Problem:

- With the current complicated conditions of the epidemic, information technology is becoming more and more popular among all people.

- Developing an application that can support adding and removing accounts Ideas:

- The initial intention is that I build an application with the function of adding accounts and deleting accounts, the information after being entered will be saved into ListView with corresponding information columns.

- This program will be created in C#, and the integrated development environment (IDE) will be used by Microsoft Visual Studio which is a program that has a number of essential features that make coding easy and convenient. More convenient.

Describe the idea of the program algorithm:

We have created formrs with the following controls.

1 Panel to create a title for the application

2 GroupBox with two different parts, 1 part with operations and 1 part to perform input and display information.

3 Button with 3 functions that are Add, Del and Exit.

3 TextBox to enter the corresponding information is Name Acc, Password Acc and ID.

1 ListView to store the information of the created account.

then i named the textbox textbox Account name = txt_name textbox Account password= txt_pass texttbox ID = txt_ID

- We will start by creating a form with Account name ,Acccount password and ID , in addition there are buttons like Add account , Delete Account , Exit application . There will also be a listview to display the information that the user has entered.

34 - In addition, the delete button will help users delete the account they want to delete by selecting that account, then clicking on the delete acccout button will display the command

"you want to delete" then click ok, the account will be deleted. will be deleted afterwards.

- finally the Exit application button to ask the user if he wants to exit or not. If YES is selected, exit the program, if NO is selected, the command will be cancelled.

Result:

Figure : Forms account manager 29 o Add Account

Figure : Forms account manager 30

o Delete Account

Figure :Forms account manager 31

o Exit Application

Figure 32:Forms account manager

36 Figure :code account manager 33

Figure :code account manager 34

Figure :code account manager 35

3.4 Analyze the common features that a developer has access to in an IDE. (M2) Introduction to IDE

It is an integrated environment used to write code for application development. In addition, the IDE integrates other support tools such as compiler, interpreter, error checking, formatting highlighting code, organizing code folders, searching code or ...

Figure : IDE 36 Functions of the IDE

Text editor: Almost every IDE will have a text editor designed for writing and manipulating source code. Some tools may have visual elements for dragging and dropping user interface

elements, but most have simple interfaces with language-specific syntax highlighting such as Turbo Pascal, Notepad++, etc

38 Figure : Text editor 37

Debugger: Debugging tools help users identify and fix errors in the source code. They often simulate real-world scenarios test functionality and performance. Programmers to and software engineers can often test different segments of code and identify bugs before an application is released.

Compiler: are components that translate a programming language into a language that a computer can process, such as binary code. Machine code is analyzed to ensure its accuracy. The compiler then parses and optimizes the code to optimize performance.

Figure : Information of each bug 38

Figure : Debug 39

Code completion: Code complete features assist programmers by intelligently identifying and inserting common code elements. These features help developers save time coding and reduce the chance of syntax errors.

40 Figure : This is start program 40

Support programming language: IDEs are usually specific to one programming language, although some also offer multilingual support such as the Sublime Text IDE. As such, the first step is to find out what language you are using and choose an appropriate IDE.

Figure 41:Support programming language

3.5 Use the IDE to manage the development process of the program (M3) To use an IDE in application development management, you want to choose an IDE that matches the language you use. In this section, I will be able to use the C# programming language to create programs and use Visual Studio to create and manage them.

Step 1: we want to install visual studio. This is probably an IDE well known for its use in development management and application creation. we should always install the latest version for more features to use.

Figure : Visual studio code 2022 42

On the correct side, there are functions wont open files other folders or create to in new file

Open a project solution: or wont open the project within the default directory to that Visual studio had installed before.

Open a neighborhood folder: accustomed open a project you downloaded or open a project you saved in another folder.

Create a replacement: wont to create a replacement project.

We will learn the way make a project using the "create a brand new project" to function.

Figure : choose project 43

42 middle part will appear select tabs like which language, what operating system

to program in, and areas programming like IoT, web, winform, desktop, game, library in ...

In this section, we are going try and create a project using C # language to on the windows software package.

Console interface:

We enter a name, choose a folder save and choose the appropriate framework, and to press "create" to let the IDE create the workspace.

In this interface, the IDE will make the code available before it works.to us Figure 44:choose language

Figure 45: Project to name

We enter a name, choose a folder save and choose the appropriate to framework, and press "create" to let the IDE create the workspace.

In this interface, the IDE will make the code available before it works. to us Now we have a place to work. The first simple program we will do is print the Line "do quang trung " onto the screen:

Figure : Code program 46

2 Figure : Result 47

3.6 Evaluate how the debugging process can be used to help develop more secure, robust applications.(M4)

Introduction to Visual Studio Debugging

- The debugging process in visual studio is the debugging process in the program.

When programming errors are inevitable, when errors occur, programmers need to find a way to debug. Visual studio is the best place for programmers to fix errors and complete their programs.

Give a review of the debugging process in Visual Studio

- The debugger in visual studio has helped many programmers complete their projects well, debugging has many features as well as many shortcuts to help programmers save their time. In addition, fixing errors in visual studio has many errors, sometimes the debugging process is frozen and not running.

Advantages

- The debugger can help me schedule or change variables, code, or any other aspect of the runtime environment, while manual debugging requires me to stop, edit, and re- execute the application. application.

- The debugger can attach to a running process or use crash dump, while with manual debugging, error "reproduction steps" are necessary.

- Debuggers provide several techniques to decrease the time and repetitive labor involved in nearly every debugging activity.

- The visual debugger is integrated into the IDE it gives us easy access to smart editing and all the other capabilities found in the IDE. In a single integrated development environment.

- Both the visual debugger and the console debugger are helpful and share similar capabilities.

Disadvantages

-In fact, sometimes when the IDE debugger finishes fixing the error, it runs and gives incorrect results.

- Sometimes the IDE can't find some errors in the library.

- Syntax error occurs due to program syntax error, the program cannot be compiled.

Example of debugging in visual studio

The following problem is all about inheritance of salary, bonus and commission.

But got the following errors.

syntax error inheritance error

Figure 48: errors

4 When running the debug program, it reported 5 errors at line 11,23,29,30. So we need to fix it in order for the program to run.

Figure :Line shows error 49

I added GiamDoc class because ThuKy class inherits from GiamDoc class.

I added NhanVien class because BaoVe class inherits from NhanVien class.

I added a ; Enter for correct syntax. So I fixed the wrong types of this problem.Let's run the program and see if it works.

Figure : Debugging 50

This is the result of the problem running successfully after I fixed the error and tested.

Figure : Result 51

6 After completing this Exercise with your own efforts and with the help of friends and teachers. During the learning process, the teacher was very dedicated to teaching and always answered the questions that I posed, creating conditions for me to complete the exercises well.

Because I have presented very fully the questions that Assignment briefly raised, with clear examples, source code written by myself. I managed to complete the M part so I could get an M. Therefore, I am confident that I can self-study and can make software processes for businesses.

In addition, I have firmly grasped the basic knowledge of

programming, so I can definitely create software. Help many people and make life better!

CONCLUSION

After completing this report, the process of converting programming language to machine language, programming models such as linear programming, functional procedures, object-oriented and event-oriented programming, do exercises on What is model, compiler?. What is an IDE?, the features found in the IDE, the process of compiling and debugging programs.

Programming is really cool! Thanks to it, I understand how the devices around us work. This is very interesting and wonderful. Thank you my mentor!

Một phần của tài liệu Information technology assignment 2 unit programing (Trang 24 - 51)

Tải bản đầy đủ (PDF)

(51 trang)