0% found this document useful (0 votes)
288 views

PROG102 - Assignment 2

The document describes an assignment to design a procedural program to manage student grades. The program is required to: 1) Allow input of student IDs, names, grades into arrays 2) Print all student information 3) Find the highest and lowest grades The implementation section explains the structure of the program including declaring libraries, a student data structure, functions, and a main menu. Key functions are described such as inputting data, storing in arrays, outputting data, calculating averages, and finding max/min grades. Testing and evaluation of the program are also discussed.

Uploaded by

Anh Minh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
288 views

PROG102 - Assignment 2

The document describes an assignment to design a procedural program to manage student grades. The program is required to: 1) Allow input of student IDs, names, grades into arrays 2) Print all student information 3) Find the highest and lowest grades The implementation section explains the structure of the program including declaring libraries, a student data structure, functions, and a main menu. Key functions are described such as inputting data, storing in arrays, outputting data, calculating averages, and finding max/min grades. Testing and evaluation of the program are also discussed.

Uploaded by

Anh Minh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 35

ASSIGNMENT 2 FRONT SHEET

Qualification BTEC Level 5 HND Diploma in Computing

Unit number and title PROG102: Procedural Programming

Submission date 13/05/2022 Date Received 1st submission

Re-submission Date Date Received 2nd submission

Student Name Trần Vũ Anh Minh Student ID GCS210898

Class GCS 1004B 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 AM

Grading grid

P4 P5 M3 M4 D2
 Summative Feedback:  Resubmission Feedback:

Grade: Assessor Signature: Date:


Lecturer Signature:
ASSIGNMENT 2

Analysis and design a solution for


procedural programming problem

1
Contents
1. Introduction ............................................................................................................................ 3
1.1. Scenario .......................................................................................................................... 3
1.2. Problem ........................................................................................................................... 3
1.3. Solution ........................................................................................................................... 3
2. Implementation ...................................................................................................................... 4
2.1. Explain about structure of program ............................................................................... 4
2.2. Explain about each function ............................................................................................ 7
2.3. Code: ................................................................................................................................ 16
4. Testing ..................................................................................................................................... 26
5. Evaluation ............................................................................................................................... 29
5.1. Evaluate my program ..................................................................................................... 29
5.2. Evaluate about Procedural programming with my program .................................... 30
6.Conclusion ............................................................................................................................... 30
Reference list .............................................................................................................................. 31

2
1. Introduction

1.1. Scenario

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


him to write a small application to do that. He needs to enter student IDs,
student’s grades and store these 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
highest grade and lowest grade. Your program should be menu based with
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 program.

1.2. Problem
• The problem of student information management is a difficult problem.
Manual management method has many disadvantages.

• I need to find a way to program and create a system that solved the
disadvantages of the old method.

• The program should have the main functions needed to enter, print,
calculate min, max, average, exit, …

1.3. Solution
• Using procedural programming to write programs.

• The program needs an interface to select functions, variables and array to


enter information: name, ID, age, gender, subject scores.

• Create separate functions for input, print, find the highest and lowest
scores, average score, result, rank, rating, exit.

3
2. Implementation
I will explain the whole program:

2.1. Explain about structure of program


• Declaration section

- Declare libraries:
<stdio.h>: Provide the ability to enter. Use printf, scanf, …
<string.h>: Adjust a variety of characters (char)
<stdlib.h>: Perform math operations, transformations, ordering, …
<conio.h>: Use it to use getch(), …
- Struct:

This section declares a variable stu to store variables related to student


information.
Inside, I declared variables to store information:
+ ID
+ name
+ age
+ gender
+ math, english, physics , average: points

Thanks to the struct structure, I can use the information easily even
though there are many students.

4
- The next is declaring functions.

At here, I declare all of functions.


• Main

I write a loop to know the limit of number of students, declare an empty


array of structure stu.
Program interface and switch-case for selecting functions are also created
here.

5
Within functions are functions applied.

• After the main


This is the place to write the functions, which will be used in main.

6
2.2. Explain about each function
• Function “Input ”:

- This function is used to enter student information: ID, name, age, gender,
grades of 3 subjects.

- I used printf to request information from the user.

- With variables of type int, float, I used scanf to save the parameter to the
variable.

- With variables of type char, I used gets to store the parameter in the variable.

- I used fflush(stdin); to clear the program’s temporary memory so that there


are no garbage values.

7
• Function “Step2”:

This function is used to store student information as an element in an


array so that it can be easily used.

Command line Explanation


Void two (stu l[ ], int n) Declare the function name as “Step2”,
declare the array l[ ] of the structure
stu, declare the variable n integer
type, n is the limit of the elements of
the array.
for (int i=0; i<n; i++) Use loop to call the elements in the
array: variable int i=0, condition i<n,
after completing the loop clause,
increase i by 1.
printf(“\n Enter student %d”, i+1); This command helps the user to know
the number of students entering.
Input(u[i]) Run “Input” function to enter
Information.
Table 1. Explain function “Step2”

8
• Function “Output”:

This function is used to print all information like ID, name, age, gender, scores
of student.

Take as input the variables a of structure stu. Use printf to print all the
information to the screen: ID, age, gender, grade of 3 subjects. Use %d,
%.1f, %s with variables to get information.
• Function “Step4”:

This function is used to print out student information. As for how it works,
it’s similar to the “Step2” function. Instead of using the “Input” function for
input, uses the “Output” function to print out the data.

9
• Function “Average”:

This function is used to calculate average. I used for loop to get the
scores information from the array. Recipe: average= total of 3 scores
(math, English, prog) divided 3.
• Function “Mar”:

This function is quite long, it has the function of calculating the highest and
lowest points.

• Find max: Initialized the float max variable, assigned it to the average of
the first element in the array. I did it for easy comparison with 2nd value.
Used loop to call out the next elements. Used If to perform max< average.
If true, assign max = average. It helped me to find the larger value than the

10
previous one and ignore the smaller one. This command line sequence
helps to find the maximum value in an array.

• Find min: Use the same algorithm as finding max. Initialized min variable
instead of max variable. In the If statement, compare min > average.

• Finally, I continued to use a loop to print the maximum and minimum


points. In addition, I also printed the average score of all students.

• Function “Evaluating”:

This function is used to print Passed or Failed. Used loop to get elements
of array. Used If statement, compared average >=5. If true, print out ID with
name is passed, if false, print out ID with name is failed. There is simple
statement to compare and find out result to be passed or failed.
• Function “Ranking”:

This function is used to print out rank of students. Initialized a variable HD


of stu.

11
Use loop 1 with i=0 and condition i<n-1. In loop 1, using loop 2 again with
y=1 and condition y<n. The purpose when using 2 loops is to be able to
retrieve 2 consecutive elements in the array.

Use the If clause to compare the average score of the first element < the
mean of the second element.

If true, use the following command lines to swap the positions of those 2
elements in array.

Finally, use a loop to print out the results.

12
Function “Rating”:

This function is quite similar to the function “Evaluating” but it focuses


more deeply. Use a loop to get the elements of the array, use If else,
else if to compare and print the student rating.
• How functions are used.

All function has command line getch(); it notifies the user to type any key
to return to the main interface.
- Function 1: Enter information.

13
Here, function “Step2” is run first. Inside this function there is a function
“Input” with all the information of student, the functions “Step2” will switch
to the next student. Function “Average” is used to calculate the average
score of each student.

- Function 2: Show all information of students.

Function “Step4” will be run. Because in this function there are function
“Output”, these 2 functions run at the same time to print out all the
information of all the students.
- Function 3: Min, max, average.

Function “” will run independently to find and print the student’s max, min,
average.

14
- Function 4: Result of course

Function “Evaluating” will run to categorize students through subjects or


failing subjects.
- Function 5: Student’s rank

Function “Ranking” will run to sort and print out the student rank in the class.

- Function 6: Rating

Function “Rating” will run to classify titles for students.

15
2.3. Code:
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
struct stu{
int ID;
int age;
char name[50];
char gender[10];
float math,eng,phs;
float average=0;
};
void Input(stu &a);
void Step2(stu l[], int n);
void Output(stu a);
void Step4(stu l[], int n);
void Mar(stu l[],int n);
void Average(stu l[],int n);
void Evaluating(stu l[],int n);
void Ranking(stu l[],int n);
void Rating(stu l[], int n);
int main(){

int n;
do {
printf ("\n How many students:");
scanf("%d", &n);
}while (n<=0);

16
stu l[n];

while(true){

printf("\n T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T.T\n");

printf("____________ Student management


system ____________\n");

printf("== 1. Input student’s information. ==\n");

printf("== 2. Student’s information. ==\n");

printf("== 3.Student’s grades. ==\n");

printf("== 4. Course result. ==\n");

printf("== 5. Student’s rank. ==\n");

printf("== 6. Rating. ==\n");

printf("== 0. Exit. >< ==\n");

int in;

printf ("__ You need to select a function: ");

scanf("%d",&in);

switch(in){

case 1:

printf("Enter student list: \n");

Step2(l,n);

Average(l,n);

printf("Enter any letter to continue");

getch();

break;

17
case 2:
printf ("Display the student list \n");
Step4(l,n);
printf("Enter any letter to continue");
getch();
break;
case 3:
Mar(l,n);
printf("Enter any letter to continue");
getch();
break;
case 4:
Evaluating(l,n);
printf("Enter any letter to continue");
getch();
break;
case 5:
Ranking(l,n);
printf("Enter any letter to continue");
getch();
break;
case 6:
Rating(l,n);
printf("Enter any letter to continue");
getch();
break;
case 0:
printf("Thank you for using this program. Have a nice day. <3 ");

18
exit(0);
break;
default:
break;

}}
return 0;
}

void Input(stu &a){


printf("\n Enter student ID:");
fflush(stdin);
scanf("%d",&a.ID);
printf ("\n Enter name:");
fflush(stdin);
gets(a.name);
printf("\n Enter age:");
fflush(stdin);
scanf("%d",&a.age);
printf ("\n Enter gender:");
fflush(stdin);
gets(a.gender);
fflush(stdin);
printf("\n Enter the scores of Math, English, Physics:");
scanf("%f%f%f",&a.math,&a.eng,&a.phs);
}
void Step2(stu l[], int n){
printf("\n-----------------");

19
for (int i=0; i <n; i++)
{
printf("\n Enter student %d", i+1);
Input(l[i]);
}

void Output(stu a){


printf("\n Student ID is: %d ",a.ID);
printf("\n Name: %s", a.name);
printf("\n Age: %d", a.age);
printf("\n Gender: %s", a.gender);
printf("\n The scores of Math,English, Physics: %.1f and
%.1f and %.1f",a.math,a.eng,a.phs);
printf("\n-------------------\n");
}

void Step4(stu l[], int n){


printf("\n-------------------\n");
for (int i=0; i<n;i++)
{
printf("\n All infomation of student %d:", i+1);
Output(l[i]);
}
printf("\n----------------------\n");}

void Mar(stu l[],int n){


int i=0;

20
float max=l[i].average;
for (int i=1;i<n;++i){
if (max<l[i].average)
max=l[i].average;}

float min=l[i].average;
for (int i=1;i<n;i++{
if (min>l[i].average)
min=l[i].average;
}
for(int i=0;i<n;i++){
printf("The average grades of %s is: %.1f \n",l[i].name,l[i].average);}
printf("The min average is: %.1f\n",min);

printf("The max average is: %.1f\n",max);

}
void Average(stu l[],int n){
for(int i=0;i<n;i++){
l[i].average=(float)(l[i].math+l[i].eng+l[i].phs)/3;

}
}

void Evaluating(stu l[],int n){


for (int i=0;i<n;i++){
if (l[i].average>=5)printf("Student has ID %d with the name
%s is: PASSED\n",l[i].ID,l[i].name);
else printf("Student has ID %d with the name %s is:
FAILED\n",l[i].ID,l[i].name); }}

21
void Ranking(stu l[],int n){
stu HD;
for(int i=0;i<n-1;i++){
for (int y=1;y<n;y++){
if (l[i].average<l[y].average)
{
HD= l[i];
l[i]=l[y];
l[y]=HD;
}
}
}
for(int i=0;i<n;++i){
printf( "%s ranked: %d \n",l[i].name,i+1);}
}

void Rating(stu l[], int n){


printf("\n---------------------------------\n");
for(int i = 0;i < n;++i){
printf("\n Student rating %d is: ", i+1);

if(l[i].average >= 8) printf("Brilliant


student."); else if(l[i].average >= 5)
printf("Great student."); else printf("Not
enough to up the grade"); }

printf("\n----------------------------------\n");
}

22
3. Program results

Ask the number of students when the program starts running

Interface of program

23
Function 1: Enter information of student
After entering all information of 3 students

Function 2: Show information of students

24
Function 3: Print out min, max, average of scores

Function 4: Print out result of course

Function 5: Print out rank of students

Function 6: Print out rating of students

25
Function 0: Thank and exit

4. Testing

A test case, in its most basic form, is a set of conditions or variables that a
tester uses to verify whether software meets requirements and performs
properly (Bartlett, 2020).
I will test the program’s navigation and all functions.

Test Test Test Steps Test data Expected Actual Pass/


case Description Results
ID Results Fail

1 Enter 1. Run -How many User re-enter Go to Fail


number of students= 0 quantity interface
2.Enter number
students
of students

2 Select 1.Run User re-enter As Pass


function function expected
2.Enter number -Select
of students function= 7
3. Select
function

3 Print 1.Run Print out all of As Pass


information information expected
2.Enter number -ID=1
of students
of students
-name=A
3.Select function
-age=18
4.Enter
-gender=male
information of
students -scores=9,8,10

26
5.Print
information of
students

4 Find max, 1.Run -ID=1 Print out As Pass


min, average of expected
2.Enter number -name=A
average students, max
of students
-age=18 and min
3.Select function -gender=male scores.
4.Enter Result is true.
-scores=9,8,10
information of
students -ID=2
5.Max, min, -name=B
average -age=18
-gender=female
-scores=1,2,3

5 Print result 1.Run -ID=1 Tung: Passed Tung: Fail


of course Passed
2.Enter number -name=A Long: Failed
of students Long:
-age=18
Failed
3.Select function
-gender=male
4.Enter
-scores=9,8,10
information of
students -ID=2
5.Result of -name=B
course -age=18
-gender=female
-scores=1,2,3

6 Rank of 1.Run -ID=1 A: rank 1 As Pass


students expected
2.Enter number -name=A B: rank 2
of students
-age=18
3.Select function
-gender=male
4.Enter
-scores=9,8,10
information of
students -ID=2
5.Rank of -name=B
students -age=18

27
-gender=female
-scores=1,2,3

7 Rating 1.Run -ID=1 Tung: Brilliant As Pass


Student expected
2.Enter number -name=A
of students Long: Not enough to
-age=18
up the grade
3.Select function
-gender=male
4.Enter
-scores=9,8,10
information of
students -ID=2
-name=B
-age=18
-gender=female
-scores=1,2,3

8 Exit 1.Run -Select Print: Thank As Pass


function=0 you for using. expected
2.Enter number
of students Program
finished.
3.Select function

Table 2: Test log

• Analysis:

There are very few command lines errors and it is easy to fix. Input data is
used correctly, variables work well. There are 9/10 functions that don’t need
editing. Most of the main functions are less buggy, they work as expected.
After finding the location and fixing the error: The first error is in the input of
the number of students, this error is due to the comparison part. The second
error is because the averaging has not run.

28
5. Evaluation
5.1. Evaluate my program
• Program:

My program already has the basic functions of a student management


software. They are input, print information, calculate scores, result, … The
program has been organized uses functions reasonably, no functions are
redundant or unused. They have been optimized and do not have any
errors. Because it’s organized, the program manager can write new
functionality easily.

Limitations:

These are only basic and incomplete functions for student management,
can only enter information once and have no correction function, input
information is incomplete, so it can only be applied for a class or group of
students. Only teachers can use this program.

• Experience:

Build the functions of the program first, then build the interface and parts in
main. List interrelated functions and build them first. Test each function, find
bugs and fix them, then move on to another.

• Future improvements:

You may tailor the recruiting environment for potential students and recruitment
officers using a variety of technical tools. All of the components work together
to assist increase school enrolment (Joshi, 2019). Therefore, the development
of a student management system is very important.

In the future, new functions such as delete, edit, add can be added to the
program. Logging in is an important function to extend the reach of users.
Student and parents will be able to access and use the functions intended
for them. More diverse input information: phone, number, address, …

In addition, the information search function is also a useful thing, it helps


users easily search within a class or a school.

29
5.2. Evaluate about Procedural programming with
my program

• Advantages:
Without having to duplicate the code, it can be utilized in different portions
of the application. The memory required of the software is lowered using
the Procedural Programming. Structures such as iteration, conditional, ...
are very suitable for implementing program functions. If there is an error,
the program will clearly notify. Arrays and variables are very useful, making
it easy to import and export student information.

• Disadvantages:
The entered data is still displayed, it may cause information disclosure. If
you change some command lines, the whole program may have to be
rewritten, which is quite troublesome.

• Difficulties:
Difficulty in using variables, combining functions to form a main function.
Difficulty in reducing lines of code, optimizing and increasing program
performance (variables, statements, calculations, …).

6.Conclusion

After completing this assignment, I know how to use procedural


programming to solve student management problems, solve math problems
using procedural programming statements. I have analyzed and divided the
program into main parts, explaining all the statements and each function of
the program in detail. Also, I ran tests of functions every day, found bugs,
fixed them, and knew how to build test logs. General assessment and find
out the limits of functions and programs, take it as leverage to write down
the functions that will be oriented and developed in the future. Learn from
the experience and lessons learned from the program and apply them to
future projects. Outline the advantages and disadvantages of procedural
programming for this student management program and the difficulties
encountered when writing the program.
This first program and course will be a great new start for me in the IT major.

30
Reference list
1. Joshi, M., 2019. What is a School Management System? How Can it
Boost Enrollment?. [online] Leadsquared. Available at:
<https://www.leadsquared.com/school-management-system/> [Accessed
11 July 2021].
2. Bartlett, J., 2020. What Is A Test Case In Software Testing?. [online]
Testlodge. Available at: <https://blog.testlodge.com/what-is-a-test-case-in-
software-testing/> [Accessed 11 July 2021].

31

You might also like