Compare commits
No commits in common. "52dcaf6fac7de9b513ff74164f4f28be73548c19" and "b3ddc907866ef463d6a6a9429d06d72b72f93145" have entirely different histories.
52dcaf6fac
...
b3ddc90786
@ -5,16 +5,4 @@ Computer
|
|||||||
88
|
88
|
||||||
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,17 +34,12 @@ 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();
|
||||||
@ -52,6 +47,7 @@ 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
|
||||||
@ -238,9 +234,6 @@ 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)
|
||||||
@ -256,118 +249,14 @@ 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()
|
||||||
{
|
{
|
||||||
// refresh data from file first
|
printf("\nNot implement yet!");
|
||||||
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()
|
||||||
{
|
{
|
||||||
int upper_mark = 50;
|
printf("\nNot implement yet!");
|
||||||
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()
|
||||||
@ -428,7 +317,7 @@ again:
|
|||||||
|
|
||||||
fclose(file);
|
fclose(file);
|
||||||
|
|
||||||
printf("\nRecord saved successfully!");
|
printf("\nSaved");
|
||||||
|
|
||||||
// reload data into linked list again
|
// reload data into linked list again
|
||||||
read_file();
|
read_file();
|
||||||
|
Loading…
Reference in New Issue
Block a user