Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Assignment 2 Procedural Programming (M), Assignments of Programming Languages

The work has been graded Merit.

Typology: Assignments

2020/2021

Uploaded on 08/14/2021

UnderLine07
UnderLine07 🇻🇳

4.7

(66)

16 documents

1 / 19

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
ASSIGNMENT 1 FRONT SHEET
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
Prog102: Procedural Programming
Submission date
30/06/2021
Date Received 1st
submission
Re-submission Date
Date Received 2nd
submission
Student Name
Nguyn Tứ Hi
Student ID
GCH200244
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
Hi
Grading grid
P1
P2
P3
M1
M2
D1
Tran Doan Dung
GCH200619
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download Assignment 2 Procedural Programming (M) and more Assignments Programming Languages 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 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

 Summative Feedback:  Resubmission Feedback:

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.

  1. Testing Test case What’s being test How Data Expected result Actual result Evaluate 1 Input total Try to input boundary data, typical data, and bad data. Letters; characters (a, b, @, $,...) Invalid The program is error Fail Typical data Data accepted Data accepted Pass Decimal data Invalid invalid pass Boundary data Invalid Invalid Pass 2 Input ID Try to input boundary data, typical data, and bad data. Letters; characters (a, b, @, $,...) invalid The program is error fail Typical data Invalid Invalid Pass Decimal data Invalid Invalid Pass Boundary data Invalid Invalid Pass 3 Input name Try to input boundary data, typical data, and bad data. Letters; characters (a, b, @, $,...) Data accepted Data accepted pass Typical data invalid invalid pass Decimal data Invalid invalid pass Boundary data invalid invalid pass 4 Finding highest grade function Find the highest grade Student 1: 1 Student 2: 3 Student 3 : 5. Highest grade is : 5. Highest grade is : 5. pass 5 Finding lowest grade function Find the lowest grade Student 1: 1 Student 2: 3 Student 3 : 5. lowest grade is : 1 lowest grade is : 1 pass 6 Input grade Try to input boundary data, typical Letters; characters (a, b, @, $,...) invalid Data accepted fail
  1. Conclusion: After the course, I understood and was able to write a small program to manage student grades, despite making many mistakes and optimizing the code. I will learn from experience and try to learn to have more advanced coding skills.