Docsity

Programming Assignment 1 Btec, Assignments of C programming

Partial preview of the text

Download Programming Assignment 1 Btec and more Assignments C programming in PDF only on Docsity!

ASSIGNMENT

PROGRAMMING REPORT 1

Student performance: TRAN QUANG HUY

ID: GCD

Class: GCD

Teacher: HOANG HUU DUC

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 TRAN QUANG HUY Student ID GCD Class GCD0821 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 HUY Grading grid P1 M1 D

INTRODUCTION Programming is important for speeding up the input and output processes in a machine. Programming is important to automate, collect, manage, calculate, analyze processing of data and information accurately. Programming is important to create software and applications that help computer and mobile users in daily life. Due to all these reasons, it’s important to learn how to use programming languages in our daily life. Java, javascript, C#, C++, PHP, Python, Swift, SQL, Ruby etc. programming languages are the reasons behind the innovations in information technologies. If today we are seeing robots, artificial intelligence, machine learning, bitcoins, the blockchain, IOT (Internet of Things), Cloud Computing etc. new technology and products in IT industry, then it’s because of programming languages. It’s also important to program a world that helps to reduce the corruption, improves transparency and happiness in everyone’s life. Programming languages are now a part of our life. Learning can never be wrong, but purposeful learning helps in a great way for students, businesses and all human beings. It’s should be done to support nature not to disturb it. That’s it for today!

Contents

  • I. Algorithm
      1. Definition of algorithm and characteristics of algorithm.
      • 1.1. Definition of algorithm.
      • 1.2 Characteristics of algorithm.
      1. Criteria to measure a good algorithm.
      1. Steps to build an application.
      • 3.1. Defining or Analyzing the problem:
      • 3.2. Design (Algorithm):
      • 3.3. Coding:
      • 3.4. Documenting the program:
      • 3.5. Compiling and running the program:
      • 3.6. Testing and debugging:
      • 3.7. Maintenance:
      1. Steps from writing code to execution:
      • 4.1. In General
      • 4.2 In C#
      1. The relationship between the written algorithm and the code variant
      • 5.1. Code variant:
      • 5.2. The difference between algorithm and code variant:
      • 5.3. The relationship between algorithm and code variant:
  • II.Programming paradigm
      1. Procedural programming..................................................................................
      • 1.1. Introduction:
      • 1.2. Characteristics:
      1. Object-oriented programming
      • 2.1. Introduction:
      • 2.2. Characteristics:
      1. Event-driven paradigm......................................................................................
      • 3.1. Introduction:
      • 3.2. Characteristics:
    • paradigms, in terms of the code stuckture and characteristics. 4. The source code of an application which implements the programming
  • III.Integrated Development Environment
      1. Definition:...........................................................................................................
      1. Features:
      1. Some specific IDE:
      • 3.1. Visual Studio:
      • 3 .2. NetBeans:
  • References
  • Picture 1 - Example coding to sum 2 number TABLE OF PICTURES
  • Picture 2 - Example An algorithm. (creately, n.d.)
  • Picture 3 - Example console run in C#
  • Picture 4 - Visual studio's interface
  • Picture 5 - Option in visual studio
  • Picture 6 - Create a project with visual studio
  • Picture 7 - Writing program in visual studio
  • Figure 1 - Example Flowchart of an Algorithm. (visual-paradigm, n.d.) TABLE OF FIGURES
  • Figure 2 - Example steps to cook rice
  • Figure 3 - 7 steps to build an application
  • Figure 4 - Writing code to execution in general
  • Figure 5 - Writing code to execution in C#..................................................................................
  • Figure 6 - Flowchart to find a number is even or odd.................................................................

1

I. Algorithm

1. Definition of algorithm and characteristics of algorithm. 1.1. Definition of algorithm. An algorithm is step by step method of solving a class of problem. It is a well-defined procedure that allows a computer to solve a math or some problem. Algorithms can perform calculation, daưta processing and automated reasoning tasks. Figure 1 - Example Flowchart of an Algorithm. (visual-paradigm, n.d.)

3

1.2 Characteristics of algorithm.

  • There are five important characteristics of an algorithm that should be considered while designing any algorithm for any problem: o Finiteness: An algorithm should terminate infinite number of steps and each step must finish in finite amount of time. o 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: - 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 ¾. o 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. o 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. (owlgen, n.d.) ▪ Example: Cook perfectly fluffy rice. (https://www.realsimple.com)
  1. Boil water and add salt
  2. Pour in rice
  3. Stir once, or just enough to separate the rice
  4. Cover the pot and simmer
  5. Fluff rice with a fork Figure 2 - Example steps to cook rice

4

2. 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: o Input: There are zero or more quantities which are externally supplied; o Output: at least one quantity is produced; o Definiteness: Each instruction must be clear and unambiguous; o Finiteness: If we trace out the instructions of an algorithm, then for all cases the algorithm will terminate after a finite number of steps; o Effectiveness: Ever instruction must be sufficiently basic that its principle be carried out by a person using only pencil and paper. o 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) o 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.

6

3. Steps to build an application.

There are 7 steps to build an application: 3.1. Defining or Analyzing the problem: Firstly, in this case, the problem must be understood before the program will be written. Then the problem must be analyzed to determine the input and output of the problem solution. This step is very important to make a successful of a project. 3.2. Design (Algorithm): With the problem was determined in the first step, there are a lot of way to solve it, but we should analyze and chose the best suitable solution that we are going to design into algorithm. To make the problem unambiguous and understandability, flow charts are drawn with the algorithms. 3.3. Coding: In programming language, all the logic and solution have been developed with the algorithm. Defining or Analyzing the problem (^) Design (Algorithm) Coding Documenting the program Compiling and running the program Testing and Debugging Maintenance Figure 3 - 7 steps to build an application

7 3.4. Documenting the program: Documenting the program is the information that describes the product to its users. For a user, the documentation helps them know how the program works and how to use it. For a developer, it helps them know all aspect of an application such as troubleshooting, database, server environment, etc. With using programing languages like C#, C++, Java, etc. Documentation often comes in two form:

  • External documentation: including Reference manuals, Algorithm descriptions, Flowcharts and Project Workbooks.
  • Internal documentation: including a part of the source code with declarations, statements and comments to provide an easier understanding. 3.5. Compiling and running the program : Compiling is a process of translating source code into binary machine code, which make computer can understand and work. 3.6. Testing and debugging:
  • Testing: is process of exploring the system to find defects present in the software, this process must locate the defects and define what will happen once these defects occur. After this phase, it will report to the developer to debug. Testing means detecting errors.
  • Debugging: When received the report from the testing, it will start debugging to locate the bug and rids the software of it. Debugging means diagnosing and correcting the root causes. 3.7. Maintenance: Program maintenance is the process of modifying a software or program after delivery to achieve any of these outcomes: o Correct errors o Improve performance o Add functionalities o Remove obsolete portions Maintenance also keep pace with changing requirements and technologies.

9

5. The relationship between the written algorithm and the code variant 5.1. Code variant:

  • Variant is a data type in certain programming languages, particularly Visual Basic, Ocaml, Delphi and C++ when using the component object model. Variant helps programmer develop their algorithms and with this code variant are essential for machine understand about the algorithm.
  • While the use of not explicitly declared variants is not recommended, they can be of use when the needed data type can only be known at runtime, when the data type is expected to vary, or when optional parameters and parameter arrays are desired. In fact, languages with dynamic type system often have variant as the only available type for variables. 5.2. The difference between algorithm and code variant:
  • The algorithm is used to provide a solution to a problem in form of well-defined steps. Whenever people use a computer to solve a problem and the algorithms can be expressed using natural language, flowcharts, etc. But variant does not use specific programming language syntax and therefor could be understood by programmers with different programming languages. 5.3. The relationship between algorithm and code variant:
  • The algorithms can be written in normal human language, allowing experts who are not programmers to provide input into the program's development phase. Code variant allows programmers who specialize in different programming languages to pool their knowledge and create the most efficient code, resulting in fast, compact programs. Each kind of “language” gives the programmer an advantage at the development stage when express their algorithms into code variant to solve solution.

10 Example: Find Whether a Number is Even or Odd Figure 6 - Flowchart to find a number is even or odd

12

II.Programming paradigm

1. Procedural programming

1.1. Introduction : Procedural programming is a programming paradigm, derived from structured programming, based upon the concept of the procedure call. Procedural programming is a list of instructions to tell a computer how to run from the code. Procedures also known as routines, subroutines, or functions, simply contain a series of computational steps to be carried out. ▪ Example: Pascal and C are two of the procedural programming languages. 1 .2. Characteristics:

  • Global data is often shared by all function.
  • Data moves openly from function to function.
  • Focus on process or doing things rather than data.
  • Using top-down approach in program design.
  • Functions transfers data from one form to another.
  • Data move openly around the system from function to function.
  • Large problems are divided into smaller programs knowns as function.

2. Object-oriented programming

1.1. Introduction:

Object-oriented programming (OOP) is a programming paradigm based on the concept of “objects” which may contain data, in the form of fields, often known as attributes; and code, in the form of procedures often know as methods. OOP packs data together, so an “object” is an instance of a class, operates on its “own” data structure. 2 .2. Characteristics:

  • Encapsulation: Encapsulation keeps data safety and securely from outside interfaces.
  • Inheritance: This is a process which a class can be received from a base class with all features of base class and some of it own. This process is very useful and help us to prevent from reusing code that will waste time and memory.
  • Polymorphism: Polymorphism is the ability to exist in various forms. That means objects of classes that inherited from a common base class may possess functions having the same name, but each having different behaviors.
  • Abstraction: Abstraction is a concept which facilitates the easy conceptualization of real-world objects into the software program. It refers to providing only essential information to the outside world and hiding their background details or eliminate the unnecessary details.
  • Objects: The instances of a class which are used in real functionality. It’s variables and operations.

13

  • Class definitions: Basic building blocks OOP and a single entity which has data and operations on data together.
  • Generic classes: Class definitions for unspecified data. They are knowing as container classes and flexible and reusable.
  • Class libraries: Built-in-language specific classes.

2. Object-oriented programming