Write a program that implements an algorithm using an [DE

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

write a program that input is a simple calculator that calculates calculations such as addition, subtraction, multiplication, and division

I set the input to enter the numbers A and B I designed the calculations as follows:

Addition, subtraction, multiplication, division I designed the button to be the exit button

I write code for delete button when clicking delete button it will refresh and empty the fields where the input names are numbers A and B

with addition of numbers a + b = sum of 2 numbers , subtraction a - b = quotient of 2 numbers , multiplication a * b = product , division a /b = quotient of 2 numbers Here is the design of the simple calculator

Step 1 : Create a new project.

14

PERFOMED STUDENT: PHAN QUANG HOP

Configure your new project

Console App (.NET Framework) pea

€onsoleApp12|

Tere ry AN

Solution name

ne directory

Figure 12 Create a new project Step 2 : Create a new class.

Add New Item - ConsoleApp12 ? x

4 Installed Sort by: Default

4 Visual C# Items oy : Visual Cẽ Iteme Type: Visual C# ltems

betel ss ° A blank Windows Forms (WinForms) Form

Data Ty Class for U-SQL Visual C# Items

General

Web Interface Visual C# Items

Windows Forms

WPF Form (Windows Forms) Visual C# Items

ASP.NET Core

SQL Server User Control (Windows Forms) fisual C# Items Storm Items

coo Component Class Visual C# Items

AT, Eee) Visual C£ ltc

About Bc 910013 Visual C# Items ADO.NET Entity Data el Visual C# Items

Application Configuration File Mitr RO aC

Name:

Cancel

Figure 13 Create a new class.

Step 3 code and design

15

PERFOMED STUDENT: PHAN QUANG HOP

Figure 14 computer design Here is the code of a simple calculator

33 34 35 36 37 38 39 41

42 43 du 5 46 47 48 49

59 51 52 53 54

1 reference

private void button5_Click(object sender, EventArgs e) int a = int.Parse(txt_soa.Text);

int b = int.Parse(txt_sob. Text);

int tong = a + b;

txt_ketqua.Text = tong.ToString();

}

1 reference

private void txt_tru_Click(object sender, EventArgs e) {

int a = int.Parse(txt_soa.Text);

int b = int.Parse(txt_sob.Text);

int tru = a - b;

txt_ketqua.Text = tru.ToString();

}

1 reference

private void txt_nhan_Click(object sender, EventArgs e) double a = double.Parse(txt_soa. Text);

double b = double.Parse(txt_sob. Text);

double nhan = a * b;

= _ ms . +* ~

16

55 56 57 58 59 68 61 62 63 65 66 67 68 69 79 T1 72 73 7

18 11 12 13 14 15 16 17 18

: “BTEC

‘BTEC —-88—

txt_ketqua.Text = nhan.ToString();

1 reference

private void txt_chia_Click(object sender, EventArgs e) double a = double.Parse(txt_soa. Text);

double b = double.Parse(txt_sob. Text);

if (b < 9)

Console.WriteLine("enter the wrong number");

else

Console.WriteLine(a / b);

if (a < 0)

Console.WriteLine("enter the wrong number");

else

Console.WriteLine (b / a);

1 reference

private void txt_delete_Click(object sender, EventArgs e) txt_ketqua.Text = "";

txt_soa.Text = "";

txt_sob.Text = "

txt_cong. Text txt_chia.Text txt_nhan. Text ; txt_tru.Text = "";

Figure 15 computer code Einamespace chuongtinhcong

{

| O references

5 internal class Program {

a static void Main(string[] args) {

Application.Run(new chuongtrinh());

| }

q

Figure 16 code to run the program

17

PERFOMED STUDENT: PHAN QUANG HOP

BTEC =a

Step 4: run the program

a2 chuongtrinh _ n x

Input A ° Inpu B `

Uotput 1

+ | - | * / | Delete

Figure 17 run the program with addition

a chuongtrinh — oO x

Input A ° Inpu B , Uotput 12

- | * | / | Delete

Figure 18 we run the program with addition

18

‘BTEC sabe

88 chuongtrinh — Oo x

Figure 19 multiplication

19

PERFOMED STUDENT: PHAN QUANG HOP

'BTEC ===

CHAPTER 3. Define the debugging process and explain the importance of standardization (P4)

3.1 explain the debugging process and explain the debugging facilities available in the IDE

Debug definition - Definition Debugging.

Debugging is the process of identifying and fixing bugs (defects or issues that inhibit the proper operation of computer programs, software, or systems) in computer programming and software development.

Debugging Process Step 1 find the error

Step 2 find the cause of the error, syntax error, declaration error, al gorithm error...

Step 3 error handling Step 4 run test and check For example

20 PERFOMED STUDENT: PHAN QUANG HOP

1 reference

30 B private void search_CLick(object sender, EventArgs e)

31 {

32 ! if (RDB2.Checked)

33 {

34 35 | int a = int.Parse(txt_number1. Text)

36 int b = int.Parse(txt_number2. Text);

37 |] if a > b)

38 txt_ketqua.Text = a.ToString();

39 else

d9 txt_ketqua.Text = b.ToString();

41

2 else

42 43 ay

45 d6 |] int a = int.Pars(txt_number1.Text);

t7 int b = int.Parse(txt_number2. Text);

d8 int c = int.Parse(txt_number3.Text);

49 if (a>b &&a>c)

50 txt_ketqua.Text = a.ToString();

51 else if (b> a && b > c)

52 =

53

txt_ketqua.Text = b.ToString();

else

Ta Tar lan a ae a

54 txt_ketqua.Text = c.ToString();

55 | }

56 | }

57

1 reference

58 a private void button2_Click(object sender, EventArgs e) 59

68 txt_ketqua.Text = "";

61 |] txt_nunber1.Text = "" -

62 txt_number2.Text = "";

63 txt_number3.Text = "";

64

65 | }

66

1 reference

67 B private void RDB2_CheckedChanged(object sender, EventArgs e)

68 {

69 if (RDB2.Checked)

7e | txt_number3.Visible= fale;

71

72 | }

73

1 reference

™m™ E private void RBD3_CheckedChanged(object sender, EventArgs e) 75

PERFOMED STUDENT: PHAN QUANG HOP

21

1 refe

74 el mielvaess void RBD3_CheckedChanged(object sender, EventArgs e)

75 {

76 if (RBD3.Checked)

77@/] txt_number3.Visible = trp;

78 }

79 }

80

81 }

82

Figure 20 code

™ Code — Description Project Fille Line Suppression State

@ csi002 ; expected max uotput.cs 35 Active

@ 51002 Syntax error, '( expected max uotput.cs 7 Active

@ 51002 ; expected max uotput.cs 61 Active

© CS0117 ‘int’ does not contain a definition for ‘Pars max uetput.cs 46 Active

@ C50103 The name ‘fele’ does not exist in the current context max uotput.cs TÔ Acbve

€@ C0103 The name ‘tre’ does not evist in the current context max uotput.cs TT Active

Figure 21 Bug

Line 35 syntax error line 46 undefined variables Line 61 syntax error Line 70 formatting error Line 77 formatting error

ba To prevent possible data loss before loading the designer, the following errors must be resolved:

@ The designer cannot process unknown name ‘textBox4_TextChanged' at line 177. The code within the method ‘InitializeComponent’ @& Soto (a) is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again. ~ code

Instances of this error (1)

1. timsolonnhat uotput.Designer.cs Line:177 Column:1 Show Call Stack Help with this error

Could not find an associated help topic for this error. Check Windows Forms Design-Time error list Forum posts about this error

Search the MSDN Forums for posts related to this error

Figure 22 cell error showing results

22

PERFOMED STUDENT: PHAN QUANG HOP

‘BTEC see

Ignore and Continue

x) The designer cannot process unknown name ‘label1_Click’ at line 84. The code within the method it’ is generated 3 ae ^

za

"InitializeComponeni by the designer and should not be manually modified. Please remove any changes and try opening the designer again.

Instances of this error (1)

1. timsolonnhat uotput.Designer.cs Line:84 Column:1 Show Call Stack Help with this error

Could not find an associated help topic for this error. Ch indows Form: ign-Time error li Forum posts about this error

Search the MSDN Forums for posts related to this error

Figure 23 error name click 1

SỬ uotput _ n x

Input SEARCH

Number 1 ‘ = Max 2

ô Max 3 Number 2 °

Number 3 Po Uotput fo

SEARCH Delete | Exit

Figure 24 After fixing the error, run normally

23 PERFOMED STUDENT: PHAN QUANG HOP

‘BTEC en

CHAPTER 4 integrates many programs like code completion, compiler editor outlining the coding standard you used in your code

(P5)

I write a program that uses programming standards such as variable naming, standard function naming, and object naming, et cetera

+ In Winfom, there are a few different methods to name objects:

(OBJECT NAME SET NAME FOR OBJECT EXAMPLE

Button btn btnHome

Check Box chk chkGender

Data View dvw dvwlnforStudent

Form frm frmLogin

Label Il IbINameUser

Link Label lIbl llblF acebook

List View |Svw IsvwlnforStudent

Numeric Up nud nudHour

Down

Picture Box pic picLogo

Scroll Bar sbr sbrTable

Tab Control tab tabDesign

Textbox txt txtPassword

— tear nan

Figure 9 standard versions of encryption Avoid giving your variables numerical names.

The name of this function is:

- When describing its function must be concise.

Capitalize the first two letters.

Indent

- Each subcommand within a block must be indented, making it easier to understand the source code.

24 PERFOMED STUDENT: PHAN QUANG HOP

‘BTEC

‘BTEC ae

- The straight column must be made of an open brace and a closed brace.

Avoid using confusing code wherever you can and keep the length of the functions to a minimum.

We will create a program to find the largest number between 2 numbers, and the largest number between 3 numbers.

Users can calculate faster.

Input SEARCH

Number 1 O Max 2

O Max 3 Number 2

Number 3 | Uotput

SEARCH Delete Exit

Figure 25 design

25

PERFOMED STUDENT: PHAN QUANG HOP

‘BTEC

BTEC =

FIND THE BIGGEST NUMBER -

Input SEARCH

Number 1 ° © Max 2

Đ ô Max 3

Number 2

8 8

Number 3 Uotput

SEARCH Delete | Exit |

Figure 26 find the largest number among three numbers

— n x

Input SEARCH

Number1 ẽ ô Max 2

§ © Max 3

Number 2

Number 3 Uotput °

SEARCH Delete | Exit |

a uotput

{

|

Figure 27 find the largest number between 2 numbers

synthesizes coding programs and compilers and applies many programming standards

for example :

26 PERFOMED STUDENT: PHAN QUANG HOP

š SBTEC

‘BTEC on mn

txt number3 ŠSystem.Windows.Forr x

(BE) [els #

© Design +

(Name) txt number3

GenerateMemb: True Locked False Modifiers Private H Focus

Hee re=reMơslialơei—i Toren

Figure 28 use standard function naming for example :

RBD3 System.Windows.Forms.Radio x

ee] DI.

Tag ^

© Design

(Name) RBD3

GenerateMemb: True

Locked False

Modifiers Private .

mĩ Career

Text

The text associated with the control.

Figure 29 using variable names

27

PERFOMED STUDENT: PHAN QUANG HOP

F BTEC

“BTEC oe

CHAPTER 4 M2 Analyze the common features that a developer has access to in an IDE.

IDE (Integrated Development Environment) is an integrated environment used to write code to develop applications. In addition, the IDE integrates other support tools such as compiler, interpreter, error checker (Debugger), format or highlight code, organize code folders, search code ...

IDE makes it easier and more convenient for you to develop applications, even though you don't need an IDE, you can still write source code, because actually to run the source code of a certain programming language, we just need the corresponding compiler (compiler) of that language.

Analysis of the common characteristics of the IDE:

Figure 30 some IDEs

A word processing program is a type of software designed to edit electronic documents with some main functions as follows:

Display text content on screen

Allows users to modify and supplement at any position in the document Display many different font styles (fonts), font sizes, colors

Images can be included in the text

28 PERFOMED STUDENT: PHAN QUANG HOP

° ‘BTEC we

Save text as a file Text printing support Has a photo collage function

There are many different word processing programs available. In terms of commercial software, the most famous is Microsoft Word that comes with Microsoft's Microsoft Office suite

internal class Program

static void Main(string[] args) int a, bj;

double x;

Console.WriteLine(" a ");

string st = Console.ReadLine();

a = int.Parse(st);

Console.WriteLine(" b ");

st = Console.ReadLine();

b = int.Parse(st);

Console.WriteLine("\n first degree equation {0}x +{1} =O ,", a,b);

if (a == 6) {

if (b == 9) {

Console.WriteLine("\n The equation has infinitely many solutions.");

else {

x = (doubte)-b / a;

Console.WriteLine("\n valid equation x = {0}", Math.Round(x, 2));

} Console.Read();

Figure 31 text editor example Debugger, Compiler:

29

PERFOMED STUDENT: PHAN QUANG HOP

26¢% []E if (a ==9_

27 {

28 =] if (b == 0)

{

36 |] Console.WriteLine("\n The equation has infinitely many solutions.");

34 =| else

35 {

36 x = (double)-b / a;

37 ] Console.WriteLine("\n valid equation x = {0}", Mat.Round(x, 2));

38 }

39 }

q6 Í] Console.Read()

mesue. — -I(Ð2mmsljAshengjl@eMems= T]

™ Code Description Project File Line Suppression State

@ cs1026 ) expected phuongtinhbacnhat Program.cs 25 Active

€ CS1002 ; expected phuengtinhbacnhet Program.cs 43 AcEve

€9 C50103 The neme ‘Mat’ does not exist in the current context phuongtinhbacnhat Program.cs 37 Active

Figure 32 debug example, compiler Visual studio helps us detect the error on line 26 which is a structural error Line 37 is wrong structure

Line 43 is missing the sign

- Complete the code and proceed to run the program

7 =|namespace phuongtinhbacnhat 8

9 E internal class Program

10 {

11 E static void Main(string[] args) 12

13 int a, b;

14 double x;

15

16 || Console.WriteLine(" a ");

17 string st = Console.ReadLine();

18 a = int.Parse(st);

19

2e Í] Console.WriteLine(" b ");

21 st = Console.ReadLine();

22 b = int.Parse(st);

23

24 Console.WriteLine("\n first degree equation {0}x +{1} =O ,", a,b);

25

26 (je if (a == 0)

30

PERFOMED STUDENT: PHAN QUANG HOP

‘BTEC

26 if (a == 0)

27 {

28 = if (b == 0)

29 {

30 Console.WriteLine(" The equation has infinitely many solutions.");

}

else

36 x = (double)-b / a;

37 Console.WriteLine(" valid equation x = {6}", Math.Round(x, 2));

38 }

_ }

t8 Console.Read();

Figure 33 code completion

# ˆ D:\code\phuongtinhbacnhat\phuongtinhbacnhat\bin\Debug\phuongtinhbacnhat.exe

Figure 34 run the program

Microsoft Visual Studio 2022 Supported Languages Introduction to Visual Studio

An effective website programming support tool is Visual Studio. Microsoft, a large company in the technology sector, developed and owns this product. The programming tool's new codename in 1997 was Project Boston. The development tools are then repackaged by Microsoft into a single solution.

The system that integrates a code editor, designer, and debugger for application development is called Visual Studio. In other words, using just one Visual Studio program,

31

PERFOMED STUDENT: PHAN QUANG HOP

3 SBTEC

‘BTEC on mn

you can easily develop code, fix bugs, and update application design. In addition, users can create user interfaces and experiences in Visual Studio, just like when creating Xamarin, Blend or UWP apps using XAML.

Visual Studio

Figure 35 Visual studio

PERFOMED STUDENT: PHAN QUANG HOP

32

eee ‘BTEC a

CRITICAL EVALUATION

After this assignment | help me understand programming, how to write an al gorithm for a problem. After each lesson, I absorbed about 85% of the lesson content that the teacher taught. above is my assignment 1. I researched content from teachers, friends, and some I searched online to make my final report. I self-assessed my work about 90% correct content and was able to get an M on this assignment.

33 PERFOMED STUDENT: PHAN QUANG HOP

‘BTEC a

CONCLUSION

After completing this report, I understood and grasped how to build a basic algorithm, the process to execute a program, the life cycle of an algorithm, how to draw a flow chart to explain How does the algorithm work?

Programming is really amazing! thanks to it I understand how the devices around us work.

This is very interesting and fantastic. Thankyou my Mentor!

34 PERFOMED STUDENT: PHAN QUANG HOP

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

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

(45 trang)