Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

bài tập về môn lập trình C#, Exercises of Programming Languages

Assignments 1 of Programming 1618 project

Typology: Exercises

2020/2021

Uploaded on 11/09/2021

huynh-van-ngoan
huynh-van-ngoan 🇺🇸

4.4

(8)

26 documents

1 / 23

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1618-Programming Page | 1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Unit 1: Programming
Submission date
21/10/2021
Date Received 1st submission
Re-submission Date
Date Received 2nd submission
Student Name
Huynh Van Ngoan
Student ID
GCC200153
Class
GCC0902
Assessor name
Le Huynh Quoc Bao
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
Huynh Van Ngoan
Grading grid
P1
M1
D1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download bài tập về môn lập trình C# and more Exercises Programming Languages in PDF only on Docsity!

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Unit 1: Programming Submission date 21/10/2021 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Huynh Van Ngoan Student ID GCC Class GCC0902 Assessor name Le Huynh Quoc Bao 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 Huynh Van Ngoan Grading grid P1 M1 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

 - ASSIGNMENT 
    1. Scenario.
    1. State your simple business problems to be solved.
    • 2.1. definition of algorithms.
    • 2.2. characteristics of algorithm.
    • 2.3. The steps of building an application.
    • 2.4. State the problem.
    1. Analyze the problem and design the solutions by the use of suitable methods.
    • 3.1. Analyze the business problem
    • 3.2. Design the solution.
    1. Demonstrate the compilation and running of a program
    • 4.1. Demonstrate how the application is implemented
    • 4.2. The source code will be compiled and run in C# step by step the C# compiler.
    1. Evaluate how the problem is solved from the designed algorithm to the execution program.
    • 5.1. Test plan.
    • 5.2. Evaluate how the problem is solved from the designed algorithm to the execution program.
  • References
  • Figure 1: The first interface of the program. Table Of Figures
  • Figure 2: Enter choice
  • Figure 3: Enter the value of the variables.
  • Figure 4: Print results to the screen.
  • Figure 5: Enter choice 2.
  • Figure 6: Enter value for the radius variable.
  • Figure 7: Print results to the screen.
  • Figure 8: The user choice = 3.
  • Figure 9: Enter value for the variables.
  • Figure 10: Print the result after calculating to the screen.
  • Figure 11: Exit program.
  • Figure 12: Compilation process of C# code.

ASSIGNMENT 1

1. Scenario.

You have applied for a post as a trainee with a software development company and have been invited for an interview. You have been asked to demonstrate your problem solving and basic programming skills. To do this you have to prepare a report on using algorithms to solve problems. You need to explain, using examples, how algorithms are used to solve simple business problems and the steps needed to be followed to produce a working program solution. You should make clear your assumption about your program. The problems to be solved will involve basic procedural programming instructions - sequence instructions (input, output and assignment statements), loops, conditional statements. Problems should be analyzed and designed by the use of flowchart and demonstrated by the use of modules (procedures). ➢ Task:

  • State your simple business problems to be solved.
  • Analyse the problem and design the solutions by the use of suitable methods.
  • Demonstrate the compilation and running of a program Evaluate how the problem is solved from the designed algorithm to the execution program written by a specific programming language.

2. State your simple business problems to be solved.

2.1. definition of algorithms.

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing. It is formally a type of effective method in which a list of well-defined instructions for completing a task will, when given an initial state, proceed through a well-defined series of successive states, eventually terminating in an end-state. (Gupta, 2017)

2.2. characteristics of algorithm.

  • Input specified: The input is the information to be changed during the calculation to create the output. An algorithm ought to have at least 0 all around characterized inputs. Input exactness necessitates that you understand what sort of information, how much and what structure the information should be.

actual program. That means we write the program to solve the given problem using programming languages like C, C++, Java, Forex programming languages like our ( mt4 and/or mt5) language(s), etc.,

  • Testing and Debugging: During this phase, we check whether the code written in previous step is solving the specified problem or not. That means we test the program whether it is solving the problem for various input data values or not. We also test that whether it is providing the desired output or not.
  • Maintenance: During this phase, the program is actively used by the users. If any enhancements found in this phase, all the phases are to be repeated again to make the enhancements. That means in this phase, the solution (program) is used by the end user. If the user encounters any problem or wants any enhancement,then we need to repeat all the phases from the starting, so that the encountered problem is solved or enhancement is added. (mql5, 2005)

2.4.State the problem.

Algorithms can be used to solve many different problems in different fields. For example, I will apply an algorithm to write a selection menu that calculates the perimeter and area of rectangles, circles, and triangles. Choose the algorithm to solve this problem is the most efficient. Moreover, the algorithm is very simple to use for beginners like me. Using algorithms to solve this problem helps me get accurate results and saves me more time than solving the problem in the traditional way.

3. Analyze the problem and design the solutions by the use of suitable methods.

3.1.Analyze the business problem

The first step is to specify the input requirements and define the output requirements. The following two tables provide additional information:

  • Specify the required input: No. Variables Data type Describe 1 lenght float The length variable is used to store the length of the rectangle as the user enters it and is declared with the float data type. 2 width float The width variable is used to store the width of the rectangle as the user enters it and is declared with the float data type.

3 radius float The radius variable is used to store the radius of the circle as the user eters it and is declared with the float data type. 4 a float This variable is used to store the side of the triangle as the user enters it and is declared with the float data type 5 b float This variable is used to store the side of the triangle as the user enters it and is declared with the float data type 6 c float This variable is used to store the side of the triangle as the user enters it and is declared with the float data type

  • Specify output requirements: No. Variables Data type Describe 1 perimeter double The perimeter value of the program will be stored in this variable after the program completes. 2 area double The area value of the program will be stored in this variable after the program completes. 3 p double The half - perimeter value of the program will be stored in this variable after the program completes. Next, I will define the processing requests: The program I wrote is intended to solve problems with calculating the perimeter and area of rectangles, circles, and triangles. First, the program will display a menu and ask the user to enter an option. I used a do - while loop and an if - else conditional to fulfill the user's requests as follows:
  • If the user selects 1, the program will start asking the user to enter the length and width of the rectangle so that the program calculates the perimeter according to the formula (length + width) * 2 and the area according to the formula (length * width) of the rectangle and print it to the screen.
  • If the user chooses the number 2, the program will ask the user to enter the radius of the circle so that the program calculates the circumference according to the formula (2 * radius * PI) and the area according to the formula (radius * radius * PI) of the circle and then print it to the screen.
  • If the user chooses the number 3, the program will ask the user to enter the 3 sides of the triangle and the program will check if ((a + b) > c) && ((b + c) > a) && ( ( ( a) + c) > b) then the program will calculate the perimeter of the triangle according to the formula (a + b + c) and then calculate the

4. Demonstrate the compilation and running of a program

4.1. Demonstrate how the application is implemented

  • Source code of the program: using System; namespace ASM { class Program { static void Main(string[] args) {

int choice = 0; do { Console.WriteLine("Program Menu Choice Calculates Perimeter And Area Of Geometry."); Console.WriteLine("===================================Menu============================") ; Console.WriteLine("1. Calculate the perimeter and area of the rectangle."); Console.WriteLine("2. Calculate the perimeter and area of a circle."); Console.WriteLine("3. Calculate the perimeter and area of the triangle."); Console.WriteLine("4. Exited."); Console.WriteLine("==================================================================="); Console.Write("Please, enter your Choice: "); choice = int.Parse(Console.ReadLine()); double perimeter = 0; double area = 0; if (choice == 1) { Console.Write("Enter the legnth of the rectangle: "); float legnth = float.Parse(Console.ReadLine()); Console.Write("Enter the width of the rectangle: "); float width = float.Parse(Console.ReadLine()); if (legnth > 0 && width > 0) { perimeter = (legnth + width) * 2; area = legnth * width; Console.WriteLine("The perimeter of the rectangle is: {0:F2}", perimeter); Console.WriteLine("The area of the rectangle is: {0:F2}", area); Console.WriteLine(" "); } else { Console.WriteLine("Please, enter legnth and width must be greater than 0."); Console.WriteLine(" "); } } else if (choice == 2) { Console.Write("Enter circle radius: "); float radius = float.Parse(Console.ReadLine()); if (radius > 0) { perimeter = 2 * radius * Math.PI; area = radius * radius * Math.PI; Console.WriteLine("The perimeter of the circle is: {0:F2}", perimeter); Console.WriteLine("The area of the circle is: {0:F2}", area); Console.WriteLine(" "); } else

  • Screenshots of the program: This is the first interface that the user encounters when launching the program. The user must enter the selection into the program: Figure 1 : The first interface of the program. After the user choice = 1 : Figure 2 : Enter choice 1

The user has to enter values in the length and width variables of the rectangle: Figure 3 : Enter the value of the variables. After entering the values of 2 variables, the program will print the results to the screen: Figure 4 : Print results to the screen. The user choice = 2:

Figure 8 : The user choice = 3. Requires the user to enter values into the variables: Figure 9 : Enter value for the variables. After entering the values of the variables, the program will print the results to the screen:

Figure 10 : Print the result after calculating to the screen. When the user choice = 4: Figure 11 : Exit program.

4.2. The source code will be compiled and run in C# step by step the C# compiler.

The source code will be compiled and run in C# step by step the C# compiler: Step 1: Write a C# code.

Step 7: Now, the C# compiler returns the output of the given c# code. Figure 12 : Compilation process of C# code. (argha_c14, 2021)

5. Evaluate how the problem is solved from the designed algorithm to the execution program.

5.1.Test plan.

No. Test case^ Function^ Input Data^ Expected output Actual output (^) Result 1 The results of calculating the perimeter and area of the rectangle will be displayed on the screen when the user enters the value of a valid length and width. Calculate the perimeter and area of the rectangle. Enter the length : 3 Enter the width: 4 Display message “The perimeter of the rectangle is: 14,00” and “The area of the rectangle is: 12,00” Display message “The perimeter of the rectangle is: 14,00” and “The area of the rectangle is: 12,00” Passed 2 Verify that “Please, enter the legnth and the width must be greater than 0.” When the user enters number of Calculate the perimeter and area of the rectangle. Enter the length : 0 Enter the width: - 1 Display error message “Please, enter the legnth and the width must be greater than 0.” Display message “Please, enter the legnth and the width must be greater than 0.” Passed

student with negative number. 3 Verify that “Please, enter the legnth and the width must be greater than 0.” When the user enters characters. Calculate the perimeter and area of the rectangle. Enter the length : a Enter the width: b Display error message “Please, enter the legnth and the width must be greater than 0.” The program is error. Failed 4 The results of calculating the perimeter and area of the circle will be displayed on the screen when the user enters the value of a valid radius. Calculate the perimeter and area of the circle. Enter the radius: 2 Display message “The perimeter of the circle is: 12,57.” and “The area of the circle is: 12,57.” Display message “The perimeter of the circle is: 12,57.” and “The area of the circle is: 12,57.” Passed 5 Verify that “Please, enter the radius must be greater than 0.” When the user enters number of student with negative number. Calculate the perimeter and area of the circle. Enter the radius: - 2 Display error message “Please, enter the radius must be greater than 0.” Display error message “Please, enter the radius must be greater than 0.” Passed 6 Verify that “Please, enter the radius must be greater than 0.” When the user enters characters. Calculate the perimeter and area of the circle. Enter the radius: c Display error message “Please, enter the radius must be greater than 0.” The program is error. Failed 7 The results of calculating the perimeter and area of the triangle will be displayed on the screen when the user enters the Calculate the perimeter and area of the triangle. Enter edge a: 3 Enter edge b: 4 Enter edge c: 5 Display message “The half – perimeter of the triangle is: 6,00.” and “The perimeter of the triangle is: 12,00.” and “The area of the Display message “The half – perimeter of the triangle is: 6,00.” and “The perimeter of the triangle is: 12,00.” and “The area of the Passed