Answered step by step
Verified Expert Solution
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
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:
getMingetMax
getAvg
getCount
getGrade
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started