Algorithms and Programming: Solving Linear and Quadratic Equations, Study Guides, Projects, Research of Law

An overview of algorithms and programming, focusing on the implementation of algorithms to solve linear and quadratic equations. It covers the definition of algorithms, their step-by-step nature, and how they are used in computer programming. The document then delves into a practical example of cooking rice, demonstrating the step-by-step nature of algorithms. It also discusses the various stages of program development, including requirements analysis, architectural design, coding, testing, and maintenance. The document then presents a program that allows the user to select options to solve linear and quadratic equations, providing detailed explanations of the underlying algorithms and their implementation. Overall, this document serves as a comprehensive guide to understanding algorithms, their role in programming, and their practical applications in solving mathematical problems.

Typology: Study Guides, Projects, Research

2022/2023

Uploaded on 07/17/2023

unknown user
unknown user 🇻🇳

1 document

1 / 27

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
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 Student ID
Class Assessor name Ngo Thi Mai Loan
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
Grading grid
P1 M1 D1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b

Partial preview of the text

Download Algorithms and Programming: Solving Linear and Quadratic Equations and more Study Guides, Projects, Research Law 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 Student ID Class Assessor name Ngo Thi Mai Loan 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 Grading grid P1 M1 D

❒ Summative Feedback: ❒ Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

  • A. Introduction............................................................................................................................................................
  • B. Content....................................................................................................................................................................
    • I. Algorithm..............................................................................................................................................................
        1. Definition
      • 2 Algorithm characteristics
        1. Algorithm example
    • II. Steps in program development...........................................................................................................................
      • 1.Requirement’s analysis:
        1. Design:
        1. Documentation:
        1. Compiling and running the program:
        1. Testing:
      • 7.Maintenance:
    • III. Solve problems using algorithms......................................................................................................................
        1. Content of the problem
        1. Problem analysis
        1. Program menu
        1. Functional analysis
        1. Functions
        1. Program Execution
  • C. Conclusion.............................................................................................................................................................
  • D. References............................................................................................................................................................
  • Figure 1: Algorithm Definition..................................................................................................................................... TABLE OF FIGURE
  • Figure 2. Algorithm characteristics..............................................................................................................................
  • Figure 3: Step 1 of cooking rice....................................................................................................................................
  • Figure 4: Step 2 of cooking rice....................................................................................................................................
  • Figure 5: Step 3 of cooking rice....................................................................................................................................
  • Figure 6: Step 4 of cooking rice....................................................................................................................................
  • Figure 7: Step 5 of cooking rice....................................................................................................................................
  • Figure 8:Flowchart of the area of a rectangle..............................................................................................................
  • Figure 9. Steps in program development.....................................................................................................................
  • Figure 10: Program menu..........................................................................................................................................
  • Figure 11:Flowchart for solving linear equation........................................................................................................
  • Figure 12:Solving for quadratic equation...................................................................................................................
  • Figure 13: Solving for linear equation........................................................................................................................
  • Figure 14: Solving for quadratic equation..................................................................................................................
  • Figure 15: Menu structure function...........................................................................................................................
  • Figure 16: The menu results are displayed on the screen.........................................................................................
  • Figure 17:Option 1 results are displayed on the screen............................................................................................
  • Figure 18: Option 2 results are displayed on the screen............................................................................................

A. Introduction Writing computer code to develop a program or solve an issue is referred to as programming. Algorithms are implemented using programs. Algorithms can be expressed as pseudocode or flowcharts, and programming is the process of converting them into computer programs. To instruct a computer, a program must be designed that specifies what to do and how to accomplish it. If an algorithm has been created, the computer program will follow it step by step, telling the machine exactly what to do. Programming is really about problem solving. It entails breaking difficult issues down into smaller, more manageable chunks and creating solutions to them. Programmers evaluate issues, create algorithms, and transform them into computer code. There are many programming languages available, each with its own syntax and purpose. These languages serve different purposes and are used in different fields, such as web development, data analysis, and game development. I will introduce this in Assignment 1.

2. Algorithm characteristics An algorithm has the following characteristics:

Figure 2. Algorithm characteristics

1. Finiteness: An algorithm must terminate after a limited number of steps. 2. Unambiguous: An algorithm must be precisely defined; each step should be clear and their inputs, outputs must lead to only one meaning. 3. Input: An algorithm should have zero or more well-defined inputs which are given to it initially before the algorithm begins. 4. Output: An algorithm should have one or more well-defined outputs and should match the desired output.

5. Effectiveness: All of the operations to be executed in the algorithm should be realizable that they can be done exactly in a limited length of time. 3. Algorithm example Practical example: Cooking rice a. Step 1: Measure the rice and put into cooking pot

Figure 5: Step 3 of cooking rice....................................................................................................................................

b. Step 2: Rinse the rice

e. Step 5: Fluff and serve

Figure 7 : Step 5 of cooking rice

Algorithm example in math: Find the area of a rectangle.

Figure 8:Flowchart of the area of a rectangle..............................................................................................................

Figure 9. Steps in program development.....................................................................................................................

The various stages in the development of a computer program are :

  1. Problem Definition
  2. Program Design
  3. Coding
  4. Debugging
  5. Testing
  6. Documentation
  7. Maintenance

Figure 9. Steps in program development

+Complete input and outputs for a module. It is very important that the module designed is appropriate with the other modules in the system construction and the other external systems. The unit tests can be developed in this stage based on the internal module designs. 3.Coding: All of the module’s design is convert into code by the developers in this step. The most suitable programming language is decided according to the system and architecture requirements. The coding is implemented based on the coding guidelines and standards. The code is went through numerous code reviews and finally optimized for the best performance. Unit testing is executed by the developers on the code written by them.

4. Documentation: -It’s very importance for developers to write technical documentation precisely. The code documents which is a part of source code (include README files or API documentation) or includes reference manuals, algorithm descriptions, flowcharts. Documentation is very helpful for development, maintenance, and knowledge transfer to other developers. It must be detailed but not verbose. Because if the documentation is lengthy, it would become very time-consuming to read or difficult to maintain them. 5. Compiling and running the program: -When developers create a program, they first write the program in source code form which is written in a specific programming language. Those code files in a text form that can be opened and edited by developers. Because the source code can’t be performance directly by computers. So, it must be converted from source code into machine code for computer can understand, this process is called “Compiling”. -Execution in computer programs is the process in which a program is loaded into the computer’s memory and then program ‘s instructions are executed. Most of the programs is executed with the support of an operating system and specific run-time libraries. 6. Testing: 6.1. Unit Test Plans (UTPs) are developed in module design step would performance now. The unit tests are a very necessary part of any application develop procedure and helps eliminate most of errors that can generate at a very early phase.

A unit like a program module is the smallest entity in the whole system. Unit testing check that the module can execute exactly when isolated from the rest of the units of system. 6.2. Integration testing: Integration Test Plans are developed in the Architectural Design step. Integration Testing performed to make sure that all of the modules created before which tested independently in UTPs can coexist and communicate among themselves within the system. Then Test results are shared with the client ‘s team. 6.3. System testing: System testing is strictly related with the system design stage. Unlike Unit and Integration Testing, System Test Plans are constructed by client's team. System Test plan ensures that all of the client ’s expectations are met. The entire application ’s system is tested for its functionality, interdependency and communication. System Testing authenticates those functional and non- functional requirements are met. Load and performance testing, stress testing, regression testing. Most of the problems about the compatibility between hardware and software can be discovered during this step. 6.4. Acceptance testing: User Acceptance Test (UAT) Plans are developed in the Requirements Analysis step. Test Plans are constructed by the user. UAT is executed in user environment and using realistic data to find out the incompatibility with the other systems. UAT confirms that complete system meets all the requirement of user and ready for use in actual time. It also detects the non-functional errors such as load and performance defects in the real time user environment. *** Debugging:** is a process of detecting and fixing the problems that prevent the program operating correctly. Developers can use debugging tools to check and correct errors in the program. In case of large program, the source code is divided into many small components which are debugged separated. Next stage is the whole program.

7.Maintenance: In computer programming, the concept of maintenance is referred to modify a software product after deployment step to correct errors, improve performance and attributes. But in reality, maintenance is more similar to enhance functionality of the system or fixing faults. Its purpose is to meet the changing with new technologies and requirements.

Press key 1: Solve the first order equation. Press key 2: Solve quadratic equation. Press key 3: Exit. Press key 1: Solve the linear equation The Solve Linear Equation function solves a linear equation of the form "ax + b = 0". It prompts the user to enter the values of coefficients 'a' and 'b', and then calculates the solution 'x' that satisfies the equation. The function handles different scenarios, including cases where 'a' is zero or 'b' is zero

Figure 11:Flowchart for solving linear equation........................................................................................................

 Inputs:

  • Coefficient 'a': The user is prompted to enter the value of coefficient 'a' in the linear equation.
  • Coefficient 'b': The user is prompted to enter the value of coefficient 'b' in the linear equation  Outputs:
  • Solution 'x': The function calculates the value of 'x' that satisfies the linear equation.  Steps: 1. Display a prompt to the user, asking them to enter the value of coefficient 'a' in the linear equation. 2. Read the value of coefficient 'a' from the user. 3. Display a prompt to the user, asking them to enter the value of coefficient 'b' in the linear equation. 4. Read the value of coefficient 'b' from the user.  Check if 'a' is equal to zero: If 'a' is zero, check if 'b' is also zero: - If 'b' is zero, display a message indicating that the equation has infinitely many solutions.  If 'b' is not zero, display a message indicating that the equation has no solution. –  If 'a' is not zero, calculate the solution 'x' using the formula: x = -b / a. 5. Display the solution 'x' to the user.

Press key 2: Solve quadratic equation. The Solve Quadratic Equation function solves a quadratic equation of the form "ax^2 + bx + c = 0". It prompts the user to enter the values of coefficients 'a', 'b', and 'c', and then calculates the solutions 'x1' and 'x2' that satisfy the equation. The function handles different scenarios based on the discriminant value (b^2 - 4ac) to determine the nature of the solutions (real, complex, or no real solutions).

 Outputs:

  • Solutions 'x1' and 'x2': The function calculates the values of 'x1' and 'x2' that satisfy the quadratic equation.  Steps:
  1. Display a prompt to the user, asking them to enter the value of coefficient 'a' in the quadratic equation.
  2. Read the value of coefficient 'a' from the user.
  3. Display a prompt to the user, asking them to enter the value of coefficient 'b' in the quadratic equation.
  4. Read the value of coefficient 'b' from the user.
  5. Display a prompt to the user, asking them to enter the value of coefficient 'c' in the quadratic equation.
  6. Read the value of coefficient 'c' from the user.
  7. Calculate the discriminant value using the formula: discriminant = b^2 - 4ac.
  8. Check the value of the discriminant:
    • If the discriminant is negative, display a message indicating that the equation has no real solutions.
    • If the discriminant is zero, calculate the solution 'x' using the formula: x = -b / (2a), and display the solution to the user.
    • If the discriminant is positive, calculate the solutions 'x1' and 'x2' using the formulas: x1 = (-b + sqrt(discriminant)) / (2a) and x2 = (-b - sqrt(discriminant)) / (2a), and display the solutions to the user.
  9. Display the solutions 'x1' and 'x2' to the user. Press key 3: Exit. The third function of the menu is exit, the following is the flowchart of the program: When we enter the key 1, the program will solve the first-order equation, enter the key 2, the program will solve the quadratic equation, enter the key 3, the program will end and automatically exit. If you enter 1 correctly  the program will solve the first order equation. If it is wrong, it will switch to key 2  if it is true, the program will solve the quadratic equation.

If later, it will switch to key 3, if it is correct, the program will automatically exit, if it is wrong, it will automatically print on the screen the words "The option does not exist, please re-enter the value from 1 - 3. "

5. Functions The first function : Solve Linear Equation

Figure 13: Solving for linear equation........................................................................................................................

  1. The function starts by displaying a message to the user indicating that it will solve a linear equation of the form "ax + b = 0".
  2. The user is prompted to enter the value of coefficient 'a'. The value is then read from the console and stored in the variable 'a'.
  3. The user is prompted to enter the value of coefficient 'b'. The value is read from the console and stored in the variable 'b'.
  4. The function checks if 'a' is equal to zero.
  5. If 'a' is zero, it further checks if 'b' is also zero. If both 'a' and 'b' are zero, it means the equation has infinitely many solutions. In this case, the function displays a message indicating that.