Introduction to Procedural Programming, Exercises of C programming

A math teacher wants to manage grades of a class. He asks you to help him to write a small application to do that. He needs to enter student IDs, student’s grades and store these information into 2 separate arrays (integer array for IDs and float array for grades). Then he needs to print all student IDs together with their grades. Finally, he needs to know which student has highest grade and lowest grade. Your program should be menu based with the options above.

Typology: Exercises

2020/2021

Uploaded on 11/05/2021

huynh-chi-bao-fgw-ct
huynh-chi-bao-fgw-ct 🇻🇳

4.8

(23)

13 documents

1 / 17

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1 | P a g e
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Prog102: Procedural Programming
Submission date
October 26
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Huynh Chi Bao
Student ID
GCC200363
Class
GCC0904
Assessor name
Le Huynh Quoc Bao
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
Huynh Chi Bao
Grading grid
P1
P2
P3
M1
M2
D1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff

Partial preview of the text

Download Introduction to Procedural Programming and more Exercises C programming 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 October 2 6 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Huynh Chi Bao Student ID GCC 200363 Class GCC^0904 Assessor name Le Huynh Quoc Bao 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 Huynh Chi Bao Grading grid P1 P2 P3 M1 M2 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date: Lecturer Signature:

Assignment 1

I. Introduction

1. Provide an introduction to procedural programmingIntroduction to computer programming languages  Programming language theory is an unusual case in the domain of theoretical computer science, being an almost perfect example of the kind of bridges that can exist between theory and practice by going from the realm of the very abstract mathematical concepts of semantics to their practical implications in software engineering.  Moreover, programming languages are so central to computer science that one could almost assert that system design amounts to programming language design. Every user or program interface is defined by a small language, whether concrete, as in button clicks or shell commands, or abstract, as in module specifications. (Meyer, 1990)  Introduction about procedural programming  Procedural programming is a programming paradigm built around the idea that programs are sequences of instructions to be executed. They focus heavily on splitting up programs into named sets of instructions called procedures, analogous to functions. A procedure can store local data that is not accessible from outside the procedure’s scope and can also access and modify global data variables.  Some of the earliest procedural programming languages were Fortran and ALGOL. Ideas developed in ALGOL are very much relevant and prevalent in modern-day programming languages. (deepsource.io) 2. Discuss on characteristics and features of procedural programmingCharacteristics of procedural programming  Procedural programming follows a top-down approach.  The program is divided into blocks of codes called functions, where each function performs a specific task.  Procedural programs model real-world processes as 'procedures' operating on 'data'.  The data and functions are detached from each other.  The data moves freely in a program.  It is easy to follow the logic of a program.

 A function can access other function's data by calling that function. ( knowledgeboat.com)  Key features of procedural programming The key features of procedural programming are given below:  Predefined functions : A predefined function is typically an instruction identified by a name. Usually, the predefined functions are built into higher-level programming languages, but they are derived from the library or the registry, rather than the program. One example of a pre-defined function is ‘char at ()’, which searches for a character position in a string.  Local Variable : A local variable is a variable that is declared in the main structure of a method and is limited to the local scope it is given. The local variable can only be used in the method it is defined in, and if it were to be used outside the defined method, the code will cease to work.  Global Variable : A global variable is a variable which is declared outside every other function defined in the code. Due to this, global variables can be used in all functions, unlike a local variable.  Modularity : Modularity is when two dissimilar systems have two different tasks at hand but are grouped together to conclude a larger task first. Every group of systems then would have its own tasks finished one after the other until all tasks are complete.  Parameter Passing : Parameter Passing is a mechanism used to pass parameters to functions, subroutines or procedures. Parameter Passing can be done through ‘pass by value’, ‘pass by reference’, ‘pass by result’, ‘pass by value-result’ and ‘pass by the name’. (hackr.io) II. Analysis: Identify the program units and data and file structures required to implement a given design

1. Identify the variables and data type required in the program No. Variables Data type Describe 1 ID[] Integer The array used to store ID data set of students declared with the data type is integer. It makes it easy to identify in the array. 2 Grade[] Float The array used to store the point data set , and it is declared with the float data type because the point can be a decimal number. 3 Min Float The variables used to store grade of student have the lowest grade in that array, it is declared with type float.

Therefore, it will be suitable for programs with few choices. The IF statement is necessary because it is a decision-making statement that instructs a program to make decisions based on specific criteria. It is used when finding the student with the highest and lowest score. “Switch statement “ Switch (expression) { Case item1: // one or more statement; break; Case item2: // one or more statement; break; Case item3: // one or more statement; break; default: // one or more statement; } A switch statement, in C#, is a selection statement that allows for the transfer of program control to a statement list with a switch label that corresponds to the value of the switch expression. A switch statement is a control statement that executes a set of logic based on the result of a comparison between a controlling expression and the labels specified in the switch block. This type of statement helps in allowing the value of a variable or expression to select the code block for

execution from a list of candidates that represent the different possibilities that can occur. (techopedia.com) It is used in menu section based on options.

3. Identify and describe any iteration constructs Selection structures Describe “for” loop for (initialization; condition; increment/decrement) { // one or more statement; } The for loop in C language is used to iterate the statements or a part of the program several times. It is frequently used to traverse the data structures like the array and linked list. (javatpoint.com) “For “loop statement is necessary because it needs to iterate until the maximum or minimum value is found. It is used when finding the student with the highest and lowest score.

2. A use case diagram for actions required

3. Flow chart diagramsMenu operation

Printing IDs and grades

Finding max grade

IV. Review

1. Advantages of procedural programming.

  • One glaring advantages of procedural programing is the ability to jump right into coding a program without the need to create any objects or classes. Many programmers prefer this method because they want to be able to write small amounts of code in a short or html pages with basic data displays.
  • The top down structure is also an advantage for those who prefer to work their way through a program vs planning the program out before the development process. 2. Disadvantage of procedural programming
  • A major disadvantage is the difficulty in error checking. In procedural programming the code in continuously broken down into smaller manageable pieces until the different problem or function more different as the code gets longer and longer.
  • The program code of a procedural programming language is much more difficult to write than to use. Requires the coder to have a lot of knowledge to master it. 3. Design evaluation
  • Regarding the flowchart: It makes it easier to understand the steps to implement the solutions to program execution and based on that we can make the C procedural programming solution faster and easier. However, it is still time consuming and if the flowchart goes wrong, it will be cause the program to crash.
  • C code or algorithm in procedural programming is generally good for the model but quite different to write to them. Furthermore, they become difficult to follow and become more of a hassle when we use one or more nested code.
  • Procedural C programming is easy to implement compiler and interpreter.
  • Like many other programs, the problem of programing language is always a problem for programmer. 4. Solution
  • Data in procedural programming should be kept confidential.
  • Need to expand the language in C procedural programming.
  • Optimizing procedural programming by introducing new codes or algorithms to the needs of modern life as well as customers, of course the must be easy to understand and implement.

References Meyer, B., 1990. Introduction to the theory of programming languages. s.l.:Prentice-Hall, Inc.. https://deepsource.io/glossary/procedural-programming/ https://www.knowledgeboat.com/question/what-are-the-characteristics-of-procedural-programming-- 28311496451138200 https://hackr.io/blog/procedural-programming https://www.cprogramming.com/tutorial/c/lesson2.html https://www.techopedia.com/definition/22412/switch-statement-c https://www.javatpoint.com/for-loop-in-c