Download Procedural Programming: A Practical Guide for BTEC Level 5 HND Diploma in Computing and more Assignments Information Technology 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 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Dinh Xuan Truong Student ID GCH Class GCH0908 Assessor name Nguyen Tran Dinh Long 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 Truong Grading grid P1 P2 P3 M1 M2 D
Summative Feedback: Resubmission Feedback:
Grade: Assessor Signature: Date: Lecturer Signature:
Introduction
Definition:
Procedural programming is the first program a programmer will have to learn. A
programming language is a formal language comprising a set of strings that produce
various kinds of machine code output. Simply put, procedural programming involves
writing down a list of instructions to tell the computer what it should do to finish the task.
Procedural Programming
Some typical programming languages:
C++: C++ is a general-purpose programming language created by Bjarne Stroustrup as
an extension of the C programming language
Python: Python is an interpreted high-level general-purpose programming language. Almost, programs language have file extension corresponding such as Python is .py, Ruby is .rb…..
Every language has strengths and weaknesses:
Most programming languages have the same strengths and weaknesses. For example:
❖ C++: Powerful objects and it is the language that you learn first in university. But it
is quite complex and difficult to learn.
❖ Pascal: Is the good program to learn, but it is not as flexible as C++
The features of procedural programming:
- 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.
- Global Variable: A global variable is a variable that is declared outside every
other function defined in the code.
- Parameter Passing: Parameter Passing is a mechanism used to pass parameters
to functions, subroutines, or procedures.
- Predefined functions: A predefined function is typically an instruction
identified by a name. One example of a pre-defined function is ‘charAt()’,
which searches for a character position in a string.
- Modularity: Modularity is when two dissimilar systems have two different
tasks at hand but are grouped together to conclude a larger task first.
The characteristics 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.
Example:
Declaring float variable float grade; Declaring integer variable int time, speed; Declaring character variable char var; Declaring string variable: Char StudentID[30][15]; Char fullname[50][50]
After declare a variable, you can print it in screen. Example:
INPUT
#include <stdio.h>
main () {
int age = 19;
float grade;
grade = 9.2;
char gender;
printf("Age : %d",age);
OUTPUT
Age : 19
Normally, in command ‘printf’,
Int will be ‘% d ’ or ‘% i ’,
For String, it will be ‘%s’. In C++, will not have variable ‘string’.
[30] is character limit in this variable
Get info from keyboard:
For Int, Float Use ‘scanf’ to get characters from keyboard. For Char, String Use ‘gets’ or scanf(“%[^/n]s) to String, use getchar to Char. [30] make this list for variable name, each containing up to [ 30 ] characters
Switch-case
- Is a control and branching construct that can be completely replaced by an if else. Using switch case in this project will make it easier to read and understand.
- Note: if there is no break in the case statement, the program will execute the statements in the next cases until it meets the break statement.
Fflush(stdin)
To clear the program's temporary memory for the above garbage values to do not occur.
While-loop
For the first request, we should choose a do-while loop. Do-while will check for conditions that do not satisfy the problem. If it’s not satisfy the problem, it will check again until user enter correct request.
For-Loop When you know exactly how many times you want to loop through a block of code, use the for
- Unlike while loop, for loop is used to iterating over a sequence.
- Have 3 statements. Statement 1 is the first number, statement 2 is the last number you put it in, and statement 3 is higher or lower by use i++ or i--. Here is an example that use for to print number from 1 to 10.
Grade[] Float array Scan number of Grades Name[] [] String Scan list of Names i Integer Using for for-loop function n Integer Scan number students choice Integer Using for switch-case to selection items from menu max Float Scan highest grade min Float Scan lowest grade check Boolen To check. If user didn’t input information first. Another option could not use. Variable, data types will use Structures: Structures Reason why use Illustration If else Find highest and lowest score Switch
- case Using for menu While- loop To check total students , to loop menu if user want to use
another option For- loop Input info of students and print it Structures will use
Review
WBS:
WBS - WBS to breakdown a problem into small ones.