Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

solve the functions // function.c #include #include #include #include #include // Given a gradebook file, return the minimum of the specified column, excluding unavailable scores

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
solve the functions
// function.c
#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 0
double getGrade(char filename[], char first[], char last[])
{
return -1.0; // not exist
}
// main.c
#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 isValidColumn(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("\thelp ");
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 (isValidColumn(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;
}
i dont know how to solve for any of the functions on function.c (the code without any real input)
functions include:
getMin
getMax
getAvg
getCount
getGrade
In this project, you will implement a set of functions that can be used to retrieve information from a CS100 grade book stored in a text file (Please download an example gradebook file named case 11.bxt and use Visual Studio Code to view the structure of the file.) 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 zyBooks 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 O in one function and is excluded in the other computation functions. You are asked to implement the following five functions in the functions.c file double getMin(char filenamell, char column []); Given a gradebook file, return the minimum of the specified column, excluding unavailable scores double getMax (char filenamell, char column []); Given a gradebook file, return the maximum of the specified column, excluding unavailable scores double getAvg (char filenamell, char column []); Given a gradebook file, return the average of the specified column, excluding unavailable scores 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 filenamel], 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. Column Weight Percentage Score Range L1 through L10 1% for each lab 0-100 B1 through 110 1% for each zyBooks 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 When implementing the above functions, you can assume the column name is always valid, and the gradebook file can always be opened for reading. The gradebook file always follows the table structure described above. You can also assume there is at least one actual score in each column. You are allowed to add some helper functions in functions.c. For example, it is probably helpful to find the column number from a given column name by searching the column name in the header line, and you can write a helper function to perform the searching. Based on the column number, you may want to retrieve the column value from a student line, and you can write another helper function to achieve it. Sample Execution $ ./a.out casell.txt Enter a command: min B1 min (B1)=10.7 Enter a command: min P3 min (P3) = 7 Enter a command: max 15 max (B5) 100 Enter a command: max P4 max (P4)-100 Enter a command: avg E4 avg (E4) -87.913 Enter a command: avg 17 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 command: count 14 100 count (L4>100)-26 Enter a command: count 14 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 #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; } Il Given a gradebook file, return the average of the specified column, excluding unavailable scores double get Avg(char filename(), char column[]) { return 3.3; } 1/ 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 } main.c. 1 #include 2 include 3 Tinclude 4 Fanclude 5 Tinclude = threshold, excluding unavailable scores 17 int getCount(char filenane (), char column [], double threshold); 12 13 14 15 I 18 19 20 21 22 23 24 25 26 27 28 29 30 1/ 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 a double getGrade(char talenanel), char first dl, char last(): int 19ValadColumn(char column()) ( char type: int num sscanf (column, cd", stype, Gun); switch (type) case 'L': 11 (nunda | NUB10) return; break; case 'E': if (nud Il nud) return 0; breaks case 3: sf (d 1 D10) return 0; breaks case pis if (nued || nb) return; break; defaults return o) 36 37 38 39 40 char column2[strlen(column)-1]; sprintf(column2, "chd", type, nun) if (strop column, column2)1=6) return ; return 15 void printHelp() e 51 S2 53 54 55 56 57 58 printf(" The valid commands) printf("\thin count") printf("\to find the sininus of the specified column, excluding unavailable scores in"); printf("\tess for examples in PA ") 5 57 ER 2 14 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 prantti"\t for example: "); printf("\tnax coluninn"); printf("\ts and the maximum of the specified colunt, excluding wavaslable scores W) printf("\ts for example: max Ell"): printf("\tavg column) printf("\tes find the average of the specified coluna, excluding available scores W) printf("\tes for example: avg 010 "); printf("\tcount column threshold\A); printf("\tess find the number of rows with its column value xe threshold, excluding unavailable scores) printf("\tess for example: count L2 68 "); printf("\tgrade firstnane lastname "); printf("\tese find the weighted average of the specified student. An unavailable score is viewed as ) printf("\tes for example: grade John Smith "); printf("\tquit "); printf("\to quit this program "); printf("\thelpin"); printf("\tese print this listin"); } int main(int argc, char sargv[]) 1f (argct-2) printf("Usage: s filename ", argv[0]); return 15 > FILE efpefopen(argv[1], "r"); if (NULL) printf("Unable to open for reading ", argv[1]) return 2: > fclose(fp): 87 88 89 90 91 92 93 94 95 97 98 99 100 18 102 while (1) char ond(30); char column (30); char Line (300): printf(" Enter a command: "); scanf("s", cad); if (strcpicad, "quit")) break; if (strcplcnd, "grade")) { char first (30), last (30); scanf("s", first, last): double gradeegetGradecargv[11, first, last); if (grade) printf("grades seng ", first, last, grade) else printf("No student named As in, first, last); > else if (strcapacad, "In")) { scanf("us", column): if (isvalidColumn(column)) { double Ringetkin(argv (1), column) printf("nin(s)wag ",column, ain); > else ( printf("s: Invalid column name. 16", column) gets(line, 308, stdin) // skip the rest of line 1e4 185 106 107 103 109 110 111 112 113 114 115 fgets(line, 300, stdin); // skip the rest of line else if (strcmp(cnd, "max")) { scanf("%s", column): if (isvalidColumn(column)) { double naxagetMax(argv[1], column); printf("max (as)=A ", colunn, max); else { printf("us: Invalid column name. In", colunta): fgets(line, 300, stdin); 11 skip the rest of line 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 else if (strcmp(cnd, "avg")) { scanf("%s", column); If (isvalidColumn(column)) { double avgegetAvg(argv[1], column); printf("avg(4) ", column, avg); > else { printf("s: Invalid column nane. In'', column); tgets(line, 300, stdin); // skip the rest of line else if (strcplcnd,"count")) { scanf("us", column); if (isolidColumn(column)) { double threshold; scanf("11", threshold) int count-getCount(argv[1], column, threshold); printf("count ( hg) wad ", column, threshold, count); else printf("1 Invalid column nane. In", column) fgets(line, 300, stdin); // skip the rest of line else if (strcmp(ond, "help")--) { printHelp(); > else printf("%s: Invalid command. Type help for help. In", cod); fgets(line, 300, stdini // skip the rest of Line > return 9 180 100 54 90 87 First Last P1 L1 B1 P2 12 82 0 B 1 P3 L4 B4 LS LS P4 BS 66 E2 LI B7 P U L9 P6 E3 88 L10B 818 E4 Lloyd Gibbons 100 100 100 100 95 102 86 100 100 100 100 100 100 95 100 100 100 100 100 100 100 100 70 99 44 100 100 100 100 100 Eleonora Schlosser 97 32 99.2 97 85 95.9 54 93.5 24 829 93.5 98 100 97 97.3 94.9 92 100 97.6 100 100 100 5 B5 97.6 4 Judith Tignor 3 100 99.2 108 95 100 100 9S 20 62 100 100 85 100 100 100 78 100 100 96 140 140 95 94 100 100 100 100 97 5 Maida Mood 100 100 100 100 100 100 90 100 100 70 100 100 100 79 100 100 100 91 100 100 100 100 90 92 94 100 100 100 100 100 E Kayla Bruner 100 100 100 85 95 102 86 140 140 80 30 100 100 100 75 100 101 79 100 100 100 100 74 83 100 100 100 100 81 Tajuana Galloway 93 100 100 100 90 100 86 10 90 100 100 100 100 100 % 100 1 81 100 100 65 100 90 69 73 160 50 100 100 83 Shantae Carcano 100 100 100 100 100 100 100 100 100 100 100 100 100 16 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 96 9 Cayle Tash 100 100 100 100 100 100 100 100 92 96 100 100 100 100 100 100 100 6 98 100 100 100 100 95 95 100 100 100 96 90 Keneth Cuesta 100 100 9.7 100 95 100 100 100 88 25 100 100 100 85 10 10 76 100 100 96 100 100 34 94 100 na 100 100 100 11 Evangelina Bozeman 100 100 100 100 9900 99 100 100 25 100 100 100 65 100 100 100 100 100 100 100 100 100 97 100 100 100 100 100 71 22 Owen Moniz 100 100 10.7 100 96 97.9 100 100 92 100 100 100 100 100 100 93.2 140 100 100 97 100 100 95 48 100 100 100 46 IN 1 Aurelio Alto 100 100 100 100 80 100 100 90 100 72 100 70 86 100 100 100 100 100 100 52 100 100 72 89 100 100 100 100 100 14 Marcene Rothenberg 100 100 100 100 100 100 86 100 200 85 58 100 100 100 100 100 44 100 100 10 100 100 88 78 100 100 100 100 55 15 Sharla Mattocks 200 90 98.6 100 100 100 100 100 100 95 100 100 70 100 % 100 100 94 100 100 100 100 100 91 100 100 60 100 100 69 16 Rob Pauls 100 100 100 100 100 100 100 100 100 99 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 Calandra Ungar 100 100 100 97 100 100 100 100 100 100 100 100 100 100 100 80 100 100 100 100 100 89 100 100 100 100 100 92 18 DeLoris Schoenborn 100 100 99.2 93 100 99 86 96.3 78 82 108 85.6 100 72 na 95.2 91 100 100 100 90 95 58 81 100 100 100 19 Brigette Finney 94 86 87.9 91 91 98.5 54 100 95 12 96 100 65 79 100 97.6 180 64 100 100 100 100 40 77 82 100 100 100 100 20 Milissa Mobley 100 100 100 96 95 100 100 100 100 81 100 100 100 86 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 92 21 Huong Letson 7 10 11 5 9.5 86 100 85 40 98 100 15 79 98.8 100 100 100 68 100 90 53 100 100 100 100 100 97 22 Ella Vike 100 100 99.2 101 100 99.5 100 100 96 100 100 100 100 100 95 100 100 100 100 100 76 100 100 100 100 100 100 100 100 100 23 Buske KIA 6 l 1 v 19 n 10010 11 10 9 85 1 1 1 1 1 1 10 10 109 10 1 0 0 24 Storey Beaufort 100 100 96.1 se 100 96.4 MB 96.3 85 N na 100 86 1 91.5 82 100 100 100 100 100 na 94 100 100 100 100 95 25 Reel 100 100 100 100 100 100 100 100 100 70 100 100 100 6 100 100 100 85 100 100 100 100 100 92 100 100 100 100 100 100 26 Rosy Hammontree 100 100 90.9 100 100 100 16 100 100 21 120 100 799 100 10 100 100 100 97 m 100 90 100 100 100 100 100 100 27 Armand Bladen 97 100 100 100 80 100 93 100 91 85 50 100 100 72 78 100 100 100 100 100 100 200 55 94 100 100 100 100 85 23 Francisco Masters 100 100 100 100 95 100 100 100 75 10 37 100 679 100 100 100 70 100 100 99 100 100 74 63 100 100 100 100 87 29 Aleida Francoeur 100 90 100 100 100 100 16 100 100 10 56 120 100 36 22 100 10 0 73 100 7 190 100 94 180 80 100 100 71 30 Nicola Alto 100 100 100 100 100 100 100 92 70 100 100 100 100 95 100 100 100 100 100 98 100 100 99 100 100 100 100 100 100 31 Dimple Watson 100 se 100 100 100 98.5 100 100 100 85 100 100 100 100 100 100 98.3 100 70 100 100 100 100 92 100 100 10 100 100 100 32 Major Witherite 93 92 99.4 100 95 100 99 100 100 85 98 100 380 722S 100 100 70 na 100 200 98 100 91 95 100 100 100 100 96 33 Louanne Fisch 97 098.3 94 41 97.4 100 100 50 25 70 100 es 50 100 100 100 38 100 100 95 200 95 50 82 100 100 100 100 51 34 Lan Mazon 97 100 100 100 95 100 29 101 91 65 100 100 100 16 100 100 100 100 100 100 97 100 16 49 94 100 100 100 3 35 Elias Kasel 180 @ 93.3 380 90 100 77 300 847 na 100 100 868 97.6 100 39 na 100 94 100 95 28 50 100 100 100 98 61 36 Kaley Pawlak 90 95 100 100 100 97 100 100 96 100 100 90 86 95 100 100 99 100 100 60 120 90 100 99 100 100 100 100 96 37 Analia Neiss 97 100 100 95 97.4 86 98.1 95 BS 72 99.3 693 100 95.2 90.2 75 100 300 40 100 100 69 36 100 100 100 92 62 38 Shando Nicley 300 52 98.6 97 72 100 100 100 79 100 100 100 100 86 95 100 100 95 100 100 100 100 100 73 94 1805 180 100 67 Harry Sessions 184 in 10 109 110 10 9 85 10 10 10 109 10 11 1 1 5 10 20 19 18 17 16 18 19 GB Jeannine Kleinan 100 na 100 100 99.5 100 100 89 10 17 100 100 100 100 95.2 100 64 200 1007 100 100 46 99 100 100 92 Stacee Andres 10 100 100 93 95 90.5 17 100 70 22 77 91.5 90 93 na 93.9 78 76 102 303 35 108 95 32 100 100 100 33 42 Sherell Calabrese 100 100 100 100 100 100 100 95 65 86 100 70 36 100 100 100 12 100 100 100 100 100 100 100 100 100 100 100 43 Karan Bengtson 95 76 95.6 100 75 97.9 100 100 112 25 100 100 76 93 100 100 100 76 100 100 100 100 100 59 58 100 100 100 100 67 44 Herlin Shuford 100 100 100 100 100 100 50 100 100 100 100 100 100 100 96 100 100 1 100 100 100 100 100 100 100 100 100 100 100 96 45 Bill Fleckenstein $ 696 160 96 100 100 76 94.4 99 100 100 100 100 86 100 100 82 70 100 76 100 100 92 14 16 100 100 93 Jonathan Kisling 97 56 100 100 100 100 100 100 100 10 100 100 100 100 91.2 100 64 100 100 100 100 100 61 34 100 100 100 84 23 47 Valarie Teoksbury 100 100 100 100 90 100 86 100 100 9640 99.3 30 100 85 100 180 64 100 100 90 100 100 78 79 200 50 100 100 88 48 I Grale

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 Concepts

Authors: David Kroenke, David Auer, Scott Vandenberg, Robert Yoder

9th Edition

0135188148, 978-0135188149, 9781642087611

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago