Docsity

Assignment 2 C language, Assignments of Procedural Law

Toggle sidebar
bg1
ASSIGNMENT 2
Qualification
BTEC Level 5 HND Diploma in Computing
Unit number and title
PROG102: Procedural Programming
Submission date
10/11/2021
Date Received 1st
submission
12/11/2021
Re-submission Date
21/11/2021
Date Received 2nd
submission
21/11/2021
Student Name
Phan Minh Tiến
Student ID
GCD201914
Class
GCD1001
Assessor name
Phan Thanh Trà
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
Tiến
Grading grid
P5
M3
M4
D2
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17

Partial preview of the text

Download Assignment 2 C language and more Assignments Procedural Law in PDF only on Docsity!

ASSIGNMENT 2

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title PROG102: Procedural Programming

Submission date 10 /11/2021 Date Received 1st submission 12/11/

Re-submission Date 21/11/2021 Date Received 2nd submission 21/11/

Student Name Phan Minh Tiến Student ID GCD

Class GCD1001^ Assessor name Phan^ Thanh Trà

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 Tiến

Grading grid

P 4 P 5 M3 M4 D

 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

CHAPTER 4: PRACTICE AND RESULTS

4.1 C source files in the design program

-In this program:

  • The name of function, array and constant are used by camelCase.

  • Some variables are used by PascalCase, example: YourChoice, ChoiceNext.

camelCase is a naming convention in which the first letter of each word in a compound word is capitalized, except for the first word. PascalCase is similar to camelCase, which capitalizes the first letters of all words in a compound word, including the first word.

Both coding standards are useful in programming since element names cannot contain spaces. The naming convention makes compound names more readable.

4.1.1 Function 1: Input ID and Grade

Figure 1: Input ID and Grade

In this function, the first thing I do is declare the arrays of IDs and arrays of grades. then I create a request that forces the user to select the number of students to enter, then I continue to use "scanf" so that the user can enter student IDs and grades. At first, the user will have to enter the total student of class. When the number of total students is inserted, the for loop is also created. To create a list of students, using for loop in the array of ID and grade can make easily for user to enter information of student from the keyboard: IDs, grades and check previous ID at the same time.

4.1.3 Function 3: Highest Grade

Figure 3: Find out the student with the highest score

To determine which student has the highest score, first construct and assign the variable gradeMax, which indicates that the first student has the highest grade, and then use the for loop to compare each grade in the list of students from first to last. If a grade is higher than the preceding grades, it is added to maxGrade. The value of maxGrade will then be returned by programming. Then I will use one more for loop to simultaneously print out the students with the highest score after finding out.

4.1.4 Function 4: Lowest Grade

Figure 4: Find out the student with the lowest score

To determine which student has the lowest score, first construct and assign the variable gradeMin, which indicates that the first student has the lowest grade, and then use the for loop to compare each grade in the list of students from first to last. If a grade is smaller than the preceding grades, it is added to minGrade. The value of minGrade will then be returned by programming. Then I will use one more for loop to simultaneously print out the students with the lowest score after finding out.

4.1.5 Function 5: Get choice from user

4.1.6 Fuction 6: Main

Figure 6: Main

The switch-case statement is used in main to act on your choice. If you select 1, the enter list of students function is enabled, which is comparable to the other options. The main portion is also where all of the functions will take place.Moreover, I use the do-while statement to avoid infinite loop, with a condition that choice is different from 5, if it is equal to 5, the program will exit.

4.2 RESULTS FOR THE CASE DATA 1:

-In this case, we will run the program with the correct data and special data to test the program for

errors.

-Firstly, when accessing the program, the system will display a menu with many options. Function

menu to display the menu to help users select what to do. So, users need to select from 1 to 5

options available in the menu depending on their needs.

-For instance:

  • Press number 1 to create a list of students where the ID and score of each student

will be stored.

  • Press number 2 to print out the list of students you entered in step 1.

  • Press number 3 to find out and print the student with the highest score.

  • Press number 4 to find out and print the student with the lowest score.

  • Press number 5 to exit program.

Figure 7: Choose option 1 to create a list of students

After performing the above operations, data will be saved to a system. Then, the menu will be

displayed again for the user to perform the next operation. Next, press 2 to print the list and scores of the students you entered in step 1.

Figure 9: Choose option 2 to print ID and Grade

After you have entered the IDs and grades of all the students you need to enter. With option 3, the computer will find out who has the highest score. Then print out a list of students with the highest score.

Figure 10: Choose option 3 to find the student with the highest score

4.3 TESTING DATA CASE

4.3.1 Test schedule

Test case

Start date End date Intend time (hour)

4.3.2 Test Result

Test case

Test data Expected results Actual result Passed/Failed

1 Enter the number of student: 4

Enter the number of student: 4

Passed

2 Enter the number of student: - 10

Return to the options menu to re-enter another option.

Passed

3 Enter the number of student: c

Invalid number of student. Please enter a number greater than 0!

Failed

4 Enter your options: 1

Enter your option: 1 Enter the number of students

Passed

8 Input Grade: 1000

Please enter your grade again! Your score only runs from 0 to 10 points.

Failed

4.4 UNEXPECTED RESULTS

In addition to the above expected successful results, there are still some unexpected results after testing the data as follows:

Test case 3: Failed

when you test this data! You enter the number of students as any letter! and what you would expect is that it will tell you that you entered it incorrectly and ask you to go back to the number of students to enter the correct selection, which is the numbers.

But as a result it creates infinite loops. because you haven't validated the limit for the number of students you enter it will run infinite loops.

Figure 13: Result of enter wrong the number of student

Test case 6: Failed

when you check this data! You fill in your choices with any letters! and what you expect is it will tell you that you entered it wrong and ask you to go back to the menu to enter the correct choice which is the numbers.

But as a result, it creates infinite loops. because you haven't validated the limit of options you enter, so it will run infinite loops.