











Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
The work has been graded Merit.
Typology: Assignments
1 / 19
This page cannot be seen from the preview
Don't miss anything!
Qualification BTEC Level 5 HND Diploma in Computing Unit number and title Prog 102 : Procedural Programming Submission date 30/06/2021 Date Received 1st submission Re-submission Date Date Received 2nd submission Student Name Nguyễn Tứ Hải Student ID GCH Class GCH0908^ Assessor name Nguyễn Đình Trần 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 Hải Grading grid P1 P2 P3 M1 M2 D
Grade: Assessor Signature: Date: Lecturer Signature:
Figure 4: input ID of student 2.1.3: choose 2, print the information of student: Figure 5: print the information of student: 2.1.4: choose 3, print max grade: Figure 6: print max grade 2.1.5: choose 4, print min grade: Figure 7: print min grade 2.1.6:choose 5, exit the program: Figure 8: exit.
2.2 : Explain my code: 2.2.1: library declaration: Figure 1: library declaration Explain: “#include <stdio.h>” function: it is used to efficiently search and copy the “stdio.h” file into the program. This file contains function prototypes called functions like printf(), scanf(), ... so that the compiler knows what the parameters and their return values are. “#include <stdbool.h>” function: it is used to declare “boolean” function. Boolean data type is a data type that can only take one of two values such as true/false (true/false, yes/no, 1/0) to represent two true values. “#include <ctype.h>” function: is used to declare some useful functions for checking characters.
Char name[30][21]: used to assign name of student , I set it as “char” data and set the array size to 30 and max length for each element in array to 20. Char temp_name[21]: I use to declare a temporary variable so that I can assign the temporary value of name[] with max length for each element in array to 20. 2.2.3: input () function:
Explain: First I used “bool check = true” to declare bool function to assign condition check=true.
Next I used another for-loop (for(j=0; j<length; j++)) "if-else" functions are placed in a "for" loop to repeat the program. In "if" will be the condition "isalpha(temp_name[j])" which will only allow the user to enter letters and the condition "temp_name[j]==' ' " will allow getting spaces when Enter the student's first and last name. When the value matches the conditions of “if”, the program will stop at "if" and will continue to the next section with the "continue" command. If "else" with "check=false" matches the condition in "while", it will repeat the program. Next with the true conditions, use "strcpy" stands for string copy, it allows to copy and paste the value of the temporary variable "temp_name" into the value of the primary variable "name[i]". “while (length < 5 || length > 20 || check == false))” is the condition for the loop that it will repeat if the input belongs to the above cases. Next is input ID of student:
I used “do_while” function with the condition (h[i]<1 || h[i]>30), the function will re-enter if the input belongs to the above cases. I use “scanf” to enter value from keyboard with integer variable h[i]. And the last is input grade of student: I used “do_while” function with the condition (g[i]<0 || g[i]>10), the function will re-enter if the input belongs to the above cases.. I use “scanf” to enter value from keyboard with float variable g[i]. I used “if” function have same condition with “do…while” function to print “pls input again” if fill in wrong. 2.2.4: output() function: Explain: This “for” function along with the condition to print out name of student, grade of student, and student ID. Grade uses variable “g[i]”, Id uses variable “h[i]” and name use variable “name[i]”. 2.2.5: findmax() function:
2.2.7: main() function: Explain:
I used “system("color 0A")” to change the color of console Program results. Next I declare the variable choice as an integer because let it accept only integer values, not letters and decimals. I declare bool function to assign condition flag=false. In “do…while” function, I print out the options for the user. Next I used scanf("%d",&choice) to choose option. And in switch function, I have some processing as follows: I want the user to have to enter the information first and then the other options. so I used the bool function.
If the user choose 3, first compare the value of the variable flag. If flag == true, then run findmax() function and return to the menu. Else print "You must input numbers first\n\n" and return to the menu. If the user choose 4, first compare the value of the variable flag. If flag == true, then run findmin() function and return to the menu. Else print "You must input numbers first\n\n" and return to the menu. If the user choose 5, print “exited thank !!!!” and exit the program. If the user chooses the wrong range from 1 to 5, the system will ask the user to re-enter it.