In: Electrical Engineering
PLEASE USE ASSEMBLY LANGUAGE
The database students.db contains student records. Each record contains a name (30B ASCII), student ID (9B ASCII), 3 grades out of 100 (3B integers), and a letter grade (1B ASCII).
For the file students.db described above, assume all records are ordered alphabetically based on the name field. A record for a new student has been entered and stored in memory. Determine how to insert the new record into the database (Hint: use string compares to determine where it goes, the create a temp file, copy record that should come before it into the temp, then copy new record, then all other record into temp file. The delete the original and rename the temp file to students.db.
#include <stdio.h> #include <stdlib.h> struct info { int ID, HWORK, MIDTERM, FINAL, NUMGRADE; char NAME[20], LASTNAME[20]; } rec; int main() { FILE *fptr1, *fptr2; int NUMGRADE; char LETGRADE[3] = ""; fptr1 = fopen("inf.txt.", "r"); fptr2 = fopen("outf.txt.", "w"); while(!feof(fptr1)) { fscanf (fptr1, "%d %s %s %d %d %d", &rec.ID, rec.NAME, rec.LASTNAME, &rec.HWORK, &rec.MIDTERM, &rec.FINAL); NUMGRADE = rec.HWORK * 0, 15 + rec.MIDTERM * 0, 35 + rec.FINAL * 0, 5; if(NUMGRADE >= 0 && NUMGRADE <= 40) LETGRADE[3] = "FF"; else if (NUMGRADE >= 41 && NUMGRADE <= 45) LETGRADE[3] = "DD"; else if (NUMGRADE >= 46 && NUMGRADE <= 52) LETGRADE[3] = "DC"; else if (NUMGRADE >= 53 && NUMGRADE <= 60) LETGRADE[3] = "CC"; else if (NUMGRADE >= 61 && NUMGRADE <= 69) LETGRADE[3] = "CB"; else if (NUMGRADE >= 70 && NUMGRADE <= 79) LETGRADE[3] = "BB"; else if (NUMGRADE >= 80 && NUMGRADE <= 89) LETGRADE[3] = "BA"; else if (NUMGRADE >= 90) LETGRADE[3] = "AA"; fprintf (fptr2, "%d %s %s %d %s", &rec.ID, rec.NAME, rec.LASTNAME, &NUMGRADE, LETGRADE); } fclose(fptr1); fclose(fptr2); return 0; }