ASSIGNMENT 2 FRONT SHEET Qualification BTEC Level 5 HND Diploma in Computing Unit number and title PROG102 Procedural Programming Submission date Date Received 1st submission Re submission Date Date R.
Trang 1ASSIGNMENT 2 FRONT SHEET
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
Trang 2 Summative Feedback: Resubmission Feedback:
Lecturer Signature:
Trang 3ASSIGNMENT 2 GUIDE
1 Implementation (P4, M3)
Declaring libraries used in program
#include <stdio.h>
<stdio.h>: Provide the core of the typing capabilities in C
intinputsvID(charID[][10]);
voidinputgrade(floatgrade[], intn);
voidmax(charstudentID[][10], floatstudentgrade[],intn);
voidmin(charstudentID[][10], floatstudentgrade[], intn);
voiddisplayall(intnumstudent);
Declaring variables used in program: Int main(void) is a variable to declare main() function used in the program Int means that main() can only return integer values
Void has the effect of specifying the main() function to return no value
intmain (){
charID[50][10];
floatgrade[50];
intn = inputsvID(ID);
inputgrade(grade, );
floatstudentgrade;
max(ID ,grade, );
min(ID ,grade, );
intnumstudent;
}
Int: This is an integer; it basically represents the natural size of the integer It is used to set variables a, c, option, ID
in the program
Trang 4•Float: This is a real number type, used to store floating point numbers For example 2.5 and 5.6 are real numbers It
is used to declare the variable Sgrade in the program
char: this is the character type used in Name
voiddisplayall(intnumstudent){
printf("Total number of student: %d",numstudent);
for (int = 0 i < numstudent; i++){
}
}
We create a function void displayall(int numstudent) used to input data from the keyboard for arrays In the function
we use a for loop starting from int i =0 and ending when i<n, in The for loop then enters the student's data
INPUT ID:
intinputsvID(charID[][10]){
intn =0;
printf("Input student ID: ");
//printf("Student ID must be greater than 0!\n");
scanf("%d", &n);
for(int = 0 i < n i++ ) {
printf("Enter ID:");
scanf("%s", ID[i]);
}
returnn;
}
INPUT GRADE:
voidinputgrade(floatgrade[], intn){
printf("Input grade\n");
// printf("Grade greater than 0 and lower than 10");
Trang 5for (int = 0 i < n i++) {
printf("Enter grade: ");
scanf("%f", &grade[i]);
}
}
MAX:
voidmax(charstudentID[][10], floatstudentgrade[], intn) {
printf("Student ID: ");
floatmax = studentgrade[0];
printf("Has the highest grade %.2f\n", max);
for (int = 0 i < n i++) {
if(max <= studentgrade[i]) {
max = studentgrade[i];
}
}
for(int = 0 i < n i++){
if(max == studentgrade[i]){
}
printf("%s", studentID[i]);
}
}
We initialize the void function void max(char studentID[][10], float studentgrade[], int n) used to find the largest value in the array In the function we declare the variable int Max = studentgrade[0] used to assign the maximum value of the array, we use a for loop that starts at int i =0 and ends when i<n and each time i increases one to traverse each element in the array In the for loop we use if with the condition that if studentgrade[0].averade is greater than Max then we assign the value of Max = studentgrade[i].; At the end of the for loop, we print Max to the screen
MIN:
voidmin(charstudentID[][10], floatstudentgrade[], intn){
printf("Student ID: ");
floatmin = studentgrade[0];
for (int = 0 i < n i++){
Trang 6printf("Has the lowest grade %.2f", min);
if(min >= studentgrade[i]){
min = studentgrade[i];
}
}
for (int = 0 i < n i++){
if(min == studentgrade[i]){
printf("%s", studentID[i]);
}
}
}
We initialize the void function void min(char studentID[][10], float studentgrade[], int n) used to find the largest value in the array In the function we declare the variable int Min = studentgrade[0] used to assign the minimum value of the array, we use a for loop that starts at int i =0 and ends when i<n and each time i increases one to traverse each element in the array In the for loop we use if with the condition that if studentgrade[0].averade is greater than Min then we assign the value of Min = studentgrade[i].; At the end of the for loop, we print Min to the screen
2 Program results (P4)
Show screenshots of your program in running
- Starting the program will appear the number of students that you choose for you to choose to start
- When you have finished entering the number of students, you will enter the All Student IDs first and go to the Score
Trang 72.2
- When entering the ID, the score will display the updated information
It will then display the student information and show the student ID with the highest and lowest scores
If two or more students have the same highest or lowest score, it will show both or more students
3 Testing (P5, M4)
Write test plan and perform tests to get results Show test log
Analyse test results in test log
4 Evaluation (D2)
Evaluate your program, state lessons learnt and future improvements
Evaluate how procedural programming is applied in your program (advantages, disadvantage, difficulties)