Download Lap Trinh co ban programing and more Exercises Tribology 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name NGUYEN VU CUONG Student ID BH Class SE06302 Assessor name HA NGOC LINH 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 Cuong Grading grid P1 P2 M1 D
Lecturer Signature:
Contents
- I. Introduction
- II. Content
- Define basic algorithms to carry out an operation and outline the process of programming an application.....
- 1.2 Characteristics of algorithm.
- 1 Criteria to measure a good algorithm.
- 2 Application development steps..........................................................................................................................
- 3 Steps in program development.
- Steps to use Visual studio to create 1 project, write code, until the program runs
- Divide the problem.
- a. Problem Definition
- b. Divide the problem.
- c. Program menu
- d. Functional analysis
- III. Conclusion
- IV. Reference List..................................................................................................................................................
- Figure Figure
- Figure
- Figure
- Figure
- Figure
- Figure
1.2 Characteristics of algorithm.
- There are five important characteristics of an algorithm that should be considered while designing any algorithm for any problem:
- Finiteness: An algorithm should terminate infinite number of steps and each step must finish in finite amount of time.
- Definiteness: Each step of algorithm should be clearly and precise define and there should not be any ambiguity. ▪ Example: A program fragment is given below: o X →1. Toss a coin, if result is head then X →3 else x→4. In the above program, all the steps would be carried out effectively but there is no definiteness since there are two possible values of X 1 and ¾.
- Inputs: An algorithm must have zero or more but must be finite number of inputs. Example of zero input algorithm. Print the ASCII code of each of the letter in the alphabet of computer system.
- Output: An algorithm must have at-least one desirable outcome o Effectiveness: An algorithm should be effective. Effective means that each step should be referred as principle and should be executing in finite time. Example: Cook perfectly fluffy rice: Figure 2
Figure^6 3 1 Criteria to measure a good algorithm. Good algorithm is one type of algorithm for solving a problem from a specific case.
- A good algorithm has these criteria:
- Input: There are zero or more quantities which are externally supplied;
- Output: at least one quantity is produced;
- Definiteness: Each instruction must be clear and unambiguous;
- Finiteness: If we trace out the instructions of an algorithm, then for all cases the algorithm will terminate after a finite number of steps;
- Effectiveness: Ever instruction must be sufficiently basic that its principle be carried out by a person using only pencil and paper.
- Execution time: An algorithm may have good time efficiency but bad space efficiency or an algorithm may have good space efficiency but bad time efficiency. Time efficiency is the time that the algorithm requires to solve a problem and size/space efficiency is the memory size (allocated for variables) that the algorithm requires solve the given problem. (Adhikari, 2018)
- Size of input data: Generally, algorithms are efficient when small inputs are given, but their efficiency gradually decreases when the size of input is increased. For evaluating the efficiency of your algorithm, you must check the time required for processing by your algorithm for different size of inputs given. (Chandel, 2017)
- It is not enough for any kind of problem, but it must also be making an algorithm become good.
- Example: Find factorial number.
- Input: Positive integer number.
- Output: Factorial of that number.
- Process: Solution technique which transforms input to output. Factory of a number can be calculated by the formula n!=123…n
2 Application development steps
Testing & 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.
3 Steps in program development.
✓ Program development is the process of creating application programs. Program development life cycle (PDLC) The process containing the five phases of program development: analyzing, designing, coding, debugging and testing, and implementing and maintaining application software. The following are six steps in the Program Development Life Cycle:
1. Analyze the problem The computer user must figure out the problem, then decide how to resolve the problem - choose a program. 2. Design the program A flow chart is important to use during this step of the PDLC. This is a visual diagram of the flow containing the program. This step will help you break down the problem. 3. Code the program This is using the language of programming to write the lines of code. The code is called the listing or the source code. The computer user will run an object code for this step. 4. Debug the program The computer user must debug. This is the process of finding the "bugs" on the computer. The bugs are important to find because this is known as errors in a program. 5. Formalize the solution One must run the program to make sure there are no syntax and logic errors. Syntax are grammatical errors and logic errors are incorrect results. 6. Document and maintain the program This step is the final step of gathering everything together. Internal documentation is involved in this step because it explains the reasoning one might have made a change in the program or how to write a program. Potential Challenges
Writing code can be challenging due to various reasons. Here are some potential challenges that you may face:
- Complexity of the Problem: Some problems can be inherently complex, requiring a deep understanding of algorithms and data structures. It may take time and effort to come up with an effective solution.
- Technical Limitations: Depending on the programming language or platform you are using, you may encounter technical limitations or constraints that make the coding process more challenging. This could include memory limitations, performance issues, or compatibility problems.
- Debugging and Troubleshooting: Finding and fixing bugs can be time-consuming and frustrating. It requires a systematic approach, good debugging skills, and the ability to think critically and analytically.
- Learning Curve: If you are new to programming or using a new programming language or framework, there may be a steep learning curve. Understanding the syntax, libraries, and best practices can take time and effort.
- Collaboration and Communication: When working on a team or collaborating with others, communication and coordination can be challenging. It is important to effectively communicate ideas, share code, and resolve conflicts or differences in coding styles.
- Time Management: Writing code can be time-consuming, especially when dealing with complex problems or large codebases. Managing your time effectively and breaking down the tasks into manageable chunks is crucial.
- Maintenance and Updates: Code needs to be maintained and updated over time. This can involve fixing bugs, adding new features, or adapting to changes in requirements or technologies. It is important to write code that is modular, reusable, and easy to maintain. By being aware of these potential challenges and following a systematic approach, you can overcome them and become a more proficient coder.
4. Steps to use Visual studio to create 1 project, write code, until the program runs
Creating a new app Open a new project: Open Visual Studio Code. Click on the Explorer icon in the left menu and click Open Folder. Select the folder you want to store the C# project. In this case, a new folder named HelloWorld should be created and selected.
Initialize C# project: Open the integrated terminal in Visual Studio Code by selecting View > Integrated Terminal from the main menu. In the Terminal window that appears, enter the command dotnet new console. This command will create a Program.cs file into the selected folder, in that file contains the program "Hello World"; At the same time is a C# project file named HelloWorld.csproj. The source code:
Using Directive: From line 1 to 5, we have a few statements that start with the word using. These statements are known as directives. They tell the compiler that our program uses a certain namespace For instance, the first line using System; tells the compiler that our program uses the System namespace. Namespace: A namespace is simply a grouping of related code elements. These elements include classes, interfaces, enums and structs etc C# comes with a large amount of pre-written code that are organised into different namespaces. The System namespace contains code for methods that allow us to interact with our users. We use two of these methods in our program
- the WriteLine() and Read() methods. Class declaration Every app consists of at least one class declaration that defined by the programmer
- user-defined class
Formatting Text Displaying Output
- Most applications require some input from the user and give output as a result. To display text to the console window you use the Console.Write or Console.WriteLine methods.
- The difference between these two is that Console.WriteLine is followed by a line terminator, which moves the cursor to the next line after the text output.
- The program below will display Hello World! to the console window: User Input You can also prompt the user to enter data and then use the Console.ReadLine method to assign the input to a string variable. The following example asks the user for a name and then displays a message that includes the input: Figure 5
User Input
- The Console.ReadLine() method returns a string value. If you are expecting another type of value (such as int or double), the entered data must be converted to that type.
- This can be done using the Convert.ToXXX methods, where XXX is the .NET name of the type that we want to convert to. For example, methods include Convert.ToDouble and Convert.ToBoolean.
- For integer conversion, there are three alternatives available based on the bit size of the integer: Convert.ToInt16, Convert.ToInt32 and Convert.ToInt64. The default int type in C# is 32-bit. Read the input
- For standard input we use Console.ReadLine() String s = Console.ReadLine(); int n = Convert.ToInt32(Console.ReadLine()); Possible erroneous input User can input a string which is not an integer In this case an Exception is raised
- We will learn about handling exception later.
5. Divide the problem.
a. Problem Definition Create a program to calculate water bills: the program allows entering the number of members to distinguish between households and other subjects and then calculates the electricity bill based on that subject's number of m3. b. Divide the problem. Application code on demand with 1 of the following features: Arrange, find customers, create invoices to notify customers and pay fees c. Program menu
- customer name
- object type Figure 6
Case3: Water bill needs to be paid Case4 : Water bill needs to be paid Default exit end infinite loop
III. Conclusion
The above essay has introduced the concept of algorithms, functions, why they are important in programming The advantages of programming algorithms include: A stepwise representation of a solution to a given problem, making it easy to understand. Uses a definite procedure. Not dependent on a particular programming language. Every step in an algorithm has its own logical sequence, making it easy to debug. The algorithm has solved the problem of calculating water bills in a simpler, easier way to catch
Flowchart