Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The gradebook file contains a sequence of printable characters and it is structured as a table, with the help of newlines and tabs. The table

The gradebook file contains a sequence of printable characters and it is structured as a table, with the help of newlines and tabs. The table contains exactly 32 columns, and the column names are shown below

  • First and Last for first name and last name.
  • L1 through L10 for 10 labs.
  • B1 through B10 for 10 exercises.
  • P1 through P6 for 6 projects.
  • E1 through E4 for 4 exams.

The first two columns are always the first name and the last name. The order of the remaining 30 columns is unknown. The first line of the file is the header line and it is a list of column names separated by tabs. Each following line represents a student. The number of students in the file is unknown either. Each student has exactly 32 fields separated by tabs. The first two fields are the first and last names of the student. The first and last names can contain up to 30 letters, and no two students have the same full name. Each student has 30 score fields and their values are either a double ranging from 0 through 100, or na (for not available). An unavailable score is viewed as 0 in one function and is excluded in the other computation functions.

  • double getMin(char filename[], char column[]); Given a gradebook file, return the minimum of the specified column,
  • double getMax(char filename[], char column[]); Given a gradebook file, return the minimum of the specified column,
  • double getAvg(char filename[], char column[]); Given a gradebook file, return the minimum of the specified column,
  • int getCount(char filename[], char column[], double threshold); Given a gradebook file, return the number of students with their column value >= threshold, excluding unavailable scores.
  • double getGrade(char filename[], char first[], char last[]); Given a gradebook file, return the weighted average of the specified student or -1.0 if there is no such student. An unavailable score is viewed as 0. The weight percentage for each column is specified below.
Colume Weight percentage Score range
L1 through L10 1% for each lab 0-100
B1 through B10 1% for each exercise 0-100
P1 through P6 2% for P1 5% each for P2, P3 6% each for P4, P5, P6 0-100
E1 through E4 10% each for E1, E2, E3 20% for E4 0-100

What to do

  • To compile this program, use gcc -Wall -std=c99 main.c functions.c -lm -o a.out
  • Please do not change main.c. You just need to complete functions.c.
  • Please test with ./a.out case11.txt. A sample execution of the program is shown below.

image text in transcribed

image text in transcribed

image text in transcribed

Function.c

image text in transcribed

Main.c

image text in transcribed

Sample Execution $ ./a.out case11.txt Enter a command: min B1 min (B1)=10.7 Enter a command: min P3 min (P3)=7 Enter a command: max B5 max (B5)=100 Enter a command: max P4 max (P4)-100 Enter a command: avg E4 avg (E4)=87.913 Enter a command: avg L7 avg (L7)=97.7955 Enter a command: count E4 100 count (E4>=100)=14 Enter a command: count E4 60 count (E4>=60) = 44 Enter a command: count L4 100 count (L4>=100)=26 Enter a command: count L4 90 count (L4>=90) =31 Enter a command: grade Louanne Fisch grade (Louanne Fisch)=68.437 Enter a command: grade Stormy Beaufort grade (Stormy Beaufort)=79.463 Enter a command: quit 82 23 85 10.7 100 100 100 hng 100 100 1022 10 100 100 96.1 100 100 100 100 100 100 98.9 100 100 90 100 100 100 100 100 96 100 100 100 92 99.4 100 Elias 95 100 94 100 100 100 94 95 98.616160 100 na 100 Stacee Andres se animale 100 93 95 Tag 100 100 100 76 95.6 100 100 100 100 100 96 96 100 96 Jonathan | Kisling 97 100 100 Valarie Tewksbury 100 100 100 100 100 100 w B6 #include #include #include #include #include // Given a gradebook file, return the minimum of the specified column, excluding unavailable scores double getMin(char filename[], char column[]) { return 1.1; } // Given a gradebook file, return the maximum of the specified column, excluding unavailable scores double getMax(char filename[], char column[]) { return 2.2; } // Given a gradebook file, return the average of the specified column, excluding unavailable scores double getAvg(char filename[], char column[]) { return 3.3; } // Given a gradebook file, return the number of students with their column value >= threshold, excluding unavailable scores int getCount(char filename[], char column[], double threshold) { return 4; } // Given a gradebook file, return the weighted average of the specified student // or -1.0 if there is no such student. // An unavailable score is viewed as O double getGrade(char filename[], char first[], char last[]) { return -1.0; // not exist } #include #include #include #include #include // Given a gradebook file, return the minimum of the specified column, excluding unavailable scores double getMin(char filename[], char column[]); // Given a gradebook file, return the maximum of the specified column, excluding unavailable scores double getMax(char filename[], char column[]); // Given a gradebook file, return the average of the specified column, excluding unavailable scores double getAvg(char filename[], char column[]); // Given a gradebook file, return the number of students with their column value >= threshold, excluding unavailable scores int getCount(char filename[], char column[], double threshold); // Given a gradebook file, return the weighted average of the specified student // or -1.0 if there is no such student. // An unavailable score is viewed as 0 double getGrade(char filename[], char first[], char last[]); int isValid Column(char column()) { char type; int num; sscanf(column, "%c%d", &type, &num); switch (type) { case 'L': if (num10) return 0; break; case 'E': if (num4) return 0; break; case 'B': if (num10) return 0; break; case 'P': if (num6) return 0; break; default: return 0; } char column2[strlen(column)+1]; sprintf(column2, "%c%d", type, num); if (strcmp(column, column2)!=0) return 0; return 1; } void printHelp { printf(" The valid commands: "); printf("\tmin column "); printf("\t*** find the minimum of the specified column, excluding unavailable scores "); printf("\t*** for example: min P4 "); printf("\tmax column "); printf("\t*** find the maximum of the specified column, excluding unavailable scores "); printf("\t*** for example: max E1 "); printf("\tavg column "); printf("\t*** find the average of the specified column, excluding unavailable scores "); printf("\t*** for example: avg B10 "); printf("\tcount column threshold "); printf("\t*** find the number of rows with its column value >= threshold, excluding unavailable scores "); printf("\t*** for example: count L2 60 "); printf("\tgrade firstname lastname "); printf("\t*** find the weighted average of the specified student. An unavailable score is viewed as 0 "); printf("\t*** for example: grade John Smith "); printf("\tquit "); printf("\t*** quit this program "); printf("\thelpin"); printf("\t*** print this list "); } int main(int argc, char *argv[]) { if (argc!=2) { printf("Usage: %s filename ", argv[0]); return 1; } FILE *fp=fopen(argv[1], "r"); if (fp==NULL) { printf("Unable to open %s for reading ", argv[1]); return 2; } fclose(fp); while (1) { char cmd[30]; char column[30]; char line[300]; printf(" Enter a command: "); scanf("%s", cmd); if (strcmp(cmd, "quit")==0) break; if (strcmp(cmd, "grade")==0) { char first[30], last[30]; scanf("%s%s", first, last); double grade=getGrade(argv[1], first, last); if (grade>=0) printf("grade(%s %s)=%g ", first, last, grade); else printf("No student named %s %s ", first, last); } else if (strcmp(cmd, "min")==0) { scanf("%s", column); if (isValid Column(column)) { double min=getMin(argv[1], column); printf("min(%s)=%g ",column, min); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd, "max")==0) { scanf("%s", column); if (isValidColumn(column)) { double max=getMax(argv[1], column); printf("max(%s)=%g ", column, max); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd, "avg")==0) { scanf("%s", column); if (isValidColumn(column)) { double avg=getAvg(argv[1], column); printf("avg(%s)=%g ", column, avg); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd,"count")==0) { scanf("%s", column); if (isValidColumn(column)) { double threshold; scanf("%lf", &threshold); int count=getCount(argv[1], column, threshold); printf("count%s>=%g)=%d ", column, threshold, count); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd, "help")==0) { printHelp(); } else { printf("%s: invalid commmand. Type help for help. ", cmd); fgets(line, 300, stdin); // skip the rest of line } } return 0; } Sample Execution $ ./a.out case11.txt Enter a command: min B1 min (B1)=10.7 Enter a command: min P3 min (P3)=7 Enter a command: max B5 max (B5)=100 Enter a command: max P4 max (P4)-100 Enter a command: avg E4 avg (E4)=87.913 Enter a command: avg L7 avg (L7)=97.7955 Enter a command: count E4 100 count (E4>=100)=14 Enter a command: count E4 60 count (E4>=60) = 44 Enter a command: count L4 100 count (L4>=100)=26 Enter a command: count L4 90 count (L4>=90) =31 Enter a command: grade Louanne Fisch grade (Louanne Fisch)=68.437 Enter a command: grade Stormy Beaufort grade (Stormy Beaufort)=79.463 Enter a command: quit 82 23 85 10.7 100 100 100 hng 100 100 1022 10 100 100 96.1 100 100 100 100 100 100 98.9 100 100 90 100 100 100 100 100 96 100 100 100 92 99.4 100 Elias 95 100 94 100 100 100 94 95 98.616160 100 na 100 Stacee Andres se animale 100 93 95 Tag 100 100 100 76 95.6 100 100 100 100 100 96 96 100 96 Jonathan | Kisling 97 100 100 Valarie Tewksbury 100 100 100 100 100 100 w B6 #include #include #include #include #include // Given a gradebook file, return the minimum of the specified column, excluding unavailable scores double getMin(char filename[], char column[]) { return 1.1; } // Given a gradebook file, return the maximum of the specified column, excluding unavailable scores double getMax(char filename[], char column[]) { return 2.2; } // Given a gradebook file, return the average of the specified column, excluding unavailable scores double getAvg(char filename[], char column[]) { return 3.3; } // Given a gradebook file, return the number of students with their column value >= threshold, excluding unavailable scores int getCount(char filename[], char column[], double threshold) { return 4; } // Given a gradebook file, return the weighted average of the specified student // or -1.0 if there is no such student. // An unavailable score is viewed as O double getGrade(char filename[], char first[], char last[]) { return -1.0; // not exist } #include #include #include #include #include // Given a gradebook file, return the minimum of the specified column, excluding unavailable scores double getMin(char filename[], char column[]); // Given a gradebook file, return the maximum of the specified column, excluding unavailable scores double getMax(char filename[], char column[]); // Given a gradebook file, return the average of the specified column, excluding unavailable scores double getAvg(char filename[], char column[]); // Given a gradebook file, return the number of students with their column value >= threshold, excluding unavailable scores int getCount(char filename[], char column[], double threshold); // Given a gradebook file, return the weighted average of the specified student // or -1.0 if there is no such student. // An unavailable score is viewed as 0 double getGrade(char filename[], char first[], char last[]); int isValid Column(char column()) { char type; int num; sscanf(column, "%c%d", &type, &num); switch (type) { case 'L': if (num10) return 0; break; case 'E': if (num4) return 0; break; case 'B': if (num10) return 0; break; case 'P': if (num6) return 0; break; default: return 0; } char column2[strlen(column)+1]; sprintf(column2, "%c%d", type, num); if (strcmp(column, column2)!=0) return 0; return 1; } void printHelp { printf(" The valid commands: "); printf("\tmin column "); printf("\t*** find the minimum of the specified column, excluding unavailable scores "); printf("\t*** for example: min P4 "); printf("\tmax column "); printf("\t*** find the maximum of the specified column, excluding unavailable scores "); printf("\t*** for example: max E1 "); printf("\tavg column "); printf("\t*** find the average of the specified column, excluding unavailable scores "); printf("\t*** for example: avg B10 "); printf("\tcount column threshold "); printf("\t*** find the number of rows with its column value >= threshold, excluding unavailable scores "); printf("\t*** for example: count L2 60 "); printf("\tgrade firstname lastname "); printf("\t*** find the weighted average of the specified student. An unavailable score is viewed as 0 "); printf("\t*** for example: grade John Smith "); printf("\tquit "); printf("\t*** quit this program "); printf("\thelpin"); printf("\t*** print this list "); } int main(int argc, char *argv[]) { if (argc!=2) { printf("Usage: %s filename ", argv[0]); return 1; } FILE *fp=fopen(argv[1], "r"); if (fp==NULL) { printf("Unable to open %s for reading ", argv[1]); return 2; } fclose(fp); while (1) { char cmd[30]; char column[30]; char line[300]; printf(" Enter a command: "); scanf("%s", cmd); if (strcmp(cmd, "quit")==0) break; if (strcmp(cmd, "grade")==0) { char first[30], last[30]; scanf("%s%s", first, last); double grade=getGrade(argv[1], first, last); if (grade>=0) printf("grade(%s %s)=%g ", first, last, grade); else printf("No student named %s %s ", first, last); } else if (strcmp(cmd, "min")==0) { scanf("%s", column); if (isValid Column(column)) { double min=getMin(argv[1], column); printf("min(%s)=%g ",column, min); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd, "max")==0) { scanf("%s", column); if (isValidColumn(column)) { double max=getMax(argv[1], column); printf("max(%s)=%g ", column, max); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd, "avg")==0) { scanf("%s", column); if (isValidColumn(column)) { double avg=getAvg(argv[1], column); printf("avg(%s)=%g ", column, avg); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd,"count")==0) { scanf("%s", column); if (isValidColumn(column)) { double threshold; scanf("%lf", &threshold); int count=getCount(argv[1], column, threshold); printf("count%s>=%g)=%d ", column, threshold, count); } else { printf("%s: invalid column name. ", column); fgets(line, 300, stdin); // skip the rest of line } } else if (strcmp(cmd, "help")==0) { printHelp(); } else { printf("%s: invalid commmand. Type help for help. ", cmd); fgets(line, 300, stdin); // skip the rest of line } } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 2 Lncs 8056

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013th Edition

3642401724, 978-3642401725

More Books

Students also viewed these Databases questions