Download as pdf or txt
Download as pdf or txt
You are on page 1of 15

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title PROG102: Procedural Programming

Submission date 6/7/2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Nguyễn Hải Việt Student ID

Class GCD1101 Assessor name Phạm Thanh Sơn

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

Grading grid

P4 P5 M3 M4 D2
 Summative Feedback:  Resubmission Feedback:
2.1

Grade: Assessor Signature: Date:


Lecturer Signature:

Contents
CHAPTER 1: IMPLEMENTATION (P4)............................................................................................................................. 3
1. INTRODUCTION ..................................................................................................................................................... 3
1.1 Scenario .......................................................................................................................................................... 3
2.2 Solution ........................................................................................................................................................... 3
2. IMPLEMENTATION ................................................................................................................................................ 3
2.1 Library Declaration.......................................................................................................................................... 3
2.2 Variables and Data Types ................................................................................................................................ 5
2.3 Display Menu .................................................................................................................................................. 5
2.4 “Input Student Information” Function ........................................................................................................... 6
2.5 “Display List Of Student” Function.................................................................................................................. 6
2.6 “View Highest Student Grade” Function ........................................................................................................ 7
2.7 “View Lowest Student Grade” Function ......................................................................................................... 7
3. ALGORITHMS ........................................................................................................................................................ 8
4. PROGRAM RESULT ................................................................................................................................................ 9
CHAPTER 2: TESTING (P5) ........................................................................................................................................... 11
Figure 1: Library Declaration......................................................................................................................................... 3
Figure 2: Variables and Data Types............................................................................................................................... 5
Figure 3:Display Menu .................................................................................................................................................. 5
Figure 4: Menu Option .................................................................................................................................................. 6
Figure 5: Student Information ...................................................................................................................................... 6
Figure 6: Display Student .............................................................................................................................................. 7
Figure 7: View Highest Student Grade .......................................................................................................................... 7
Figure 8: View Lowest Student Grade .......................................................................................................................... 7
Figure 9: Example Do While Loop ................................................................................................................................. 8
Figure 10: Example Switch Case ................................................................................................................................... 9
Figure 11: Example If Else conditional statement ........................................................................................................ 9
Figure 12: Program Menu ........................................................................................................................................... 10
Figure 13: Select Option 1........................................................................................................................................... 10
Figure 14: Select Option 2........................................................................................................................................... 10
Figure 15: Select Option 3........................................................................................................................................... 10
Figure 16: Select Option 4........................................................................................................................................... 11
Figure 17: Select Option 5........................................................................................................................................... 11

CHAPTER 1: IMPLEMENTATION (P4)

1. INTRODUCTION
1.1 Scenario
I received a request from a teacher to create a program that can manage student information. In the
program, teachers can view and enter student information. The program also has a place to store student
information such as grades, IDs. Besides, the program can also help teachers find out the students with the highest
scores and the students with the lowest scores.

2.2 Solution
In assignment 1, I introduced procedural programming, some information about the commands I use to
create the program, and explained how they work so that the program can store IDs and scores. students and
output to the screen. I will now go into more depth about how I created this program, including graphics, tables,
and most importantly, detailing the main command line functions.

2. IMPLEMENTATION
2.1 Library Declaration

Figure 1: Library Declaration


- #include "stdio.h": This library employs "streams" to communicate with any sort of system-accepted
file as well as with physical devices like keyboards, printers, and terminals. A simplified approach to
interact with them is through streams. Regardless of the unique qualities of the physical medium they
are linked to, all streams have comparable attributes. This library defines most of the C
fileinput/output routines.
- #include "stdlib.h": This library includes a number of macros, four different variable types, and a
number of functions for performing general operations. This library is what I use to pause the screen,
clean the screen, and end the program.
2.2 Variables and Data Types

Figure 2: Variables and Data Types

The Data Type that I use in this program is integer and real number, it is abbreviated as "int" and "float".

• n : The variable “n” I use in the program is used to store the number of students entered.
• choice: The “choice” variable I use in the program is used to save the choice in the menu and
execute the appropriate cases.
• MaxGrade, MinGrade, HighestGrade,LowestGrade: These variables are used to store the price
when performing the search for the student with the highest and lowest scores in the program.
• StudentID[100]: It is used to store a list of student IDs.
• StudentGrade[100]: It is used to store a list of student’s grades.

2.3 Display Menu

Figure 3:Display Menu

The viewmenu() function is created using the printf() statement. It outputs menus and options that the user can
choose to use. I also use a Switch case so that the program can run the requests the user wants and ignore the
others. Besides, I use While loop to be able to repeat the commands requested by the user until the user wants to
end the program.
Figure 4: Menu Option

2.4 “Input Student Information” Function


The purpose of this function is to enter the number of students, their grades and IDs. To run the program, I
use a loop to run from i=0 to i<n so that the program can run. In the loop, "i+1' helps me to always print the
first student. After entering the score I continue to use the condition to check if it is valid or not to be output to
the screen. If it's wrong, I have to re-enter it.

Figure 5: Student Information

2.5 “Display List Of Student” Function


The purpose of the function is to view the list of student IDs and grades.

I create the for loop with printf() function to repeat printing out One by one value of 2 arrays StudentID
and StudentGrade until the loop equal to the number of students that the user entered.
%d and %f represent StudentID[i] and StudentGrade[i]. Besides, I also use margins to make printing
more accurate. Example "%5d%21.1f".

Figure 6: Display Student

2.6 “View Highest Student Grade” Function


The purpose of this function is to determine and output to the screen the student with the highest score. I assign
student IDs and grades to MaxID and HighestGrade. Then I used a for loop from student 2 to student n-1 to check.
If StudentGrade [i] > HighestGrade, the program will output the ID and score of the student with the highest score.

Figure 7: View Highest Student Grade

2.7 “View Lowest Student Grade” Function


The purpose of this function is to determine and output to the screen the student with the highest score. I assign
student IDs and grades to MinID and LowestGrade. Then I used a for loop from student 2 to student n-1 to check. If
StudentGrade [i] > LowestGrade, the program will output the ID and score of the student with the highest score.

Figure 8: View Lowest Student Grade


3. ALGORITHMS
Mathematical calculations in C language are relatively basic and simple, so when writing a program, it must be clear
and reasonable for the program to run smoothly.

While and do-while loops are used in a program to execute program choices. It saves us from having to rewrite many
times, making the program more complicated. When the condition is met, the program will pause the loop and
move on to the next step. For example in the exercise, if a student's score and ID is the highest that matches the
given condition, it will output that student's information screen.

Figure 9: Example Do While Loop

For the switch case statement, it will act like an if-else structure, but in some cases there are multiple
conditional statements to execute. It would be simpler to generate and read our code if we used a
switch case. It also takes less time in rewriting multiple times. There will be a large number of options in
the program, from 1 to 5. There is a default case for switch cases that will be run if none of the cases
match the value of the condition and generate the error indicates that the user has provided an
incorrect condition.

Figure 10: Example Switch Case

Besides, it is also indispensable for the if else conditional statement. In the program it helps us to find the
student with the highest and lowest grade.

Figure 11: Example If Else conditional statement

4. PROGRAM RESULT
This is the program's menu, which has been created with an intuitive interface suited for all novice users.
The relevant data input will be made by the user. The system will initially display all five function
possibilities to you; select one of them to initiate the function. Your job is to enter the appropriate request.
Figure 12: Program Menu

A notification asking the user to enter a number of pupils shows on the screen when the user chooses
option 1. User-selected choices and statements for student information entry are shown.

Figure 13: Select Option 1

When the user chooses option 2, the program will display on the screen all the student's information
including the student's grade and ID.

Figure 14: Select Option 2

When the user does option 3, the program will display on the screen the student with the highest grade.

Figure 15: Select Option 3


When the user does option 4, the program will display on the screen the student with the lowest grade.

Figure 16: Select Option 4

When the user selects option 5, the program will be closed. Enter any key to exit the program.

Figure 17: Select Option 5

CHAPTER 2: TESTING (P5)

Test Pass
Test Content Test Data Expected Actual Result
Case /Fail
Enter wrong Show enter
Input a
choice (choice error and re-
1 number other PASS
<=0 or choice > enter
than 1,2,3,4,5
5)
Enter any Show enter
Enter wrong
negative error and re-
2 StudentID FAIL
number or any enter
value
letter
Enter a
Show enter
Enter wrong number
error and re-
3 Grade greater than PASS
enter
value 10 or less than
0
Input a The program
Enter the
number returns to re-
wrong number
4 greater than enter the FAIL
range of
100 or less number of
students
than 0 students
The program
reported a
Enter duplicate Enter
mistake and
5 student ID duplicate ID in FAIL
re-entered
entered before a program
the student
ID

Check exit The program


6 Enter option 5 PASS
program stops

The program
Enter student
correctly
7 Check ID ID that match PASS
received the
the program
input data

Enter student The program


grade that correctly
8 Check Grade PASS
match the received the
program input data

Check and
output all The program
Enter student
student correctly
9 data and select PASS
information outputs all
option 2
input data

The program
Check the Enter student outputs the
student with information correct
10 PASS
the highest and select student with
grade option 3 the highest
grade
The program
Check the Enter student outputs the
student with information correct
11 PASS
the lowest and select student with
grade option 4 the lowest
grade

Enter the The program


Check input characters in reports an
12 FAIL
data type the "Enter your error and re-
choice:" . enters
Powered by TCPDF (www.tcpdf.org)
Index of comments

2.1 1. What is good


- You can write a program that implements the designed solution.
2. What is not good
- Your test case should have the expected value to be compared with the actual value. Your expected value must
be clear, precise, and comparable with the actual value
- Some expected value is not exactly as actual value but you write that the test case is passed for example the
expected value you want is "Show enter error and reenter" but your actual result didn't show any message about
"enter error"

Powered by TCPDF (www.tcpdf.org)

You might also like