hi! i need rewrite this program using sequential text file!
Code:
#include<stdio.h>
#include<string.h>
typedef struct
{ char last_name[15];
char first_name[15];
double grade_point_index;
}student;
typedef struct
{ char last_name[15];
char first_name[15];
double salary;
}employee;
int
main(){
int num_student;
int num_employee;
int i,k,j;
student arr_student[5],temp;
employee arr_employee[5],temp1;
printf("\nEnter the number of students==> ");
scanf("%d", &num_student);
for(i=0;i<num_student;i++)
{printf("\nEnter the last name of student %d==>",i+1 );
scanf("%s",arr_student[i].last_name);
printf("\nEnter the first name of student %d==>",i+1 );
scanf("%s",arr_student[i].first_name);
printf("\nEnter the grade point index of student %d==>",i+1 );
scanf("%lf",&arr_student[i].grade_point_index);}
for (k = 0; k <num_student; ++k)
for (j = k+1; j <num_student; ++j){
if (strcmp(arr_student[k].last_name,arr_student [j].last_name)>0){
temp=arr_student[k];
arr_student[k]=arr_student[j];
arr_student[j]=temp;}
else if (strcmp(arr_student[k].last_name,arr_student[j].last_name)==0){
if (strcmp(arr_student[k].first_name,arr_student[j].first_name)>0){
temp=arr_student[k];
arr_student[k]=arr_student[j];
arr_student[j]=temp;}}
}
printf("Students' records \t last name \t first name \t grade point index \n");
for(i=0;i<num_student;i++)
printf(" \t %-8s \t %-8s \t %-8.2f \n",arr_student[i].last_name,arr_student[i].first_name,arr_student[i].grade_point_index);
printf("Enter the number of employees==> ");
scanf("%d", &num_employee);
for(i=0;i<num_employee;i++)
{printf("\nEnter the last name of employee %d==>",i+1 );
scanf("%s",arr_employee[i].last_name);
printf("\nEnter the first name of employee %d==>",i+1 );
scanf("%s",arr_employee[i].first_name);
printf("\nEnter the salary of employee %d==>",i+1 );
scanf("%lf",&arr_employee[i].salary);
}
for (k = 0; k <num_employee; ++k)
for (j = k+1; j <num_employee ; ++j){
if (strcmp(arr_employee [k].last_name,arr_employee[j].last_name)>0){
temp1=arr_employee[k];
arr_employee[k]=arr_employee[j];
arr_employee[j]=temp1;}
else if (strcmp(arr_employee[k].last_name,arr_employee[j].last_name)==0){
if (strcmp(arr_employee [k].first_name,arr_employee [j].first_name)>0){
temp1=arr_employee[k];
arr_employee[k]=arr_employee[j];
arr_employee[j]=temp1;}}
}
printf("\nThe Employees' records that you have entered are: \n\n");
printf("Employees' records \t last name \t first name \t salary \n");
for(i=0;i<num_employee;i++)
printf(" \t %-8s \t %-8s \t %-8.2f \n",arr_employee[i].last_name,arr_employee[i].first_name,arr_employee[i].salary);
for(i=0;i<num_student;i++)
{for(j=0; j<num_employee; j++)
if(strcmp(arr_employee[j].last_name,arr_student[i].last_name)==0 && strcmp(arr_employee[j].first_name,arr_student[i].first_name)==0)
if(arr_student[i].grade_point_index>3)
arr_employee[j].salary= arr_employee[j].salary * 1.10;}
printf("\n\nThe emplyees' salary after the increase: \n \n");
printf("Employees' records \t last name \t first name \t salary \n");
for(i=0;i<num_employee;i++)
printf(" \t %-8.3s \t %-8s \t %-8.3f \n",arr_employee[i].last_name,arr_employee[i].first_name,arr_employee[i].salary);
return (0);
}
i need put data in an external files (ordered), one for students (called "students.dat"), one for employees (called "employees.dat").
2- read it in
3-change the salary of those employees who had a GPA greater than 3.0 as students
4- write out the changed employee array (the students' array doesn't change) to a file called "employees_updated.dat".