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

Algorithms in Software Programming: A Practical Guide with C# Examples, Assignments of Programming Languages

A comprehensive introduction to algorithms in software programming, focusing on their importance, advantages, and disadvantages. It uses a practical example of a student grading system implemented in c# to illustrate the application of algorithms in solving real-world business problems. Code examples, flowcharts, and a detailed explanation of the algorithm's implementation, making it a valuable resource for students and professionals interested in learning about algorithms and their practical applications.

Typology: Assignments

2018/2019

Uploaded on 03/12/2025

linh-linh-89
linh-linh-89 🇻🇳

1 document

1 / 36

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
RT7
Assessor name
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
M1
D1
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24

Partial preview of the text

Download Algorithms in Software Programming: A Practical Guide with C# Examples and more Assignments 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 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Student ID

Class RT7 Assessor name

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:

Table of Contents

  • I. Introduction.........................................................................................................................
  • II. Algorithm.............................................................................................................................
      1. Definition of algorithm....................................................................................................
      1. The characteristics of an algorithm..................................................................................
      1. Advantages and disadvantages of algorithm....................................................................
      1. Algorithm for Simple Problem........................................................................................
  • III. Business problems..........................................................................................................
      1. Definition of business problems....................................................................................
      1. Steps for problem solving..............................................................................................
      • 2.1 Analyzing the problem...........................................................................................
      • 2.2 Developing an algorithm........................................................................................
      • 2.3 Coding....................................................................................................................
      • 2.4 Testing and Debugging...........................................................................................
      1. Solve business problems by algorithms.........................................................................
      • 3.1 Analyze the problem...............................................................................................
      • 3.2 Function..................................................................................................................
  • IV. Demonstrate application...................................................................................................
      1. Demonstrate and run program.......................................................................................
      1. SDLC and source code...................................................................................................
  • V. Evaluation problem...........................................................................................................
      1. Test plan and test case....................................................................................................
      1. Evaluation how to solve problems from algorithms......................................................
  • VI. Conclusion........................................................................................................................
  • VII. References......................................................................................................................
  • Figure 1. What is algorithm? Table of figures
  • Figure 2. Properties of algorithm
  • Figure 3. Shapes or symbol to draw flow charts
  • Figure 4. Flowchart to calculate square of a number
  • Figure 5. Code to calculate square of a number
  • Figure 6. The result of the algorithm to find the square of a number
  • Figure 7. Step for problem solving
  • Figure 8. Operation diagram of the program
  • Figure 9. Variables and data types
  • Figure 10. Menu of system
  • Figure 11. Flowchart Main menu
  • Figure 12. Flowchart Input Student
  • Figure 13. Flowchart Print information of student
  • Figure 14. Flowchart function Rank
  • Figure 15. Flowchart function Average
  • Figure 16. Flowchart function Pass
  • Figure 17. Main menu
  • Figure 18. Menu result
  • Figure 19. Code function input
  • Figure 20. Code function print
  • Figure 21. Input data
  • Figure 22. Function input
  • Figure 23. Result of function print
  • Figure 24. Code function rank
  • Figure 25. Result of unction rank
  • Figure 26. Code of function average
  • Figure 27. Result of function average
  • Figure 28. Code function pass
  • Figure 29. Result of function pass
  • Figure 30. Exit program
  • Figure 31. C# code compilation
  • Figure 32. Test plan
  • Figure 33. Test case

1. Definition of algorithm

Algorithm is one of the foundations of programming. There are many definitions of algorithms, such as:

Algorithms can be defined as: “A sequence of activities to be processed for getting desired output from a given input.”

Webopedia defines an algorithm as: “A formula or set of steps for solving a particular problem. To be an algorithm, a set of rules must be unambiguous and have a clear stopping point”. There can be many ways to solve a problem, so there can be more than one algorithm for a problem.

Now, if we take the definition of algorithm as: “A sequence of activities to be processed for getting desired output from a given input.” This is why an algorithm refers to a set of rules/instructions that define step by step how to do work to achieve an expected result.

Figure 1. What is algorithm?

Thus, the entire algorithmic flowchart will have three main components:

● Input: What we already know or things we have to start with. ● Algorithm: A set of sequenced steps that we need to follow one by one. ● Output: The expected results we need to achieve in the end.

Algorithms take in zero or more inputs and give back one or more outputs. A recipe is a good example of an algorithm because it tells you what you need to do step by step. It takes inputs (ingredients) and produces an output. For instance, the Coffee Maker Algorithm would run something like

● Turn on Coffee Maker ● Grind Coffee Beans ● Put in filter and place coffee in filter ● Add Water ● Start brewing process ● Drink coffee.

In computer programming, algorithms are often created as functions. These functions serve as small programs that can be referenced by a larger program. For example, an image viewing application may include a library of functions that each use a custom algorithm to render

different image file formats. An image editing program may contain algorithms designed to process image data. Examples of image processing algorithms include cropping, resizing, sharpening, blurring, red-eye reduction, and color enhancement.

Algorithm is developed first before writing the program. By using good algorithms, we can improve the efficiency of the program. Algorithm is not the complete program or code, it is just a solution of a problem or the set of steps that are required to solve a problem, which can be represented either using a Flowchart or Pseudocode.

2. The characteristics of an algorithm

Donald Ervin Knuth has given a list of five properties for a, algorithm, these properties are:

Figure 2. Properties of algorithm

  1. Input: An algorithm must be provided with 0 or more number of input/data values or in some cases no external input is provided.
  2. Output: After processing the statements in the algorithm step-by-step statements will generate some result. Hence at least 1 output must be produced. This enables us to verify the algorithm.
  3. Finiteness: An algorithm must always terminate after a finite number of steps. It means after every step one reaches closer to the solution of the problem and after a finite number of steps algorithm reaches to an end point. For example
  1. Let a = 10
  2. If a >10 then go to step 5

There are standardized symbols to draw flowcharts. Some are given in Table below.

Flowchart symbol

Function Description

Start/End Also called the “Terminator” symbol. It indicates where the flow starts and ends. Process Also called “Action Symbol”, it represents a process, action, or a single step. Decision A decision or branching point, usually a yes/no or true/false question is asked, and based on the answer, a path gets split into two branches. Input/Output Also called a data symbol, this parallelogram shape is used to input or output data. Arrow Connector to show order of flow between shapes. Figure 3. Shapes or symbol to draw flow charts

Some examples of algorithms.

Example 1 : Write an algorithm to find the square of a number.

Before developing the algorithm, let us first identify the input, process and output:

● Input: Number whose square is required ● Process: Multiply the number by itself to get its square. ● Output: Square of the number.

Algorithm to find the square of a number.

Step 1: Input a number and store it to num

Step 2: Compute num * num and store it in square

Step 3: Print square

There can be represented pictorially using flowchart as shown in Figure below.

Figure 4. Flowchart to calculate square of a number

The below program asks the user to enter the value. After getting the value from the user it will calculate the square of entered number by using arithmetic multiplication operator.

Figure 5. Code to calculate square of a number

And the result:

Figure 6. The result of the algorithm to find the square of a number

Figure 7. Step for problem solving

2.1 Analyzing the problem

It is important to clearly understand a problem before we begin to find a solution to it. If it is not clear to us what will be resolved, we may end up developing a program that may not solve our purpose. Therefore, we need to read and analyze the statement carefully to list the main components of the problem and decide what core functions our solution should have. By analyzing a problem, we will be able to figure out what input our program should accept and what output the program should produce.

2.2 Developing an algorithm

It is essential to device a solution before writing a program code for a given problem. The solution is represented in natural language and is called an algorithm. We can imagine an algorithm like a very well-written recipe for a dish, with clearly defined steps that, if followed, one will end up preparing the dish.

We start with a tentative solution plan and keep on refining the algorithm until the algorithm is able to capture all the aspects of the desired solution. For a given problem, more than one algorithm is possible and we have to select the most suitable solution.

2.3 Coding

After finalizing the algorithm, we need to convert the algorithm into the format which can be understood by the computer to generate the desired solution. Different high level programming languages can be used for writing a program.

2.4 Testing and Debugging

The program created should be tested on various parameters. The program should meet the requirements of the user. It must respond within the expected time. It should generate correct

output for all possible inputs. In the presence of syntactical errors, no output will be obtained. In case the output generated is incorrect, then the program should be checked for logical errors, if any.

Software industry follows standardized testing methods like unit or component testing, integration testing, system testing, and acceptance testing while developing complex applications. This is to ensure that the software meets all the business and technical requirements and works as expected. The errors or defects found in the testing phases are debugged or rectified and the program is again tested. This continues till all the errors are removed from the program.

Once the software application has been developed, tested and delivered to the user, still problems in terms of functioning can come up and need to be resolved from time to time. The maintenance of the solution, thus, involves fixing the problems faced by the user, answering the queries of the user and even serving the request for addition or modification of features.

3. Solve business problems by algorithms

To be able to understand more about the algorithm and its details. I will apply an algorithm to solve a problem like this: A teacher wants to manage the final grades of students in the class. He needs to print out the ranking of the students, calculate the average score of the students and calculate the pass rate of the students. The program needs to enter student information, student IDs and grades.

After entering the information, the program needs a Menu so that he can use the functions as a After read clearly the scenario, I solved it by using an algorithm based on C# language to create a program must have full option that satisfy the requirement of teacher. C# is a general object-oriented programming (OOP) language for networking and Web development. C# is specified as a common language infrastructure (CLI) language. In January 1999, Dutch software engineer Anders Hejlsberg formed a team to develop C# as a complement to Microsoft’s NET framework. Initially, C# was developed as C-Like Object Oriented Language (Cool). The actual name was changed to avert potential trademark issues. In January 2000, NET was released as C#. Its NET framework promotes multiple Web technologies.

Here, we need to create an application to enter name, score, ID above.

3.1 Analyze the problem

To solve the above problem, we need the Input and Output integration of the problem. Here, the teacher will enter the student's information and ask the program to print out the student rankings, the grade point average of the class and the passing rate of the students. So, we can summarize the input and output as follows:

● Input: Student's information including ID, name and grade. ● Output: Ranking, GPA and pass rate of students in the class.

name (name), student’s ID (ID), intermediate variable to change student code according to grade arrangement (id). To be clearer, I will create a table of the variables that I use in this program.

Data type Variable Function Integer choice Get user selected silk Double number Declare the number of students sum Calculate the total score of the student count Calculate the number of students who pass the course compare The intermediate variable to sort the student’s score grade Declare student’s grade String ID Declare the ID of the student name Declare the name of the student id The intermediate variable to change the student’s ID according to the score arrangement. Figure 9. Variables and data types

3.2 Function

Here, I will use flowchart to show the algorithms that I will use in the system.

  1. Menu

The system includes the following features:

Figure 10. Menu of system

Figure 11. Flowchart Main menu

Algorithm (Pseudo code):

Figure 12. Flowchart Input Student

  1. Print information of student

Figure 13. Flowchart Print information of student

  1. Function Rank