Answer To: /** Name: Student Course Registration System (SCRS)* Description: Utilizing functions, build a...
Kamal answered on May 05 2021
StaticArray.c
#include"StaticArray.h"
#include
/* student-oriented function */
int import_students(char const filename[], student_type students[], int* count)
{
FILE* fp = fopen(filename, "r");
int i = *count;
if (!fp)
printf("Can't open file\n");
else
{
char buffer[1024];
int row = 0;
int column = 0;
while (fgets(buffer, 1024, fp))
{
column = 0;
row++;
if (row == 1)
continue;
char* value = strtok(buffer, ", ");
while (value)
{
if (column == 0) students[i].student_status = value;
else if (column == 1) strcpy(students[i].student_id, value);
else if (column == 2) strcpy(students[i].student_first_name, value);
else if (column == 3) strcpy(students[i].student_middle_initial, value);
else if (column == 4) strcpy(students[i].student_last_name, value);
value = strtok(NULL, ", ");
column++;
}
}
fclose(fp);
}
}
int display_students(student_type const students[], int count)
{
for (int i = 0; i < count; i++)
{
printf("Student Id: %s\n", students[i].student_id);
printf("Student first name: %s\n", students[i].student_first_name);
printf("Student last name: %s\n", students[i].student_last_name);
printf("Student Middle initial: %s\n", students[i].student_middle_initial);
printf("Student status: %s\n", students[i].student_status);
}
return 1;
}
int sort_students(student_type students[], int count, student_fields_enum field, order_enum order)
{
int f;
if (field == "student_id") f = 1;
else if (field == "last_name") f = 2;
else if (field == "student_status") f = 3;
else return 0;
if (f == 1)
{
for (int i = 0; i < count; i++)
{
if (students[i].student_id < students[i + 1].student_id)
{
swap(students[i], students[i + 1]);
}
}
}
if (f == 2)
{
for (int i = 0; i < count; i++)
{
if (students[i].student_last_name < students[i + 1].student_last_name)
{
swap(students[i], students[i + 1]);
}
}
}
if (f == 3)
{
for (int i = 0; i < count; i++)
{
if (students[i].student_status < students[i + 1].student_status)
{
swap(students[i], students[i + 1]);
}
}
}
return 1;
}
int export_students(char const filename[], student_type const students[], int count)
{
FILE* fp = fopen(filename, "w");
if (!fp)
{
printf("Can't open file\n");
return 0;
}
for (int i = 0; i < count; i++)
{
fprintf(fp, "%d,%s,%s,%s,%s\n", students[i].student_status, students[i].student_id,
students[i].student_first_name, students[i].student_middle_initial, students[i].student_last_name);
}
}
int add_student(student_type students[], int* count, student_type student)
{
int i = *count;
strcpy(students[i].student_id, student.student_id);
strcpy(students[i].student_first_name, student.student_first_name);
strcpy(students[i].student_last_name, student.student_last_name);
strcpy(students[i].student_middle_initial, student.student_middle_initial);
students[i].student_status = student.student_status;
*count++;
return 1;
}
int remove_student(student_type students[], int* count, student_type student)
{
int f = 0, i;
for (i = 0; i < *count; i++)
{
if (students[i].student_id == student.student_id)
{
f = 1;
break;
}
}
if (f == 1)
{
while (i < *count)
{
students[i] = students[i + 1];
i++;
}
}
*count--;
return f;
}
int isa_student(student_type const students[], int count, char const student_id[])
{
for (int i = 0; i < count; i++)
{
if (students[i].student_id == student_id)
{
return 1;
}
}
return 0;
}
int get_student(student_type const students[], int count, char const student_id[], student_type* student)
{
for (int i = 0; i < count; i++)
{
if (students[i].student_id == student_id)
{
*student = students[i];
return 1;
}
}
return 0;
}
int compare_student(student_type first_student, student_type second_student)
{
if (first_student.student_id == second_student.student_id)
{
return 1;
}
return 0;
}
int copy_student(student_type* destination, student_type const* source)
{
if (destination->student_id != source->student_id)
{
destination = source;
return 1;
}
return 0;
}
int display_student(student_type student)
{
printf("Student Id: %s\n", student.student_id);
printf("Student first name: %s\n", student.student_first_name);
printf("Student last name: %s\n", student.student_last_name);
printf("Student Middle initial: %s\n", student.student_middle_initial);
printf("Student status: %s\n", student.student_status);
}
/* course-oriented function */
int import_courses(char const filename[], course_type courses[], int* count)
{
FILE* fp = fopen(filename, "r");
int i = *count;
if (!fp)
printf("Can't open file\n");
else
{
char buffer[1024];
int row = 0;
int column = 0;
while (fgets(buffer, 1024, fp))
{
column = 0;
row++;
if (row == 1)
continue;
char* value = strtok(buffer, ", ");
while (value)
{
if (column == 0) courses[i].course_status = value;
else if (column == 1) strcpy(courses[i].course_id, value);
else if (column == 2) strcpy(courses[i].course_semester, value);
else if (column == 3) strcpy(courses[i].course_department, value);
else if (column == 4) courses[i].course_number = value;
else if (column == 5) strcpy(courses[i].course_title, value);
else if (column == 6) courses[i].couse_hours = value;
value = strtok(NULL, ", ");
column++;
}
}
fclose(fp);
}
}
int display_courses(course_type const courses[], int count)
{
for (int i = 0; i < count; i++)
{
printf("Course ID: %s\n", courses[i].course_id);
printf("Course Number: %d\n", courses[i].course_number);
printf("Course Department: %s\n", courses[i].course_department);
printf("Course Semester: %s\n", courses[i].course_semester);
printf("Course Title: %s\n", courses[i].course_title);
printf("Course Status: %s\n", courses[i].course_status);
printf("Course Hours: %d\n", courses[i].couse_hours);
}
}
int sort_courses(course_type courses[], int count, course_fields_enum field, order_enum order)
{
int f;
if (field == "course_id") f = 1;
else if (field == "course_department") f = 2;
else if (field == "course_status") f = 3;
else return 0;
if (f == 1)
{
for (int i = 0; i < count; i++)
{
if (courses[i].course_id < courses[i + 1].course_id)
{
swap(courses[i], courses[i + 1]);
}
}
}
if (f == 2)
{
for (int i = 0; i < count; i++)
{
if (courses[i].course_department < courses[i + 1].course_department)
{
swap(courses[i], courses[i + 1]);
}
}
}
if (f == 3)
{
for (int i = 0; i < count; i++)
{
if (courses[i].course_status < courses[i + 1].course_status)
{
swap(courses[i], courses[i + 1]);
}
}
}
return 1;
}
int export_courses(char const filename[], course_type const courses[], int count)
{
FILE* fp = fopen(filename, "w");
if (!fp)
{
printf("Can't open file\n");
return 0;
}
for (int i = 0; i < count; i++)
{
fprintf(fp, "%d,%s,%s,%s,%d,%s,%d\n", courses[i].course_status, courses[i].course_id,
courses[i].course_semester, courses[i].course_department, courses[i].course_number,
courses[i].course_title, courses[i].couse_hours);
}
}
int add_course(course_type courses[], int* count, course_type course)
{
int i = *count;
strcpy(courses[i].course_department, course.course_department);
strcpy(courses[i].course_id, course.course_id);
courses[i].course_number = course.course_number;
strcpy(courses[i].course_semester, course.course_semester);
courses[i].course_status = course.course_status;
strcpy(courses[i].course_title, course.course_title);
courses[i].couse_hours = course.couse_hours;
*count++;
}
int remove_course(course_type courses[], int* count, course_type course)
{
int f = 0, i;
for (i = 0; i < *count; i++)
{
if (courses[i].course_id == course.course_id)
{
f = 1;
break;
}
}
if (f == 1)
{
while (i < *count)
{
courses[i] = courses[i + 1];
i++;
}
}
*count--;
return f;
}
int isa_course(course_type const courses[], int count, char const course_id[])
{
for (int i = 0; i < count; i++)
{
if (courses[i].course_id == course_id)
{
return 1;
}
}
return 0;
}
int get_course(course_type const courses[], int count, char const course_id[], course_type* course)
{
for (int i = 0; i < count; i++)
{
if (courses[i].course_id == course_id)
{
*course = courses[i];
return 1;
}
}
return 0;
}
int compare_course(course_type first_course, course_type second_course)
{
if (first_course.course_id == second_course.course_id)
{
return 1;
}
return 0;
}
int copy_course(course_type* destination, course_type const* source)
{
if (destination->course_id != source->course_id)
{
destination = source;
return 1;
}
return 0;
}
int display_course(course_type course)
{
printf("Course ID: %s\n", course.course_id);
printf("Course Number: %d\n", course.course_number);
printf("Course Department: %s\n", course.course_department);
printf("Course Semester: %s\n", course.course_semester);
printf("Course Title: %s\n", course.course_title);
printf("Course Status: %s\n", course.course_status);
printf("Course Hours: %d\n", course.couse_hours);
}
/* registration-oriented functions */
int import_registrations(char const filename[], registration_type registrations[], int* count)
{
FILE* fp = fopen(filename, "r");
int i = *count;
if (!fp)
printf("Can't open file\n");
else
{
char buffer[1024];
int row = 0;
int column = 0;
while (fgets(buffer, 1024, fp))
{
column = 0;
row++;
if (row == 1)
continue;
char* value = strtok(buffer, ", ");
while (value)
{
if (column == 0) registrations[i].registration_status = value;
else if (column == 1) strcpy(registrations[i].registration_student_id, value);
else if (column == 2) strcpy(registrations[i].registration_course_id, value);
else if (column == 3) registrations[i].registration_grade = value;
value = strtok(NULL, ", ");
column++;
}
}
fclose(fp);
}
}
int display_registrations(registration_type const registrations[], int count)
{
for (int i = 0; i < count; i++)
{
printf("Registration Status: %s\n", registrations[i].registration_status);
printf("Student ID: %s\n", registrations[i].registration_student_id);
printf("Course ID: %s\n", registrations[i].registration_course_id);
printf("Grade: %d\n", registrations[i].registration_grade);
}
}
int sort_registrations(registration_type registrations[], int count, registration_fields_enum field, order_enum order)
{
int f;
if (field == "registration_status") f = 1;
else return 0;
if (f == 1)
{
for (int i = 0; i < count; i++)
{
if (registrations[i].registration_status < registrations[i + 1].registration_status)
{
swap(registrations[i], registrations[i + 1]);
}
}
}
return 1;
}
int export_registrations(char const filename[], registration_type const registrations[], int count)
{
FILE* fp = fopen(filename, "w");
if (!fp)
{
printf("Can't open file\n");
return 0;
}
/*status_enum registration_status; // active with _grade --> completed, inactive --> incomplete or w
char registration_student_id[10]; // same as student_type.student_id
char registration_course_id[10]; // same as course_type.course_id
unsigned int registration_grade;*/
for (int i = 0; i < count; i++)
{
fprintf(fp, "%d,%s,%s,%d\n", registrations[i].registration_status, registrations[i].registration_student_id,
registrations[i].registration_course_id, registrations[i].registration_grade);
}
}
int add_registration(registration_type registrations[], int* count, registration_type registration)
{
int i = *count;
strcpy(registrations[i].registration_course_id, registration.registration_course_id);
strcpy(registrations[i].registration_status, registration.registration_status);
strcpy(registrations[i].registration_student_id, registration.registration_student_id);
registrations[i].registration_grade = registration.registration_grade;
*count++;
return 1;
}
int remove_registration(registration_type registrations[], int* count, registration_type registration)
{
int f = 0, i;
for (i = 0; i < *count; i++)
{
if ((registrations[i].registration_course_id == registration.registration_course_id) &&
(registrations[i].registration_student_id == registration.registration_student_id))
{
f = 1;
break;
}
}
if (f == 1)
{
while (i < *count)
{
registrations[i] = registrations[i + 1];
i++;
}
}
*count--;
return f;
}
int isa_registration(registration_type const registrations[], int count, char const...