Docsity

Assignment 1 - PROG102, Assignments of Programming Languages

Toggle sidebar
bg1
1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Prog102: Procedural Programming
Submission date
19/10/2021
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Phan Nhat Linh
Student ID
GCD201635
Class
GCD0905
Assessor name
Phan Thanh Tra
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
Linh
Grading grid
P1
P2
P3
M1
M2
D1
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
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d

Partial preview of the text

Download Assignment 1 - PROG102 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 Prog 102 : Procedural Programming Submission date 19/10/2021 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Phan Nhat Linh Student ID GCD Class GCD0905 Assessor name Phan Thanh Tra 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 Linh Grading grid P1 P2 P3 M1 M2 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Table of Contents

  • CHAPTER I: PROBLEM STATEMENT
      1. Scenario
      1. Objective reporting
      1. Report outline
  • CHAPTER II: INTRODUCTION
      1. A programming language
      • 1.1 High-level languages
      • 1.2 Low-level languages
      1. C language
      • 2.1 Definition
        1. 2 Advantages Of C........................................................................................................................
      • 2.3 Disadvantages Of C
      1. Procedural Programming
      • 3.1 Defenition
        1. 2 Advantages
        1. 3 Disadvantages
  • CHAPTER III: CHARACTERISTICS OF PROCEDURAL PROGRAMMING
      1. Predefined functions:
      1. Local Variables................................................................................................................................
      • 2.1 Definition
      • 2.2 Advantages of using Local Variables
      • 2.3 Disadvantages of using Local Variables....................................................................................
      1. Global Variables
      • 3.1 Definition
      • 3.2 Advantages of using Global variables
      • 3.3 Disadvantages of using Global Variables
      1. Modularity
      1. Parameter Passing............................................................................................................................
      • 5.1 Pass by value..............................................................................................................................
      • 5.2 Pass by reference
      1. Program Structure............................................................................................................................
      • 6.1 Function Declaration
      • 6.2 Procedural Program Organization
      • 6.3 Program Organization
  • CHAPTER IV: ANALYZE THE SITUATION
      1. Variables and Data Types................................................................................................................
      • 1.1 Variables
      • 1.2 Data Types
      1. Conditional statements
      • 2.1 If statement
      • 2.2 Switch case
      1. Loop statements
      • 3.1 For
      • 3.2 Do-while
      • 3.3 While..........................................................................................................................................
      1. Function
      • 4.1 Theory
      • 4.2 In the program............................................................................................................................
      1. Hierarchy Diagram
  • CHAPTER V: Diagrams
      1. Use case diagram
      1. Flowchar diagrams
      • 2.1 Menu option operation
      • 2.2 Enter information
        1. 3 Print information
        1. 4 Findding the students have highest grade
        1. 5 Findding the students have lowest grade
  • CHAPTER VI : EVALUATE THE PROGRAM
      1. Advantage
      • 1.1 Aesthetics
      • 1.2 Accuracy
      • 1.3 Conclusion
      1. Disadvantage
      1. Improvement
  • References
  • Figure 1: Presenting TABLE OF FIGURES
  • Figure 2: Examples of high-level languages
  • Figure 3: example of low-level languages
  • Figure 4: C Programming Language Icon...............................................................................................
  • Figure 5: Advantages and Disadvantages of C language
  • Figure 6: A structure program
  • Figure 7: Procedural Vs Object-Oriented Coding Style
  • Figure 8: Some of the predefined functions in stdio.h header file (part 1)
  • Figure 9: Some of the predefined functions in stdio.h header file (part 2)
  • Figure 10: Example of local variable
  • Figure 11: Example of global variable
  • Figure 12: Example of modularity
  • Figure 13: C program to illustrate call by value
  • Figure 14: Result of the program in Figure 13........................................................................................
  • Figure 15:C program to illustrate call by reference
  • Figure 16: Result of the program in Figure 15........................................................................................
  • Figure 17: Example of Function Declaration
  • Figure 18: Example of Program Organization
  • Figure 19:Some of Data Types in C Programming Language
  • Figure 20:The flowchart of if statement
  • Figure 21: The flowchart of switch case
  • Figure 22: The flowchart of for loop
  • Figure 23: The flowchart of do-while loop
  • Figure 24: The flowchart of while loop
  • Figure 25: Function Prototype
  • Figure 26:5. Hierarchy Diagram of the scenario.....................................................................................
  • Figure 27: The use case diagram for actions required
  • Figure 28: The flowchart for menu option operation
  • Figure 29: The flowchar of enter information
  • Figure 30: The flowchar of display information
  • Figure 31: The flowchart of Getting the best grade
  • Figure 32: The flowchart of getting the students have the best grade
  • Figure 33: The flowchart of Getting the worst grade.............................................................................
  • Figure 34: The flowchart of getting the students have the worst grade
  • Figure 35: Menu option...........................................................................................................................
  • Figure 36: Response from the program...................................................................................................
  • Figure 37: Example of the downside of the program..............................................................................
  • Figure 38: Example of grade color
  • The first chapter introduces the problem and the situation posed.
  • Chapter two introduces programming language, C language and procedual programming.
  • Chapter three delves into characteristics of procedural programming
  • Chapter four is the scenario analysis given
  • Chapter five is in charge of creating design diagrams for the program, including a use case diagram.
  • Chapter six is Evaluating the program CHAPTER II: INTRODUCTION

1. A programming language

A programming language is a set of commands, instructions, and other syntax that is used to write software. "High-level languages" refer to the languages that programmers use to write code. This code can be turned into a "low-level language" that the computer hardware can understand directly.

1.1 High-level languages

a. Definition A high-level language is a programming language that is meant to make computer programming easier. The term “high-level” refers to the separation of numerous processor operations from the actual application. Figure 2 : Examples of high-level languages b. Advantages of High-level languages

  • They are simple to create, debug, and maintain, resulting in fewer faults that are easier to locate, identify, and delete.
  • High-level languages are user-friendly to programmers; not only is learning a lot simpler, but high-level programming is also more efficient.
  • They aren’t dependent on machines.

c. Disadvantages of High-level languages

  • It’s possible that translating the source into machine code will take longer. As a result, high- level programs are slower than low-level programs.
  • They are significantly less memory efficient than low-level programs.
  • They are unable to connect with the hardware directly.

1.2 Low-level languages

a. Definition A low-level language works with the physical components and restrictions of a computer. It works to control a computer’s operational semantics and has no abstraction about computers. Figure 3 : example of low-level languages b. Advantages of Low-level languages

  • They can communicate directly with hardware devices.
  • The low-level language program is efficient and quick. Compilers and interpreters do not need to convert the source code to machine code. As a result, the compilation time is reduced.
  • Low-level languages allow for direct manipulation and storing of computer registry data. c. Disadvantages of Low-level languages
  • They are more difficult to create, debug, and maintain, resulting in more error-prone, easy-to- find, identify, and delete faults.
  • Because they rely largely on the computer, low-level language-designed programs are not mobile.
  • Low-level programming is notorious for lowering programming productivity.
  • A programmer must also be familiar with the computer architecture of a certain machine.

The syntax of the C programming language is relatively simple to grasp. It employs keywords such as if, else, goto, switch, main, and so on. This is the type of term that we all use in our daily lives to express meaning or make judgments. e, Portable The setup for the C language is about 3-5 MB. As a result, you may save this language on a floppy disk or a USB flash drive. It's simple to set up and use, and its result is an exe file that can be run on any machine without the need for any additional framework or software. Figure 5 : Advantages and Disadvantages of C language

2. 3 Disadvantages Of C

a, Object-Oriented Programming Features (OOPS) Because the C language lacks object-oriented programming features, you must create your application entirely in procedure-oriented language. b, Run-Time Type Checking is Not Available There is no provision for run-time type verification in C. For example, if I send a float value and the receiving parameter is of integer type, the value will be altered and no error notice will be displayed. c, Namespace Feature Because C lacks namespace support, you won't be able to reuse the same variable name across scopes. You may be possible to reuse the same variable name if namespace features are present. d , Constructor and Destructor is not available Constructor and Destructor are not available in C since it lacks object-oriented capabilities. Constructor and Destructor are methods for creating and destroying objects. As a result, in C, you must manually build and destroy the variable, either via a function or another method. Our instructional course design is both practical and instructive. We provide resources at TekSlate to assist you in learning various IT courses. We provide both textual and video demonstrations. Explore Online C Tutorials for in-depth information and practical experience.

3. Procedural Programming

3.1 Defenition

Procedural programming is a programming approach that allows for the division of functions into a number of processes. A huge program is split down into smaller, more manageable sections called procedures or functions in procedural programming. Functions take precedence over data in this case. A program in a procedural programming language consists of a series of instructions, each of which instructs the computer to perform a specific task, such as reading user input, performing the necessary computation, and presenting the results. When a program grows in size, it is divided into smaller components known as procedures or functions. For the completion of a given task, a number of functions are needed to be written. Because the same function is called from many locations, these functions prevent code duplication. Only medium-sized software programs are acceptable for this method. Figure 6 : A structure program There are two sorts of data in procedural programming: local and global. Local data is data that is contained within a function, while global data is data that is not included within any function. The only function where local data is defined has access to it. As a result, each function has access to both local and global data. Other functions cannot access the local data of one function. If two or more functions need to access the same data, it should be made global. Global data, on the other hand, is subject to being modified unintentionally by another programmer. The separation of data and functions performs a poor job of simulating real-world situations. As a result, procedural programming does not properly replicate a real-world system. Some programming languages that may implement procedural programming include COBOL, FORTRAN, C, and Pascal.

CHAPTER III: CHARACTERISTICS OF PROCEDURAL PROGRAMMING

1. Predefined functions:

In a program, a function is a procedure that may be invoked by its name. Built-in functions refer to predefined functions. They are a collection of subroutines that perform specialized functions. These functions are often included in high-level programming languages like Python and C++, but they may also be imported into the programming language via registries or libraries. Figure 8 : Some of the predefined functions in stdio.h header file (part 1) User-defined functions, on the other hand, are functions that are created by the user and must be loaded through a program, i.e., they are only present in that program and nowhere else. Concat(), for example, is a pre-defined function that allows you to combine the text of two strings into one new string. sqrt(), for example, returns the square root of any number passed to it as a parameter. The sqrt() function is a predefined function since it is built-in to Python and does not require explicit loading. They're helpful since they save the user from having to write a long line of code for a process and instead allow them to use a function. Furthermore, built-in features do not require any loading, making them extremely handy.

Figure 9 : Some of the predefined functions in stdio.h header file (part 2)

2. Local Variables

2.1 Definition

Variables are storage areas with specified names in computer languages. They can have values assigned to them by users. They are used to refer to a program's stored value. Local variables, also known as lexical variables, are variables defined within a method and may only be used/referenced within that method. As a result, their scope is limited to that technique, and they can't be utilized elsewhere. Other methods in the program will be unaware of the local variable created in this function if there are any. The software will throw an error if a local variable is used in another function. Figure 10 : Example of local variable The variable x, which is declared within the function, is only accessible within the function.

Figure 11 : Example of global variable Only global variables are accessible in certain computer languages, but most programming languages enable you to select between global and local variables. The 'global' keyword in some of these languages, such as Python and MATLAB, allows the creation of a global variable anywhere in the program, including inside the function. Some computer languages, particularly some modular programming languages, do not enable global variables at all.

3.2 Advantages of using Global variables

  • The global variable can be accessed from any function or module in a program.
  • Outside of the modules, you only need to define global variables once.
  • It's great for storing "constants" since it helps maintain consistency.
  • When many functions need to access the same data, a global variable comes in handy.

3.3 Disadvantages of using Global Variables

  • If there are too many global variables defined, they will remain in memory until the program is finished. This might result in an Out of Memory error.
  • Any function has the ability to change data. The value of the global variable can be changed by any statement in the program. In multi-tasking situations, this might lead to unforeseen outcomes.
  • If global variables are no longer used as a result of code restructuring, you'll need to update all of the modules that use them.

4. Modularity

Modularity refers to the use or use of modules, or pieces or components. It implies breaking down a huge problem into tiny chunks so that it may be solved quickly. It entails breaking down the program's functionality into smaller, independent components, each of which may do the job for which it was created. The work may be split down into smaller executable parts that can be readily turned into computer code thanks to the modular design. As a result, it is the breaking down of a program into smaller chunks that are easier to comprehend, alter, and administer. Modular programming in structural programming refers to the use of structured flow in low-level code.

Figure 12 : Example of modularity There are several advantages to programming in a modular fashion. The program is easier to work on, which is a significant benefit. It also allows you to invoke a piece of code many times. A single module can also be run independently of the rest of the program because it is a standalone component. The idea of modularity in procedural programming indicates that a big program is divided into smaller components, each of which performs a single task. These modules or components complete duties one by one before delivering the ultimate product.

5. Parameter Passing

Parameter passing is a programming language feature that allows parameters to be given to procedures or functions. The term parameter should not be confused with the term argument. The argument is the value that is provided to the function and is processed by it, whereas the parameter is the value that is specified in the function when it is declared. Multiple ways can be used to pass parameters to a function. The four parameter passing techniques are listed and discussed below:

5.1 Pass by value

In-mode semantics are used in pass by value mode. Any changes to the perimeter are not sent to the caller while using this approach. Changes to the parameter are solely reflected in the separate storage location, and they have no effect on where the function is invoked.