















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
Assignments 1 of Programming 1618 project
Typology: Exercises
1 / 23
This page cannot be seen from the preview
Don't miss anything!
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
Grade: Assessor Signature: Date: Lecturer Signature:
- ASSIGNMENT
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:
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)
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.,
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.
The first step is to specify the input requirements and define the output requirements. The following two tables provide additional information:
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
4. Demonstrate the compilation and running of a program
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
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.
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.
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