Assignment 1 Front Sheet

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 27

ASSIGNMENT 1 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title Unit 0: Procedural Programming

Submission date 17/06/2020 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name PHAN ANH LY LY Student ID GCD191295

Class PRO101 – GCD0806 Assessor name QUYNH TRAN LY

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 LyLy

Grading grid
P1 P2 P3 M1 M2 D1
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
Chapter 1: PROBLEM STATEMENT
1.1 SCENARIO

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.
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.

1.2 REPORT OBJECTIVES


This report aims to show the basic definitions of procedural programming,
importing, exporting information, arranging and finding student information.
CHAPTER 2: PRINCIPLES OF PROCEDURAL PROGRAMMING

1.3 COMPUTERS & PROGRAMS


1.3.1 Computers & Programs

The idea of an internally stored program was introduced in the late 1940s by the
Hungarian-born mathematician John von Neumann.
They consist of a CPU (the part that executes instructions), the Memory (the part
where programs and data are stored), the bus (the wire connecting all components), and
the peripherals (input and output devices).

Figure 1

A computer program is a collection of instructions that perform a specific task when executed
by a computer.

1.3.2 What is coding and how does computer work?


People who work with computer and make code called programmers, coders or
developers.
Computers have their own language called Machine Code which tells them what to
do. As you can see, it doesn’t make a lot of sense to humans!
Coding is the process of using programing language to make computer understand
what we want and to behave how we want.

Almost all programming languages work the same way:


 You write code to tell it what to do: print(“Hello there !”).
 The code is compiled, which turns it into machine code the computer can understand.
 The computer executes the code, and writes Hello there ! back to us.

Figure 2

1.4 INTRODUCTION TO PROCEDURAL PROGRAMMING


1.4.1 Simple Program
Now we have a simple program about input your name and display it.

 Firstly: we need to enter our name into program.


 Secondly: the computer will run and display it on your screen.

Figure 3

 Input: your name has been entered from keyboard.


 Output: your name has been displayed on your screen.

Figure 4

1.4.2 Variable

A variable is a symbolic name for (or reference to) information. The variable's name
represents what information the variable contains. They are called variables because the
represented information can change but the processes on the variable remain the same. In
general, a program should be written with "Symbolic" notation, such that a declaration is
always true symbolically.
Local variable

local variable has a limited scope, it's only exist in block which has been declared but when the
block ends, the variable is destroyed and its values are lost.

Figure 5

Global variables
Global variables are useful for values that are relatively constant, or that many functions in
the script must access, such as a session id.

Figure 6

parameter
A parameter is normally a constant in a single simulation, and is changed only when you
need to adjust your model behavior

Figure 7

1.4.3 Three constructions (sequence, selection, iteration with 6 statements)


There are three basic building blocks to consider:

Sequence

Sequence is the order in which instructions occur and are processed

Selection

Selection determines which path a program takes when it is running

Iteration

Iteration is the repeated execution of a section of code when a program is running.

6 statements:

Do (…) while statement:


Figure 8

If (…) statement:

Figure 9

For (…) statement:

Figure 10

If (…) else statement:

Figure 11
Else if (…) statement:

Figure 12
Switch (…) case statement:

Figure 13

1.4.4 Function
A function is a set of statements that take inputs, do some specific computation and
produces output.

Figure 14

1.4.5 Value passing (parameter)

Passing a value-type variable to a method by value means passing a copy of the variable to
the method
Figure 15

1.4.6 Parameter passing (Pointer)


Just like any other argument, pointers can also be passed to a function as an argument.

Figure 16

1.4.7 Modularity.

Modularity is one measure of the structure of network or graphs. It was designed to measure


the strength of division of a network into modules (also called groups, clusters or communities).
CHAPTER 3: DESIGN PROCEDURAL PROGRAMMING SOLUTIONS

3.1 Identify Input, Output: variables and data types and its scope.
3.1.1 In/Out variables: take print struct of student
Input:

Input choice: input the choice of the menu.

Input n: input number of students.

Input student detail about name, ID, grades.

Output:

Display the simple table of student detail.

Display student who has lowest and highest grade

Display a student with ordinal number you want

3.1.2 Main Variable

Figure 17

Int choice: The choice variable of menu, use int type because choice from 1-6

Scope: variable in main (): local variable

Input for getting the choice for the table and then run the table base on the input.

Int n: the variable of number of students

Scope: variable in main (): local variable

Input for getting the number of students from the list, suppose to calculate and run loop.
In max and min:

Scope: variable in main (): local variable

Use for store the variable of local max and min grade.

3.1.3 Switch – case / Selection variables:


This program uses the switch for creating the menu for user. Based on the function, using press
from 1 to 6 to select them.

Figure 18

3.1.4 Variables outside the main function (Local or parameter)


In struct: int id, float grade

They are local variable inside the struct function.

Declare the member definition in struct.

Use for saving the value of id and grade when enter from the keyboard.
Figure 19

Use student studentList[] and int n in whole of function for calculate using the information about
student.

They are parameter variable.

student studentList[] meaning array of student and int n is number of member.

Using float max, float min and int count for calculate the local of student have max and min grade.

They are local variable.

Highest and lowest for calculate, after that save the local to maxMark and minMark.
3.1.5 Switch-case statement
Input is choice.

Output base on case:

Case 1: Use for enter list of students.

Case 2: Use for display list of students.

Case 3: Use for display a student with ordinal number enter from keyboard.

Case 4: Use for display student who has highest grade.

Case 5: Use for display student who has lowest grade.

Case 6: For exit.

Default for enter wrong type of choice.


3.1.6 If-else statement
Using if for calculate highest and lowest mark: save in local in maxMark and minMark.

3.1.7 for statement


Use for run loop to calculate and display:

For calculate

Input ID, grades, highest and lowest grades.

Output is highest and lowest grades local.

The purpose of the for loop in this case is used to scan the list of students, for each student in list, I also
access the value too.
For display:

Display list of students with ID and grades:

3.1.8 Do-while statement


Use for check the condition of id and grade

In here ID must be > 0 and 0 < grades ≤ 10.

If enter wrong user need to type it again.

- Use for keep running the menu after one choice:


Make user enter the choice again
3.1.9 Sub functions and hierarchy diagram of the program.
3.1.10 Input ID and grades: int ID and float grades.
3.1.11 Get choice from user: int choice

3.1.12 Enter and create list of students


3.1.13 Find highest and lowest grades

3.1.14 Select keys menu

3.1.15 Design a procedural programming solution for a given problem.


3.1.16 Use-Case diagram
Teacher is a user can have 5 permisson:

 Can know highest grade.


 Can know lowest grade.
 Can find a student.
 Can enter ID and grades of students.
 Can display student detail.

3.1.17 Flow chart diagrams


INDEX OF COMMENTS

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................

.......................................................................................................................................................................
.......................................................................................................................................................................

You might also like