Compare commits
6 Commits
b3ddc90786
...
52dcaf6fac
Author | SHA1 | Date | |
---|---|---|---|
52dcaf6fac | |||
c5416d4704 | |||
1007604842 | |||
ee1ec269b4 | |||
9880763344 | |||
6a0deedead |
@ -6,3 +6,15 @@ Computer
|
|||||||
98
|
98
|
||||||
52
|
52
|
||||||
95
|
95
|
||||||
|
Sambo
|
||||||
|
12345
|
||||||
|
CS90
|
||||||
|
2
|
||||||
|
50
|
||||||
|
40
|
||||||
|
Chea
|
||||||
|
6789
|
||||||
|
CS78
|
||||||
|
2
|
||||||
|
50
|
||||||
|
20
|
119
work1/single.c
119
work1/single.c
@ -34,12 +34,17 @@ typedef struct person_tag PERSON;
|
|||||||
typedef struct course_tag COURSE;
|
typedef struct course_tag COURSE;
|
||||||
typedef struct student_tag STUDENT;
|
typedef struct student_tag STUDENT;
|
||||||
|
|
||||||
|
// file function
|
||||||
|
void read_file();
|
||||||
|
|
||||||
// util functions
|
// util functions
|
||||||
void display_menu();
|
void display_menu();
|
||||||
void print_welcome();
|
void print_welcome();
|
||||||
void print_student(STUDENT *student);
|
void print_student(STUDENT *student);
|
||||||
void release(STUDENT *data);
|
void release(STUDENT *data);
|
||||||
|
int find_min_in_array(int *array);
|
||||||
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE]);
|
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE]);
|
||||||
|
STUDENT *find_maximum_avg();
|
||||||
|
|
||||||
// core functions
|
// core functions
|
||||||
void display_students();
|
void display_students();
|
||||||
@ -47,7 +52,6 @@ void search_student();
|
|||||||
void find_maximum();
|
void find_maximum();
|
||||||
void find_failed();
|
void find_failed();
|
||||||
void update_file();
|
void update_file();
|
||||||
void read_file();
|
|
||||||
void quite();
|
void quite();
|
||||||
|
|
||||||
// Linked list functions
|
// Linked list functions
|
||||||
@ -234,6 +238,9 @@ void search_student()
|
|||||||
|
|
||||||
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE])
|
STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE])
|
||||||
{
|
{
|
||||||
|
// refresh data from file first
|
||||||
|
read_file();
|
||||||
|
|
||||||
STUDENT *temp = head;
|
STUDENT *temp = head;
|
||||||
|
|
||||||
while (temp != NULL)
|
while (temp != NULL)
|
||||||
@ -249,14 +256,118 @@ STUDENT *search_student_by_name_or_id(char search_key[NAME_SIZE])
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
STUDENT *find_maximum_avg()
|
||||||
|
{
|
||||||
|
// refresh data from file first
|
||||||
|
read_file();
|
||||||
|
|
||||||
|
STUDENT *temp = head, *max;
|
||||||
|
max = temp->next;
|
||||||
|
|
||||||
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
if (max == NULL)
|
||||||
|
{
|
||||||
|
return temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (max->course_info.avg < temp->course_info.avg)
|
||||||
|
{
|
||||||
|
max = temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
// release the max next record
|
||||||
|
// set max next element to NULL
|
||||||
|
// because we use only one record
|
||||||
|
release(max->next);
|
||||||
|
max->next = NULL;
|
||||||
|
|
||||||
|
return max;
|
||||||
|
}
|
||||||
|
|
||||||
|
int find_min_in_array(int *array)
|
||||||
|
{
|
||||||
|
if (array == NULL)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int min = array[0];
|
||||||
|
size_t size = sizeof(array) / sizeof(array[0]);
|
||||||
|
|
||||||
|
for (int i = 1; i < size; i++)
|
||||||
|
{
|
||||||
|
if (array[i] < min)
|
||||||
|
{
|
||||||
|
min = array[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return min;
|
||||||
|
}
|
||||||
|
|
||||||
|
STUDENT *find_failed_mark(int upper_mark)
|
||||||
|
{
|
||||||
|
// refresh data from file first
|
||||||
|
read_file();
|
||||||
|
|
||||||
|
STUDENT *temp = head, *failed_students = NULL;
|
||||||
|
|
||||||
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
int min = find_min_in_array(temp->course_info.marks);
|
||||||
|
|
||||||
|
if (min < upper_mark)
|
||||||
|
{
|
||||||
|
if (failed_students == NULL)
|
||||||
|
{
|
||||||
|
failed_students = temp;
|
||||||
|
failed_students->next = NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
while (failed_students->next != NULL)
|
||||||
|
{
|
||||||
|
failed_students = failed_students->next;
|
||||||
|
}
|
||||||
|
failed_students->next = temp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
|
||||||
|
return failed_students;
|
||||||
|
}
|
||||||
void find_maximum()
|
void find_maximum()
|
||||||
{
|
{
|
||||||
printf("\nNot implement yet!");
|
// refresh data from file first
|
||||||
|
read_file();
|
||||||
|
|
||||||
|
STUDENT *max_student = find_maximum_avg();
|
||||||
|
if (max_student == NULL)
|
||||||
|
{
|
||||||
|
printf("\nNo maximum student found!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nFind maximum avg was found with: %0.2f\n", max_student->course_info.avg);
|
||||||
|
print_student(max_student);
|
||||||
}
|
}
|
||||||
|
|
||||||
void find_failed()
|
void find_failed()
|
||||||
{
|
{
|
||||||
printf("\nNot implement yet!");
|
int upper_mark = 50;
|
||||||
|
STUDENT *failed_students = find_failed_mark(upper_mark);
|
||||||
|
if (failed_students == NULL)
|
||||||
|
{
|
||||||
|
printf("\nNo failed student found!\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("\nFind the failed students that at least one mark less than %d\n", upper_mark);
|
||||||
|
print_student(failed_students);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_file()
|
void update_file()
|
||||||
@ -317,7 +428,7 @@ again:
|
|||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
printf("\nSaved");
|
printf("\nRecord saved successfully!");
|
||||||
|
|
||||||
// reload data into linked list again
|
// reload data into linked list again
|
||||||
read_file();
|
read_file();
|
||||||
|
Loading…
Reference in New Issue
Block a user