Download Assignment 1, programming 1619, Pass and more Essays (university) Computer Science 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 Trinh Nguyen Phuong Student ID GCH Class GCH1110-RE Assessor name Pham Danh Tuyen 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 PHUONG
Grading grid P1 M1 D
Summative Feedback: Resubmission Feedback:
Grade: Assessor Signature: Date: Lecturer Signature:
Table of content
- Count the components.
- To prepare the batter, combine the ingredients.
- Oil a pan.
- Fill the pan with the batter.
- Place the skillet in the oven.
- Make a timer.
- Take the pan out of the oven when the timer sounds.
- Eating! Another example of an algorithm to solve a code problem is: Find the sum of two input numbers N and M. The procedure should be:
- Enter the two numbers in the variables N and M.
- Sum them and save the result in the variable sum.
- Output the result. Figure 1: Algorithm to calculate the sum of two numbers. Writing a set of instructions for the computer with a limited number of steps is what algorithmic programming is all about. A computer program is essentially an algorithm that instructs the machine on how to carry out a certain task by instructing it on what exact actions to take and in what order. Depending on the programming language being used, a particular syntax is utilized while writing algorithms. b. Properties of algorithms
- Specified Input: We must be aware of all pertinent information, including the kind, size, data structure, distribution, and other characteristics of the input. A value or a group of values can be used as input
- The output that is Specified: We must be aware of all pertinent information regarding
the output. A value or a collection of values can be the output
- Correctness: Our algorithm must come to an end with the right result for every set of inputs. So, our algorithm has to be accurate. For some input values, an erroneous algorithm may stop with inaccurate responses or not stop at the correct output.
- Efficiency: Because running time and memory are finite resources, our algorithms must be efficient in how they use them. To put it simply, our method should be effective in terms of memory and time.
- Finiteness: After a finite number of steps, our algorithm must come to an end. There should never be an infinite loop or unlimited recursion
- Simple and Elegant : An algorithm should be easy to understand and implement c. Different types of algorithms Based on the ideas that they employ to complete a task, algorithms are categorized. Even though there are numerous kinds of algorithms, the following are the most basic kinds:
- Divide and conquer algorithms : break the problem down into smaller, related subproblems, solve those, then combine those solutions to solve the original problem.
- Brute force algorithms : all potential solutions are tested until one is discovered to be adequate.
- Randomized algorithms : use a random number at least once during the computation to find a solution to the problem.
- Greedy algorithms : discover the best answer at the local level to find the best solution overall.
- Recursive algorithms: solve the lowest and simplest version of a problem to then solve increasingly larger versions of the problem until the solution to the original problem is found.
- Backtracking algorithms: Divide the problem into smaller problems that can each be tried to be addressed; however, if the desired answer is not obtained, travel backward in the problem until a path is found that pushes it forward.
- Dynamic programming algorithms: divide a large problem into several smaller,
Figure 2: Example of Object ii. Characteristics
1. Encapsulation - The method through which programmers’ separate data inside the object is called encapsulation. - The two primary elements of the OOP paradigm that increase security are encapsulation and abstraction of data. It stops data that is saved in the database from being altered by hackers 2. Abstraction - This is the process of creating reusable objects that are designed to standardize common business logic. They should be used consistently across many different applications. This helps to standardize the logic and makes it easier to maintain across various programs. - It encourages collaboration between different parties, making it easier to create programs that integrate disparate data sets and functionality. 3. Classes and Objects - The blueprint for an object is specified in a class. The object's methods, traits, and other characteristics are described in the blueprint. Classes are used to build objects. - It outlines the object's characteristics, methods, and other features. Classes are used to build objects. A class is simply an object's blueprint. It outlines the object's characteristics, methods, and other features. 4. Inheritance and Composition - The act of permitting one object to produce another is known as inheritance. The attributes, methods, and other features of another object can essentially be "inherited" by another object. - The act of combining different objects to produce a brand-new, original object is known as composition. Programmers can essentially reuse the elements that are specific to other objects to construct new, original objects. iii. Compare to POP
- Procedural programming is a programming paradigm that uses a linear or top- down approach. It relies on procedures or subroutines to perform computations. (Techopedia 2015). In simpler words, programmers write a series of instructions involving the progress of splitting up lines of codes into a small set of variables, data structures, and subroutines. OOP POP Basic Definition OOP is object- oriented. POP is structure or procedure-oriented. Progr am Divisi on The program is divided into objects. The program is divided into functions. Approach (^) Bottom-Up approach Top-down approach Data Control Data in each object is controlled on its own. Every function has different data, so there’s no control over it. Entit y Linka ge Object functions are linked through message passing. Parts of a program are linked through parameter passing. Expansion Adding new data and functions is easy. Expanding data and function is not easy.
grades. Finally, he needs to know which student has highest grade and lowest grade. Your program should be menu based with the options above. When an option is done, the program should go back to the main menu so he can choose another option. There should be an option to quit program. b. Applications of algorithm and OOP There are various types of data such as student Id (type Integer), and grades (type float), that are needed to be stored and accessed through different methods. Using global variables to store this information could help to reduce the duplication inside each function and all of the functions can access these variables. For example, the function accepts will receive the input from the teacher and store the student's records inside a list, and then the function display will get the data from the student's list, which is global, to display the records. To provide an interface for the teacher to choose the option to execute the program, a do-while loop statement and multiple print functions are necessary. Hence, to conclude, procedural programming is a well-suited solution for breaking down the programs into different sub-routines (suitable for different needed features that the Maths teacher wants), storing, managing variable sets to use globally through the program and loop and conditional statements for validation, display and get the inputs. To provide an interface for the teacher to choose the option to execute the program, a do-while loop statement and multiple print functions are necessary. Hence, to conclude, procedural programming is a well-suited solution for breaking down the programs into different sub-routines (suitable for different needed features that the Maths teacher wants).
II. Analysis and Design
1. Analysis
a. Data types No Name Type Purpose 1 Student Store student’s id, name, grades 2 user Choice String Store user’s menu choice
3 _students List List contains students’ record 4 i Integer Keep track of the index inside the students list 5 id Integer Store the index of the student needed to update or delete 6 isValidName, isValidGrade Boolean Variable to keep track of the validation result for input name, grades. b. Data Structure
- studentNames: string[] - An array to store the names of the students.
- studentIDs: int[] - An array to store the IDs of the students.
- studentGrades: float[] - An array to store the grades of the students.
- numberOfStudents: int - A variable to store the total number of students. c. Conditional Statement i. In the ‘Main’ function:
- ‘while (!exit)’ - This conditional statement checks if the variable exit is false. It continues to loop if exit is false.
- ‘switch (choice)’ - This conditional statement checks the value of the variable ‘choice’ and executes the corresponding case based on the user's input. ii. In the ‘PrintStudentInformation’ function:
- ‘if (numberOfStudents == 0)’ - This conditional statement checks if the ‘numberOfStudents’ variable is equal to 0. It is used to check if any student information has been entered. iii. In the ‘FindStudentWithHighestGrade’ and ‘FindStudentWithLowestGrade’ function:
program. Flow chart
III. Demonstration
1. Source code
a. Main:
- The ‘Main’ function serves as the entry point of the program. It displays the program title and enters a while loop that continues until the user chooses to exit.
- The ‘PrintStudentInformation’ function checks if any student information has been entered (‘numberOfStudents == 0’). If no information is available, it displays a message indicating that no student information has been entered. Otherwise, it iterates over the arrays and prints the student IDs and grades. d. FindStudentWithHighestGrade and FindStudentWithLowestGrade
- The ‘FindStudentWithHighestGrade’ function checks if any student information has been entered. If not, it displays a message indicating that no student information has been entered. Otherwise, it finds the student with the highest grade by iterating over the ‘studentGrades’ array and keeping track of the index (‘highestGradeIndex’) and grade (‘highestGrade’) of the student with the highest grade. Finally, it prints the information of the student with the highest grade.
- The ‘FindStudentWithLowestGrade’ function is similar to ‘FindStudentWithHighestGrade’ but finds the student with the lowest grade instead.
2. Screenshots
a. Menu
e. Find student with lowest grade f. Quit program
3. Software Development Life Cycle
- The use of common business procedures in the development of software applications is known as the software development life cycle. Planning, Requirements, Design, Build, Document, Test, Deploy, and Maintain is the traditional six to eight processes. Depending on the size and complexity of the project, some project managers will combine, divide, or eliminate steps.
- The SDLC is a tool for monitoring and enhancing the development process. It enables a detailed examination of every stage of the procedure. As a result, businesses can maximize efficiency at every stage.
- Seven phases of the SDLC:
- Planning: Planning should distinctly outline the application's scope and goal. It charts the team's trajectory and provides everything they need to successfully construct the program. Additionally, it establishes limitations to
prevent the project from escalating or deviating from its initial objective.
- Define Requirements : To define what the application is intended to achieve and its requirements, defining requirements is considered to be an element of planning. For instance, a social media app would need to allow users to interact with friends. A search function can be necessary for an inventory program.
- Design and Prototyping: The Design phase models the way a software application will work
- Software Development: This is the real program writing. A small project might be written by just one developer, whilst a big project might be divided into numerous teams and worked on by them all.
- Testing: Before making an application accessible to users, testing is essential. Security testing is one area of testing that can be automated.
- Deployment: In the deployment phase, the application is made available to users
- Operations and Maintenance: The development cycle is about to complete at this stage. The program is finished and in use in the field. However, the Operation and Maintenance phase is still crucial. Users find flaws in this stage that weren't detected during testing.
4. How the source is compiled and run
- Human languages are not understood by computers. In actuality, computers can only comprehend numerical sequences that reflect operating codes at the most fundamental level (op codes for short). On the other hand, writing programs in terms of op codes would be extremely challenging for humans. Programming languages were created as a result to make it simpler for people to create computer programs.
- Humans can read and understand programming languages. For the computer to run the program, the source code must be translated into machine language (as the computer only understands machine language). Whether the programming language is an interpreted