PROG102 - Assignment 2
PROG102 - Assignment 2
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:
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
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.
• 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:
- 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:
Thanks to the struct structure, I can use the information easily even
though there are many students.
4
- The next is declaring functions.
5
Within functions are functions applied.
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.
- 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.
7
• 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.
• 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”:
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.
12
Function “Rating”:
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 “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 “Ranking” will run to sort and print out the student rank in the class.
- Function 6: Rating
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");
int in;
scanf("%d",&in);
switch(in){
case 1:
Step2(l,n);
Average(l,n);
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;
}
19
for (int i=0; i <n; i++)
{
printf("\n Enter student %d", i+1);
Input(l[i]);
}
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);
}
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;
}
}
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);}
}
printf("\n----------------------------------\n");
}
22
3. Program results
Interface of program
23
Function 1: Enter information of student
After entering all information of 3 students
24
Function 3: Print out min, max, average of scores
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.
26
5.Print
information of
students
27
-gender=female
-scores=1,2,3
• 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:
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, …
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
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