Download Assignment 1 - Programming - 1618 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 Le Nguyen Quang Nam Student ID GCD Class GCD0905 Assessor name Nguyen Van Loi 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:
- CHAPTER I. DEFINITION OF ALGORITHM AND ITRODUCTION TO SIMPLE BUSSINESS PROBLEM TO BE SOLVED (P1)..
- Definition of algorithm.....................................................................................................................................
- Introduction to simple problem.......................................................................................................................
- CHAPER II. ANALYZING THE PROBLEM AND DESIGNING THE SOLUTIONS (P2)............................................................
- Analyzing the problem......................................................................................................................................
- Designing the solutions....................................................................................................................................
- 2.1. Use-case diagram...................................................................................................................................
- 2.2. Flowchart for the menu option..............................................................................................................
- 2.3. Flowchart for checking the perfect number.........................................................................................
- 2.4. Flowchart for checking the prime number...........................................................................................
- 2.5. Flowchart for decomposing number N into its prime factors..............................................................
- CHAPTER III. DEMOSTRATING THE COMPILATION AND RUNNING OF A PROGRAM..................................................
- Demonstrating the compilation and running of a program............................................................................
- 1.1. Function in the program: Entering number N......................................................................................
- 1.2. Function in the program: Menu option................................................................................................
- 1.3. Function in the program: Checking the perfect number......................................................................
- 1.4. Function in the program: Checking the prime number........................................................................
- 1.5. Function in the program: Decomposing number N into its prime factors............................................
- 1.6. Function in the program: Main............................................................................................................
- Software Development Life Circle..................................................................................................................
- The compilation of the source code...............................................................................................................
- REFERENCE LIST.........................................................................................................................................................
- Figure 1. Algorithm. TABLE OF FIGURES
- Figure 2. A simple example of algorithm about ordering the numbers.
- Figure 3. Use-case diagram of The Algorithmic Program.
- Figure 4. Flowchart for the menu option of The Algorithmic Program.
- Figure 5. Flowchart for Checking the perfect number.
- Figure 6. Flowchart for checking the prime number.
- Figure 7. Flowchart decomposing number N into its prime factors.
- Figure 8. Entering number N function.
- Figure 9. The output of Entering number N function.
- Figure 10. Menu option function.
- Figure 11. The output of Menu option function.
- Figure 12. Algorithm for Checking the perfect number.
- Figure 13. The output of Checking the perfect number.
- Figure 14. Another output of Checking the perfect number
- Figure 15. Algorithm for Checking the prime number function.
- Figure 16. The output of Checking the prime number.
- Figure 17 Another output of Checking the prime number.
- Figure 18. Algorithm for Decomposing number N into its prime factors function.
- Figure 19. The output of Decomposing number N into its prime factors.
- Figure 20. Another output of Decomposing number N into its prime factors.
- Figure 21. Main program
- Figure 22. A typical Software Development Life Cycle consists of the following stages.
- Figure 23. How the source is compiled.
CHAPTER I. DEFINITION OF ALGORITHM AND
ITRODUCTION TO SIMPLE BUSSINESS PROBLEM TO BE
SOLVED (P1).
1. Definition of algorithm.
In mathematics and computer science, an algorithm is a finite sequence of well-defined instructions, typically used to solve a class of specific problems or to perform a computation. Algorithms are used as specifications for performing calculations, data processing, automated reasoning, automated decision-making and other tasks. Broadly, algorithm is a step-by-step procedure for solving a problem or accomplishing some end. Figure 1. Algorithm.
To make it more accessible, let's take an algorithmic example. Figure 2. A simple example of algorithm about ordering the numbers. To sort a jumbled sequence of numbers, having ways to deal with it. However, to do it in a program that needs logic, the most efficient way is to use an algorithm to break the problem down as Figure 2 illustrating. From a sequence of numbers having 8 digits, divide it into 4 sequences of numbers having 2 digits to solve. Clearly, dealing with a sequence of two-digit numbers is much easier than dealing with a sequence of eight-digit numbers. After solving each small part, put them together and come up with the final result of the problem.
2. Introduction to simple problem.
Figure 3. Use-case diagram of The Algorithmic Program. As Figure 3 illustrated, after entering a random number, the users can perform function 1 to function 4. The functions from 1 to 3 will also displayed by following flowcharts.
2.2. Flowchart for the menu option.
Switch-case statement is used for creating the menu option.
Figure 4. Flowchart for the menu option of The Algorithmic Program. The menu have four cases for the users choose. Case 1 to 3 will be represented by the corresponding flowcharts to the algorithms used with them. Before choosing options, the users must enter the number N that they like. The number N must be more than 0. If the users enter negative numbers, the program force them to re-enter the positive numbers.
2.3. Flowchart for checking the perfect number.
Figure 6. Flowchart for checking the prime number.
2.5. Flowchart for decomposing number N into its prime factors.
Figure 7. Flowchart decomposing number N into its prime factors.
CHAPTER III. DEMOSTRATING THE COMPILATION AND
RUNNING OF A PROGRAM.
1. Demonstrating the compilation and running of a program.
After implementing the program by designing flowcharts for the functions, I will generalize and code the program.
1.1. Function in the program: Entering number N.
As mentioned above, the users will enter a random number that they like. After that, the program will display a menu option. Therefore, I create a function that allow the users to enter the number N.
Figure 10. Menu option function. Output:
Figure 11. The output of Menu option function.
1.3. Function in the program: Checking the perfect number.
The first function in The Algorithmic Program is used for Checking the perfect number N that the users enter previously. Figure 12. Algorithm for Checking the perfect number. Explanation: Step 1: Declare variable: int sum = 0. Step 2: Using for loop to find positive divisors of a given number and sum of these divisors. Step 3: Checking the perfect of a given number and printing the result. The output:
Figure 15. Algorithm for Checking the prime number function. Explanation: Step 1: Declare variables: mark = 1; This variable is used for marking to find a prime number. Step 2: Marking numbers. Step 3: Checking the prime number based on Step 2 and printing the result. The output:
Figure 16. The output of Checking the prime number. Another result: Figure 17. Another output of Checking the prime number.
1.5. Function in the program: Decomposing number N into its prime factors.
The seventh function in The Algorithmic Program is used for decomposing number N into its prime factors that the users enter previously. The input: