finish lab 08

This commit is contained in:
SowinskiBraeden committed 2025-11-07 10:40:50 -08:00
1 parent f1a0d21d04
commit d06ca3f01a
14 files changed
+988 -1

No files matched your search

+1 -1
View File
@@ -3,7 +3,7 @@ CC = gcc
CFLAGS = -Wall -std=c11 CFLAGS = -Wall -std=c11
#Input file #Input file
INPUT = input1.txt INPUT = input.txt
OUTPUT = output.txt OUTPUT = output.txt
REF = ref1.txt REF = ref1.txt
# Source file # Source file
+60
View File
@@ -0,0 +1,60 @@
# Compiler and flags
CC = gcc
CFLAGS = -Wall -std=c11
#Input file
INPUT = input5.txt
OUTPUT = output.txt
REF = ref5.txt
# Source file
SRCS = lab8.c
# Output
TARGET = lab8.out
# Default target
all: $(TARGET)
# Rule to build the executable
$(TARGET): $(SRCS)
$(CC) $(CFLAGS) $(SRCS) -o $(TARGET)
convert_input: $(INPUT)
@if [ -s $(INPUT) ] && file $(INPUT) | grep -q 'CRLF line terminators' ; then \
{ cat $(INPUT) | dos2unix; } | tee $(INPUT) >/dev/null; \
fi
@if [ -s $(INPUT) ] && tail -c1 $(INPUT) | grep -q . ; then \
echo >> $(INPUT); \
tr -d '\r' < $(INPUT) > temp_file && mv temp_file $(INPUT); \
fi
convert_output: $(OUTPUT)
@if [ -s $(OUTPUT) ] && file $(OUTPUT) | grep -q 'CRLF line terminators' ; then \
{ cat $(OUTPUT) | dos2unix; } | tee $(OUTPUT) >/dev/null; \
fi
@if [ -s $(OUTPUT) ] && tail -c1 $(OUTPUT) | grep -q . ; then \
echo >> $(OUTPUT); \
tr -d '\r' < $(OUTPUT) > temp_file && mv temp_file $(OUTPUT); \
fi
check: $(OUTPUT) $(REF)
@if [ -s $(REF) ] && file $(REF) | grep -q 'CRLF line terminators' ; then \
{ cat $(REF) | dos2unix; } | tee $(REF) >/dev/null; \
fi
@if [ -s $(REF) ] && tail -c1 $(REF) | grep -q . ; then \
echo >> $(REF); \
tr -d '\r' < $(REF) > temp_file && mv temp_file $(REF); \
fi
@diff -q $(OUTPUT) $(REF) > /dev/null; \
if [ $$? -eq 0 ]; then \
echo "Pass"; \
else \
echo "Fail"; \
fi
# Rule to run the program
run: $(TARGET)
./$(TARGET) $(INPUT) $(OUTPUT)
# Rule to clean generated files
clean:
rm -f $(TARGET)
+106
View File
@@ -0,0 +1,106 @@
1
Johnston Maria A0413808 97 49
Bryant Rhonda A0142192 1 45
Bailey Candice A0834662 98 38
Campbell Matthew A0622975 76 83
May Ryan A0760904 39 97
Miranda David A0330182 86 48
Henry Karen A0431273 15 84
Middleton Sarah A0231710 79 25
Gilbert Howard A0212656 89 73
Castro Robert A0261725 94 12
Lara Robert A0368288 80 80
Lara Robert A0368288 81 80
Lara Robert A0368289 80 81
Wells Brittany A0660122 13 6
Adams Cynthia A0627095 20 20
Morse Douglas A0258366 18 23
Patel Derrick A0570531 64 70
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Brown Brian A0103518 99 1
Lee Patrick A0893874 95 73
Carter Christine A0785415 42 50
Henderson Andrew A0371183 29 58
Anderson Brett A0168017 36 56
Simon Thomas A0517482 50 56
Lane Nancy A0542001 51 30
Smith Anthony A0410478 41 28
Summers Michael A0893440 55 50
Singleton Jordan A0566335 59 10
Lawrence Michelle A0241228 17 22
Castillo Shawn A0908873 65 58
Newman David A0665229 40 53
Richards Shawn A0942153 62 91
Berger Keith A0568406 56 46
Williams Kimberly A0731536 1 6
Terry Marcia A0996692 43 77
Collins Christopher A0669187 8 28
Mclaughlin Stephanie A0766027 31 6
Fowler Clayton A0513357 70 70
Richards Veronica A0958309 49 93
Perkins Arthur A0437488 66 49
Lopez Christine A0396434 80 4
Mclaughlin Brandon A0816497 48 47
Rios Stacey A0296736 69 83
Gray Teresa A0797916 60 60
Chapman Angela A0149524 2 42
Lewis Stacey A0284552 99 97
Day Christopher A0322878 27 48
Williams Richard A0971344 96 46
Ward Mark A0460420 26 44
Dean Derrick A0888238 3 88
Stone James A0364579 79 19
Wagner Kylie A0950922 38 58
Martinez April A0987945 47 58
Dodson Steven A0858775 96 92
Hanna Tiffany A0497426 41 24
Reed Robert A0657526 74 78
Valdez Abigail A0760928 23 30
Rivas Jeremy A0305368 89 12
Morrow Lauren A0916826 90 90
Callahan Amy A0435370 68 67
Brown Shane A0738510 57 70
Porter Michael A0922166 64 69
Bailey Aaron A0208249 52 99
Smith Adam A0782612 81 0
Meza Shannon A0159196 45 35
Bell Zachary A0101500 11 78
Pratt Ricky A0768873 58 39
Stewart Alison A0772659 31 39
Wilkinson Robert A0133880 58 34
Johnson Gregory A0102285 65 12
Duarte Leslie A0347545 9 12
Patterson Glen A0685261 72 25
Griffin Benjamin A0699185 64 96
Bowen Victoria A0795992 44 35
Brown Tracy A0819034 95 33
Montgomery Jamie A0962876 87 74
Peters James A0207655 25 88
Moss Kelly A0302483 52 12
Malone Jacob A0962010 57 87
Perry Eric A0730019 98 97
Perry Eric A0730019 97 98
Perry Eric A0730020 98 97
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Morales Katherine A0253258 93 49
Lucas Jessica A0104732 38 13
Small Alexander A0127412 70 13
Anderson Christina A0973331 56 100
Perry Frank A0856521 52 36
Watson Mitchell A0735949 66 54
Webb Shawn A0526252 87 94
Estrada Sheri A0389976 68 35
Montoya Mark A0367381 5 50
Patterson Sandra A0848894 41 94
Vang Jonathan A0696603 59 33
Scott Cindy A0888243 49 30
Hicks David A0858335 57 63
Berry Jacqueline A0483351 87 68
Washington Kenneth A0696548 51 77
Drake Brenda A0395400 64 5
Ward Alexis A0165533 48 32
Phillips Karen A0354175 65 51
Johnson Kyle A0273834 57 88
E
+106
View File
@@ -0,0 +1,106 @@
2
Johnston Maria A0413808 97 49
Bryant Rhonda A0142192 1 45
Bailey Candice A0834662 98 38
Campbell Matthew A0622975 76 83
May Ryan A0760904 39 97
Miranda David A0330182 86 48
Henry Karen A0431273 15 84
Middleton Sarah A0231710 79 25
Gilbert Howard A0212656 89 73
Castro Robert A0261725 94 12
Lara Robert A0368288 80 80
Lara Robert A0368288 81 80
Lara Robert A0368289 80 81
Wells Brittany A0660122 13 6
Adams Cynthia A0627095 20 20
Morse Douglas A0258366 18 23
Patel Derrick A0570531 64 70
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Brown Brian A0103518 99 1
Lee Patrick A0893874 95 73
Carter Christine A0785415 42 50
Henderson Andrew A0371183 29 58
Anderson Brett A0168017 36 56
Simon Thomas A0517482 50 56
Lane Nancy A0542001 51 30
Smith Anthony A0410478 41 28
Summers Michael A0893440 55 50
Singleton Jordan A0566335 59 10
Lawrence Michelle A0241228 17 22
Castillo Shawn A0908873 65 58
Newman David A0665229 40 53
Richards Shawn A0942153 62 91
Berger Keith A0568406 56 46
Williams Kimberly A0731536 1 6
Terry Marcia A0996692 43 77
Collins Christopher A0669187 8 28
Mclaughlin Stephanie A0766027 31 6
Fowler Clayton A0513357 70 70
Richards Veronica A0958309 49 93
Perkins Arthur A0437488 66 49
Lopez Christine A0396434 80 4
Mclaughlin Brandon A0816497 48 47
Rios Stacey A0296736 69 83
Gray Teresa A0797916 60 60
Chapman Angela A0149524 2 42
Lewis Stacey A0284552 99 97
Day Christopher A0322878 27 48
Williams Richard A0971344 96 46
Ward Mark A0460420 26 44
Dean Derrick A0888238 3 88
Stone James A0364579 79 19
Wagner Kylie A0950922 38 58
Martinez April A0987945 47 58
Dodson Steven A0858775 96 92
Hanna Tiffany A0497426 41 24
Reed Robert A0657526 74 78
Valdez Abigail A0760928 23 30
Rivas Jeremy A0305368 89 12
Morrow Lauren A0916826 90 90
Callahan Amy A0435370 68 67
Brown Shane A0738510 57 70
Porter Michael A0922166 64 69
Bailey Aaron A0208249 52 99
Smith Adam A0782612 81 0
Meza Shannon A0159196 45 35
Bell Zachary A0101500 11 78
Pratt Ricky A0768873 58 39
Stewart Alison A0772659 31 39
Wilkinson Robert A0133880 58 34
Johnson Gregory A0102285 65 12
Duarte Leslie A0347545 9 12
Patterson Glen A0685261 72 25
Griffin Benjamin A0699185 64 96
Bowen Victoria A0795992 44 35
Brown Tracy A0819034 95 33
Montgomery Jamie A0962876 87 74
Peters James A0207655 25 88
Moss Kelly A0302483 52 12
Malone Jacob A0962010 57 87
Perry Eric A0730019 98 97
Perry Eric A0730019 97 98
Perry Eric A0730020 98 97
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Morales Katherine A0253258 93 49
Lucas Jessica A0104732 38 13
Small Alexander A0127412 70 13
Anderson Christina A0973331 56 100
Perry Frank A0856521 52 36
Watson Mitchell A0735949 66 54
Webb Shawn A0526252 87 94
Estrada Sheri A0389976 68 35
Montoya Mark A0367381 5 50
Patterson Sandra A0848894 41 94
Vang Jonathan A0696603 59 33
Scott Cindy A0888243 49 30
Hicks David A0858335 57 63
Berry Jacqueline A0483351 87 68
Washington Kenneth A0696548 51 77
Drake Brenda A0395400 64 5
Ward Alexis A0165533 48 32
Phillips Karen A0354175 65 51
Johnson Kyle A0273834 57 88
E
+106
View File
@@ -0,0 +1,106 @@
3
Johnston Maria A0413808 97 49
Bryant Rhonda A0142192 1 45
Bailey Candice A0834662 98 38
Campbell Matthew A0622975 76 83
May Ryan A0760904 39 97
Miranda David A0330182 86 48
Henry Karen A0431273 15 84
Middleton Sarah A0231710 79 25
Gilbert Howard A0212656 89 73
Castro Robert A0261725 94 12
Lara Robert A0368288 80 80
Lara Robert A0368288 81 80
Lara Robert A0368289 80 81
Wells Brittany A0660122 13 6
Adams Cynthia A0627095 20 20
Morse Douglas A0258366 18 23
Patel Derrick A0570531 64 70
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Brown Brian A0103518 99 1
Lee Patrick A0893874 95 73
Carter Christine A0785415 42 50
Henderson Andrew A0371183 29 58
Anderson Brett A0168017 36 56
Simon Thomas A0517482 50 56
Lane Nancy A0542001 51 30
Smith Anthony A0410478 41 28
Summers Michael A0893440 55 50
Singleton Jordan A0566335 59 10
Lawrence Michelle A0241228 17 22
Castillo Shawn A0908873 65 58
Newman David A0665229 40 53
Richards Shawn A0942153 62 91
Berger Keith A0568406 56 46
Williams Kimberly A0731536 1 6
Terry Marcia A0996692 43 77
Collins Christopher A0669187 8 28
Mclaughlin Stephanie A0766027 31 6
Fowler Clayton A0513357 70 70
Richards Veronica A0958309 49 93
Perkins Arthur A0437488 66 49
Lopez Christine A0396434 80 4
Mclaughlin Brandon A0816497 48 47
Rios Stacey A0296736 69 83
Gray Teresa A0797916 60 60
Chapman Angela A0149524 2 42
Lewis Stacey A0284552 99 97
Day Christopher A0322878 27 48
Williams Richard A0971344 96 46
Ward Mark A0460420 26 44
Dean Derrick A0888238 3 88
Stone James A0364579 79 19
Wagner Kylie A0950922 38 58
Martinez April A0987945 47 58
Dodson Steven A0858775 96 92
Hanna Tiffany A0497426 41 24
Reed Robert A0657526 74 78
Valdez Abigail A0760928 23 30
Rivas Jeremy A0305368 89 12
Morrow Lauren A0916826 90 90
Callahan Amy A0435370 68 67
Brown Shane A0738510 57 70
Porter Michael A0922166 64 69
Bailey Aaron A0208249 52 99
Smith Adam A0782612 81 0
Meza Shannon A0159196 45 35
Bell Zachary A0101500 11 78
Pratt Ricky A0768873 58 39
Stewart Alison A0772659 31 39
Wilkinson Robert A0133880 58 34
Johnson Gregory A0102285 65 12
Duarte Leslie A0347545 9 12
Patterson Glen A0685261 72 25
Griffin Benjamin A0699185 64 96
Bowen Victoria A0795992 44 35
Brown Tracy A0819034 95 33
Montgomery Jamie A0962876 87 74
Peters James A0207655 25 88
Moss Kelly A0302483 52 12
Malone Jacob A0962010 57 87
Perry Eric A0730019 98 97
Perry Eric A0730019 97 98
Perry Eric A0730020 98 97
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Morales Katherine A0253258 93 49
Lucas Jessica A0104732 38 13
Small Alexander A0127412 70 13
Anderson Christina A0973331 56 100
Perry Frank A0856521 52 36
Watson Mitchell A0735949 66 54
Webb Shawn A0526252 87 94
Estrada Sheri A0389976 68 35
Montoya Mark A0367381 5 50
Patterson Sandra A0848894 41 94
Vang Jonathan A0696603 59 33
Scott Cindy A0888243 49 30
Hicks David A0858335 57 63
Berry Jacqueline A0483351 87 68
Washington Kenneth A0696548 51 77
Drake Brenda A0395400 64 5
Ward Alexis A0165533 48 32
Phillips Karen A0354175 65 51
Johnson Kyle A0273834 57 88
E
+106
View File
@@ -0,0 +1,106 @@
4
Johnston Maria A0413808 97 49
Bryant Rhonda A0142192 1 45
Bailey Candice A0834662 98 38
Campbell Matthew A0622975 76 83
May Ryan A0760904 39 97
Miranda David A0330182 86 48
Henry Karen A0431273 15 84
Middleton Sarah A0231710 79 25
Gilbert Howard A0212656 89 73
Castro Robert A0261725 94 12
Lara Robert A0368288 80 80
Lara Robert A0368288 81 80
Lara Robert A0368289 80 81
Wells Brittany A0660122 13 6
Adams Cynthia A0627095 20 20
Morse Douglas A0258366 18 23
Patel Derrick A0570531 64 70
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Brown Brian A0103518 99 1
Lee Patrick A0893874 95 73
Carter Christine A0785415 42 50
Henderson Andrew A0371183 29 58
Anderson Brett A0168017 36 56
Simon Thomas A0517482 50 56
Lane Nancy A0542001 51 30
Smith Anthony A0410478 41 28
Summers Michael A0893440 55 50
Singleton Jordan A0566335 59 10
Lawrence Michelle A0241228 17 22
Castillo Shawn A0908873 65 58
Newman David A0665229 40 53
Richards Shawn A0942153 62 91
Berger Keith A0568406 56 46
Williams Kimberly A0731536 1 6
Terry Marcia A0996692 43 77
Collins Christopher A0669187 8 28
Mclaughlin Stephanie A0766027 31 6
Fowler Clayton A0513357 70 70
Richards Veronica A0958309 49 93
Perkins Arthur A0437488 66 49
Lopez Christine A0396434 80 4
Mclaughlin Brandon A0816497 48 47
Rios Stacey A0296736 69 83
Gray Teresa A0797916 60 60
Chapman Angela A0149524 2 42
Lewis Stacey A0284552 99 97
Day Christopher A0322878 27 48
Williams Richard A0971344 96 46
Ward Mark A0460420 26 44
Dean Derrick A0888238 3 88
Stone James A0364579 79 19
Wagner Kylie A0950922 38 58
Martinez April A0987945 47 58
Dodson Steven A0858775 96 92
Hanna Tiffany A0497426 41 24
Reed Robert A0657526 74 78
Valdez Abigail A0760928 23 30
Rivas Jeremy A0305368 89 12
Morrow Lauren A0916826 90 90
Callahan Amy A0435370 68 67
Brown Shane A0738510 57 70
Porter Michael A0922166 64 69
Bailey Aaron A0208249 52 99
Smith Adam A0782612 81 0
Meza Shannon A0159196 45 35
Bell Zachary A0101500 11 78
Pratt Ricky A0768873 58 39
Stewart Alison A0772659 31 39
Wilkinson Robert A0133880 58 34
Johnson Gregory A0102285 65 12
Duarte Leslie A0347545 9 12
Patterson Glen A0685261 72 25
Griffin Benjamin A0699185 64 96
Bowen Victoria A0795992 44 35
Brown Tracy A0819034 95 33
Montgomery Jamie A0962876 87 74
Peters James A0207655 25 88
Moss Kelly A0302483 52 12
Malone Jacob A0962010 57 87
Perry Eric A0730019 98 97
Perry Eric A0730019 97 98
Perry Eric A0730020 98 97
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Morales Katherine A0253258 93 49
Lucas Jessica A0104732 38 13
Small Alexander A0127412 70 13
Anderson Christina A0973331 56 100
Perry Frank A0856521 52 36
Watson Mitchell A0735949 66 54
Webb Shawn A0526252 87 94
Estrada Sheri A0389976 68 35
Montoya Mark A0367381 5 50
Patterson Sandra A0848894 41 94
Vang Jonathan A0696603 59 33
Scott Cindy A0888243 49 30
Hicks David A0858335 57 63
Berry Jacqueline A0483351 87 68
Washington Kenneth A0696548 51 77
Drake Brenda A0395400 64 5
Ward Alexis A0165533 48 32
Phillips Karen A0354175 65 51
Johnson Kyle A0273834 57 88
E
+106
View File
@@ -0,0 +1,106 @@
5
Johnston Maria A0413808 97 49
Bryant Rhonda A0142192 1 45
Bailey Candice A0834662 98 38
Campbell Matthew A0622975 76 83
May Ryan A0760904 39 97
Miranda David A0330182 86 48
Henry Karen A0431273 15 84
Middleton Sarah A0231710 79 25
Gilbert Howard A0212656 89 73
Castro Robert A0261725 94 12
Lara Robert A0368288 80 80
Lara Robert A0368288 81 80
Lara Robert A0368289 80 81
Wells Brittany A0660122 13 6
Adams Cynthia A0627095 20 20
Morse Douglas A0258366 18 23
Patel Derrick A0570531 64 70
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Brown Brian A0103518 99 1
Lee Patrick A0893874 95 73
Carter Christine A0785415 42 50
Henderson Andrew A0371183 29 58
Anderson Brett A0168017 36 56
Simon Thomas A0517482 50 56
Lane Nancy A0542001 51 30
Smith Anthony A0410478 41 28
Summers Michael A0893440 55 50
Singleton Jordan A0566335 59 10
Lawrence Michelle A0241228 17 22
Castillo Shawn A0908873 65 58
Newman David A0665229 40 53
Richards Shawn A0942153 62 91
Berger Keith A0568406 56 46
Williams Kimberly A0731536 1 6
Terry Marcia A0996692 43 77
Collins Christopher A0669187 8 28
Mclaughlin Stephanie A0766027 31 6
Fowler Clayton A0513357 70 70
Richards Veronica A0958309 49 93
Perkins Arthur A0437488 66 49
Lopez Christine A0396434 80 4
Mclaughlin Brandon A0816497 48 47
Rios Stacey A0296736 69 83
Gray Teresa A0797916 60 60
Chapman Angela A0149524 2 42
Lewis Stacey A0284552 99 97
Day Christopher A0322878 27 48
Williams Richard A0971344 96 46
Ward Mark A0460420 26 44
Dean Derrick A0888238 3 88
Stone James A0364579 79 19
Wagner Kylie A0950922 38 58
Martinez April A0987945 47 58
Dodson Steven A0858775 96 92
Hanna Tiffany A0497426 41 24
Reed Robert A0657526 74 78
Valdez Abigail A0760928 23 30
Rivas Jeremy A0305368 89 12
Morrow Lauren A0916826 90 90
Callahan Amy A0435370 68 67
Brown Shane A0738510 57 70
Porter Michael A0922166 64 69
Bailey Aaron A0208249 52 99
Smith Adam A0782612 81 0
Meza Shannon A0159196 45 35
Bell Zachary A0101500 11 78
Pratt Ricky A0768873 58 39
Stewart Alison A0772659 31 39
Wilkinson Robert A0133880 58 34
Johnson Gregory A0102285 65 12
Duarte Leslie A0347545 9 12
Patterson Glen A0685261 72 25
Griffin Benjamin A0699185 64 96
Bowen Victoria A0795992 44 35
Brown Tracy A0819034 95 33
Montgomery Jamie A0962876 87 74
Peters James A0207655 25 88
Moss Kelly A0302483 52 12
Malone Jacob A0962010 57 87
Perry Eric A0730019 98 97
Perry Eric A0730019 97 98
Perry Eric A0730020 98 97
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Morales Katherine A0253258 93 49
Lucas Jessica A0104732 38 13
Small Alexander A0127412 70 13
Anderson Christina A0973331 56 100
Perry Frank A0856521 52 36
Watson Mitchell A0735949 66 54
Webb Shawn A0526252 87 94
Estrada Sheri A0389976 68 35
Montoya Mark A0367381 5 50
Patterson Sandra A0848894 41 94
Vang Jonathan A0696603 59 33
Scott Cindy A0888243 49 30
Hicks David A0858335 57 63
Berry Jacqueline A0483351 87 68
Washington Kenneth A0696548 51 77
Drake Brenda A0395400 64 5
Ward Alexis A0165533 48 32
Phillips Karen A0354175 65 51
Johnson Kyle A0273834 57 88
E
+232
View File
@@ -0,0 +1,232 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#define MIN_OPTION 1
#define MAX_OPTION 5
#define BUFFER_SIZE 50
#define MAX_STUDENTS 111
#define AVERAGE_NINETY_PLUS 1
#define AVERAGE_EIGHTY_TO_NINETY 2
#define AVERAGE_SEVENTY_TO_EIGHTY 3
#define AVERAGE_SIXTY_TO_SEVENTY 4
#define AVERAGE_SIXTY_BELOW 5
#define MIN_THRESHOLD 0
#define MAX_THRESHOLD 101
#define NINETY_PLUS_THRESHOLD 90
#define EIGHTY_PLUS_THRESHOLD 80
#define SEVENTY_PLUS_THRESHOLD 70
#define SIXTY_PLUS_THRESHOLD 60
#define MIN_GRADE 0
#define MAX_GRADE 100
#define EMPTY_STRING ""
char A_NUMBER[] = "A01385066";
typedef struct
{
char lastName[BUFFER_SIZE];
char firstName[BUFFER_SIZE];
char studentNum[BUFFER_SIZE];
int midtermGrade;
int finalGrade;
} STUDENT;
void writeStudents(
char *outputPath,
STUDENT students[MAX_STUDENTS],
size_t numStudents,
size_t minThresholdIncusive,
size_t maxThresholdExclusive
)
{
FILE *outputFile;
outputFile = fopen(outputPath, "w");
if (outputFile == NULL)
{
printf("Failed to open file\n");
return;
}
for (int i = 0; i < numStudents; i++)
{
float average = ((float)students[i].midtermGrade + (float)students[i].finalGrade) / 2;
if (average >= minThresholdIncusive &&
average < maxThresholdExclusive)
{
fprintf(outputFile, "%s %s %s %d %d\n",
students[i].lastName,
students[i].firstName,
students[i].studentNum,
students[i].midtermGrade,
students[i].finalGrade
);
}
}
fclose(outputFile);
}
int compareStudent(const void *a, const void *b)
{
const STUDENT *studentA = (const STUDENT *)a;
const STUDENT *studentB = (const STUDENT *)b;
int cmp = strcmp(studentA->lastName, studentB->lastName);
if (cmp != 0)
{
return cmp;
}
cmp = strcmp(studentA->firstName, studentB->firstName);
if (cmp != 0)
{
return cmp;
}
cmp = strcmp(studentA->studentNum, studentB->studentNum);
if (cmp != 0)
{
return cmp;
}
float diff = studentA->midtermGrade - studentB->midtermGrade;
if (diff != 0)
{
return (diff > 0) - (diff < 0);
}
diff = studentA->finalGrade - studentB->finalGrade;
return (diff > 0) - (diff < 0);
}
int main(int argc, char *argv[])
{
if (argc != 3)
{
printf("Usage: lab7.c <input_file> <output_file>\n");
return 1;
}
char *inputPath;
char *outputPath;
FILE *inputFile;
inputPath = argv[1];
outputPath = argv[2];
inputFile = fopen(inputPath, "r");
if (inputFile == NULL)
{
printf("Failed to open file\n");
return 1;
}
int option;
STUDENT students[MAX_STUDENTS];
size_t numStudents;
numStudents = 0;
fscanf(inputFile, "%d", &option);
if (option < MIN_OPTION || option > MAX_OPTION)
{
printf("Error: Invalid option\n");
return -1;
}
char lastName[BUFFER_SIZE];
char firstName[BUFFER_SIZE];
char studentNum[BUFFER_SIZE];
int midtermGrade;
int finalGrade;
while (fscanf(inputFile, "%s %s %s %d %d",
firstName,
lastName,
studentNum,
&midtermGrade,
&finalGrade
) == 5)
{
if (midtermGrade < MIN_GRADE ||
midtermGrade > MAX_GRADE ||
finalGrade < MIN_GRADE ||
finalGrade > MAX_GRADE)
{
printf("Error: Invalid student grade found\n");
return -1;
}
if (strcmp(firstName, "") == 0 ||
strcmp(lastName, "") == 0 ||
strcmp(studentNum, "") == 0)
{
printf("Error: Missing first name, last name, or student number\n");
return -1;
}
STUDENT newStudent;
strcpy(newStudent.firstName, lastName);
strcpy(newStudent.lastName, firstName);
strcpy(newStudent.studentNum, studentNum);
newStudent.midtermGrade = midtermGrade;
newStudent.finalGrade = finalGrade;
students[numStudents] = newStudent;
numStudents++;
}
fclose(inputFile);
qsort(students, numStudents, sizeof(STUDENT), compareStudent);
size_t minThresholdInclusive;
size_t maxThresholdExclusive;
switch (option)
{
case AVERAGE_NINETY_PLUS:
minThresholdInclusive = NINETY_PLUS_THRESHOLD;
maxThresholdExclusive = MAX_THRESHOLD;
break;
case AVERAGE_EIGHTY_TO_NINETY:
minThresholdInclusive = EIGHTY_PLUS_THRESHOLD;
maxThresholdExclusive = NINETY_PLUS_THRESHOLD;
break;
case AVERAGE_SEVENTY_TO_EIGHTY:
minThresholdInclusive = SEVENTY_PLUS_THRESHOLD;
maxThresholdExclusive = EIGHTY_PLUS_THRESHOLD;
break;
case AVERAGE_SIXTY_TO_SEVENTY:
minThresholdInclusive = SIXTY_PLUS_THRESHOLD;
maxThresholdExclusive = SEVENTY_PLUS_THRESHOLD;
break;
case AVERAGE_SIXTY_BELOW:
minThresholdInclusive = MIN_THRESHOLD;
maxThresholdExclusive = SIXTY_PLUS_THRESHOLD;
break;
default:
printf("Error: Invalid option\n");
return -1;
}
writeStudents(
outputPath,
students,
numStudents,
minThresholdInclusive,
maxThresholdExclusive
);
return 0;
}
+61
View File
@@ -0,0 +1,61 @@
Adams Cynthia A0627095 20 20
Anderson Brett A0168017 36 56
Bell Zachary A0101500 11 78
Berger Keith A0568406 56 46
Bowen Victoria A0795992 44 35
Brown Brian A0103518 99 1
Bryant Rhonda A0142192 1 45
Carter Christine A0785415 42 50
Castro Robert A0261725 94 12
Chapman Angela A0149524 2 42
Collins Christopher A0669187 8 28
Day Christopher A0322878 27 48
Dean Derrick A0888238 3 88
Drake Brenda A0395400 64 5
Duarte Leslie A0347545 9 12
Estrada Sheri A0389976 68 35
Hanna Tiffany A0497426 41 24
Henderson Andrew A0371183 29 58
Henry Karen A0431273 15 84
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Johnson Gregory A0102285 65 12
Lane Nancy A0542001 51 30
Lawrence Michelle A0241228 17 22
Lopez Christine A0396434 80 4
Lucas Jessica A0104732 38 13
Martinez April A0987945 47 58
Mclaughlin Brandon A0816497 48 47
Mclaughlin Stephanie A0766027 31 6
Meza Shannon A0159196 45 35
Middleton Sarah A0231710 79 25
Montoya Mark A0367381 5 50
Morse Douglas A0258366 18 23
Moss Kelly A0302483 52 12
Newman David A0665229 40 53
Patterson Glen A0685261 72 25
Perkins Arthur A0437488 66 49
Perry Frank A0856521 52 36
Peters James A0207655 25 88
Phillips Karen A0354175 65 51
Pratt Ricky A0768873 58 39
Rivas Jeremy A0305368 89 12
Scott Cindy A0888243 49 30
Simon Thomas A0517482 50 56
Singleton Jordan A0566335 59 10
Small Alexander A0127412 70 13
Smith Adam A0782612 81 0
Smith Anthony A0410478 41 28
Stewart Alison A0772659 31 39
Stone James A0364579 79 19
Summers Michael A0893440 55 50
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Valdez Abigail A0760928 23 30
Vang Jonathan A0696603 59 33
Wagner Kylie A0950922 38 58
Ward Alexis A0165533 48 32
Ward Mark A0460420 26 44
Wells Brittany A0660122 13 6
Wilkinson Robert A0133880 58 34
Williams Kimberly A0731536 1 6
+7
View File
@@ -0,0 +1,7 @@
Dodson Steven A0858775 96 92
Lewis Stacey A0284552 99 97
Morrow Lauren A0916826 90 90
Perry Eric A0730019 97 98
Perry Eric A0730019 98 97
Perry Eric A0730020 98 97
Webb Shawn A0526252 87 94
+7
View File
@@ -0,0 +1,7 @@
Gilbert Howard A0212656 89 73
Griffin Benjamin A0699185 64 96
Lara Robert A0368288 80 80
Lara Robert A0368288 81 80
Lara Robert A0368289 80 81
Lee Patrick A0893874 95 73
Montgomery Jamie A0962876 87 74
+14
View File
@@ -0,0 +1,14 @@
Anderson Christina A0973331 56 100
Bailey Aaron A0208249 52 99
Berry Jacqueline A0483351 87 68
Campbell Matthew A0622975 76 83
Fowler Clayton A0513357 70 70
Johnson Kyle A0273834 57 88
Johnston Maria A0413808 97 49
Malone Jacob A0962010 57 87
Morales Katherine A0253258 93 49
Reed Robert A0657526 74 78
Richards Shawn A0942153 62 91
Richards Veronica A0958309 49 93
Rios Stacey A0296736 69 83
Williams Richard A0971344 96 46
+15
View File
@@ -0,0 +1,15 @@
Bailey Candice A0834662 98 38
Brown Shane A0738510 57 70
Brown Tracy A0819034 95 33
Callahan Amy A0435370 68 67
Castillo Shawn A0908873 65 58
Gray Teresa A0797916 60 60
Hicks David A0858335 57 63
May Ryan A0760904 39 97
Miranda David A0330182 86 48
Patel Derrick A0570531 64 70
Patterson Sandra A0848894 41 94
Porter Michael A0922166 64 69
Terry Marcia A0996692 43 77
Washington Kenneth A0696548 51 77
Watson Mitchell A0735949 66 54
+61
View File
@@ -0,0 +1,61 @@
Adams Cynthia A0627095 20 20
Anderson Brett A0168017 36 56
Bell Zachary A0101500 11 78
Berger Keith A0568406 56 46
Bowen Victoria A0795992 44 35
Brown Brian A0103518 99 1
Bryant Rhonda A0142192 1 45
Carter Christine A0785415 42 50
Castro Robert A0261725 94 12
Chapman Angela A0149524 2 42
Collins Christopher A0669187 8 28
Day Christopher A0322878 27 48
Dean Derrick A0888238 3 88
Drake Brenda A0395400 64 5
Duarte Leslie A0347545 9 12
Estrada Sheri A0389976 68 35
Hanna Tiffany A0497426 41 24
Henderson Andrew A0371183 29 58
Henry Karen A0431273 15 84
Hernandez Denise A0874151 55 57
Hughes Cynthia A0816146 41 68
Johnson Gregory A0102285 65 12
Lane Nancy A0542001 51 30
Lawrence Michelle A0241228 17 22
Lopez Christine A0396434 80 4
Lucas Jessica A0104732 38 13
Martinez April A0987945 47 58
Mclaughlin Brandon A0816497 48 47
Mclaughlin Stephanie A0766027 31 6
Meza Shannon A0159196 45 35
Middleton Sarah A0231710 79 25
Montoya Mark A0367381 5 50
Morse Douglas A0258366 18 23
Moss Kelly A0302483 52 12
Newman David A0665229 40 53
Patterson Glen A0685261 72 25
Perkins Arthur A0437488 66 49
Perry Frank A0856521 52 36
Peters James A0207655 25 88
Phillips Karen A0354175 65 51
Pratt Ricky A0768873 58 39
Rivas Jeremy A0305368 89 12
Scott Cindy A0888243 49 30
Simon Thomas A0517482 50 56
Singleton Jordan A0566335 59 10
Small Alexander A0127412 70 13
Smith Adam A0782612 81 0
Smith Anthony A0410478 41 28
Stewart Alison A0772659 31 39
Stone James A0364579 79 19
Summers Michael A0893440 55 50
Swanson Alan A0730535 33 18
Taylor Andrew A0139853 49 13
Valdez Abigail A0760928 23 30
Vang Jonathan A0696603 59 33
Wagner Kylie A0950922 38 58
Ward Alexis A0165533 48 32
Ward Mark A0460420 26 44
Wells Brittany A0660122 13 6
Wilkinson Robert A0133880 58 34
Williams Kimberly A0731536 1 6