Docsity

homework from a teacher, Exercises of Mathematics

Toggle sidebar
bg1
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 Received 2nd submission
Student Name Student ID
Class Assessor name
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 M
4
D2
1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13

Partial preview of the text

Download homework from a teacher and more Exercises Mathematics in PDF only on Docsity!

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 Received 2nd submission

Student Name Student ID

Class Assessor name

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 M

D

Summative Feedback:Resubmission Feedback:

Grade: Assessor Signature: Date:

Lecturer Signature:

I. INTRODUCTION: 1.Scenario

A math teacher wants to manage the grades of a class. He asks you to help him to write

a small application to do that. He needs to enter student IDs, and student grades and

store this information into 2 separate arrays (integer array for IDs and float array for

grades). Then he needs to print all student IDs together with their grades. Finally, he

needs to know which student has the highest grade and lowest grade. Your program

should be menu based on the options above. When an option is done, the program

should go back to the main menu so he can choose another option. There should be an

option to quit the program.

  1. Solution
    • Using procedural programming to write the program for the scenario. The

program needs an interface to select functions, variables and array to enter

information: names, -- ID, grade.

  • Create a menu.
  • Create separate function for input, print, find the highest and lowest.

II. IMPLEMENTATION:...........................................................................................................................................

1. Explain the program............................................................................................................................................

1.1 Library declaration:................................................................................................................................................

Figure 1 : Library

  • #include<stdio.h>: This library is uses what called streams to operate with

physical devices such as keyboards, terminals, or with any other type of files

supported for the system. Streams are an abstraction to interact with these in a

uniform way. All streams have similar properties independent of characteristics of

the physical media that they are associated with. Most of the C file input/output

function are defined in this library.

  • #include<stdlib.h>: This library defines for variable types, several macros, and

various functions for performing general functions. I use it for exit the program.

1.2 Variable and Data type.........................................................................................................................................

Figure 2 : Variables and data

  • int numberOfStudents: I use to declare the value of the total number of students.
  • int IDs[100]: Creating an integer array used to store id of students that user can

enter.

  • float sGrade[100]: Creating an array used to store grades with decimal.
  • int choose: I use to declare the value choose for the menu.

Figure 5 : switch

  • I use do while loop to repeat the user selection times until the user chose to exit

the program (case 0) with exit(0).

1.5 Input student information......................................................................................................................................

Figure 6 : enter student Id

  • First, I use a do while loop, which helps the user to input until the number of

loops is equal to the number of students to enter(n). Meaning the loop repeat

until I meet the condition i<numberOfStudent.

  • In the loop, I let the user enter the student id, “i+1” is used so that the program

start to print the 1st^ student instead of the 0th^ student, then I continue to create a

new loop with j variable and IDs[j] to check if the input id exists in the IDs[100]

array or not. If not, the program will continue to run to the next statement.

  • After the Id input is passed, I continue to create a loop to enter the student’s

grades into the sGrade[100] array, with the purpose of checking that the user’s

entered the score is correct with the rule of greater than or equal to 0 and less

more than equal to 10 or not. If the condition is passed, the input() function has

completed the task.

in each array, for example, the position of max in the sGrade[] array will implicity

correspond to position in array IDs[]. Given variable max = 0, start the loop with

the condition that if max variable value is less than another value variable then

max will be equal to that value. This statement will be executed in a loop until the

variable max value is no longer less than any value variable.

1.8 Find and display the student with lowest grade..............................................................................................

Figure 9 : Display student with Id have lowest grade

  • Same way to create array, n value to create loop and same strategy to find the

maximum value, only difference is the statement of conditional statement. Make

min variable instead of max, make it zero put in conditional statement with

condition if min variable value in sGrade[] array is greater than other value in the

same array then min will equal it and also get its id in the IDs[] array.

1.9 Exit program.........................................................................................................................................................

Figure 10 : exit

  • To exit the program we choose option 6 and the program will end.

2.Program result.........................................................................................................................................................

2.1Menu: Figure 11 : Menu output

  • The menu shows up with option from 1 to 6 for user to choose. After user choose

an option, the program show the user option.

2.2 Input students ID and grade:

Figure 12 : Option 1

  • After choosing option 1 it show the option you choose and you can enter the

number of students, their ID and grade.

2.6 exit the program:

  • After user choose option 6 the program end.

III. TEST...............................................................................................................................................................

1.Test plan...................................................................................................................................................................

  • I. INTRODUCTION:................................................................................................................................................
  • 1.Scenario.....................................................................................................................................................................
    1. Solution......................................................................................................................................................................
  • II. IMPLEMENTATION:...........................................................................................................................................
    1. Explain the program............................................................................................................................................
  • 1.1 Library declaration:................................................................................................................................................
  • 1.2 Variable and Data type.........................................................................................................................................
  • 1.3 Menu........................................................................................................................................................................
  • 1.4 Select an option.....................................................................................................................................................
  • 1.5 Input student information......................................................................................................................................
  • 1.6 Display list of students........................................................................................................................................
  • 1.7 Find and display the student with highest grade............................................................................................
  • 1.8 Find and display the student with lowest grade..............................................................................................
  • 1.9 Exit program.........................................................................................................................................................
  • 2.Program result.........................................................................................................................................................
    • 2.1Menu:..................................................................................................................................................................
    • 2.2 Input students ID and grade:.........................................................................................................................
    • 2.3 print out the student ID and grade:...............................................................................................................
    • 2.4 find the student with the highest grade:.......................................................................................................
    • 2.5 find the student with the lowest grade:.........................................................................................................
    • 2.6 exit the program:..............................................................................................................................................
  • III. TEST...............................................................................................................................................................
  • 1.Test plan...................................................................................................................................................................
  • 2.Test result................................................................................................................................................................
  • Figure 16 : Option - 1 7/12/2022 7/12/2022 Test case Start day End Date Intend time(hour) - 2 7/12/2022 7/12/2022 - 3 7/12/2022 7/12/2022 - 4 7/12/2022 7/12/2022 - 5 7/12/2022 7/12/2022 - 6 7/12/2022 7/12/2022 - 7 7/12/2022 7/12/2022 - 8 7/12/2022 7/12/2022 - 9 7/12/2022 7/12/2022
    • 10 7/12/2022 7/12/2022
    • 11 7/12/2022 7/12/2022
    • 12 7/12/2022 7/12/2022
    • 13 7/12/2022 7/12/2022
    • 14 7/12/2022 7/12/2022
    • 15 7/12/2022 7/12/2022

2.Test result................................................................................................................................................................

Test case Test data Expected results Actual result Pass/Fail 1 Enter your option: 1 You choose the first function Enter number of students: Pass 2 Enter the number of student: 5 Enter number of students: 5 Enter student number 1 id: Pass 3 Enter the number of student: - Enter the number of student: - 5 Please enter the correct number: Pass 4 Enter the number of student: b Invalid number of student. Please enter a number greater than 0! Fail

8 Enter option 1 Enter number of student: 5 Enter student number 1 id: 1 Enter student number 1 grade : 1. Enter student number 2 id: 2 Enter student number 2 grade : 1. Enter student number 3 id: 3 Enter student number 3 grade : 6. Enter student number 4 id: 4 Enter student number 4 grade : 6. Enter student number 5 id: 5 Enter student number 5 grade : 5. your option 1 you choose the first function Enter number of student: 5 Enter student number 1 id: 1 Enter student number 1 grade : 1. Enter student number 2 id: 2 Enter student number 2 grade : 1. Enter student number 3 id: 3 Enter student number 3 grade : 6. Enter student number 4 id: 4 Enter student number 4 grade : 6. Enter student number 5 id: 5 Enter student number 5 grade : 5. Pass

9 Enter option 2 and submit your option : 2 you choose the second function The 1 student with id 1 has grade

The 2 student with id 2 has grade

The 3 student with id 3 has grade

The 4 student with id 4 has grade

The 5 student with id 5 has grade

Pass 10 Enter option 3 and submit your option : 3 you choose the third function The student Id 3 has the highest grade 6. The student Id 4 has the highest grade 6. Pass

15 Enter option 1 and enter Student Grade = e Invalid Fail