Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Here is the (A3b-smallgrades.txt) text file: Here is the (A3b-largegrades.txt) text file: Here is the Program A3a without modification: #include #include #include #include void getGrades(int

image text in transcribed

Here is the (A3b-smallgrades.txt) text file:

image text in transcribed

Here is the (A3b-largegrades.txt) text file:image text in transcribed

Here is the Program A3a without modification:

#include

#include

#include

#include

void getGrades(int ROWS, int COLS, int grades[ROWS][COLS], char students[COLS][20]);

void printGrades(int ROWS, int COLS, int grades[ROWS][COLS]);

void getStudents(int COLS, char students[COLS][20]);

void printStudents(int COLS, char students[COLS][20]);

void calcGrades(int ROWS, int COLS, int grades[ROWS][COLS], char Fgrades[]);

void printFinalGrades(int COLS, char Fgrades[]);

int main()

{

srand(time(0));

int stu = 0, assign = 0;

char input[50];

printf("How many students? ");

fgets(input, sizeof(input), stdin);

sscanf(input, "%d", &stu);

printf("How many assignments? ");

fgets(input, sizeof(input), stdin);

sscanf(input, "%d", &assign);

char students[stu][20];

int grades[assign][stu];

char final_grade[stu];

getStudents(stu, students);

getGrades(assign, stu, grades, students);

calcGrades(assign, stu, grades, final_grade);

printf(" ");

printStudents(stu, students);

printGrades(assign, stu, grades);

printFinalGrades(stu, final_grade);

return 0;

}

void printFinalGrades(int COLS, char Fgrades[])

{

int i = 0;

for (i = 0; i

{

printf("%10c", Fgrades[i]);

}

printf(" ");

}

void calcGrades(int ROWS, int COLS, int grades[ROWS][COLS], char Fgrades[])

{

int avg = 0;

int sum = 0;

int i = 0, j = 0;

for (i = 0; i

{

// Find the sum

sum = 0;

for (j = 0; j

{

sum += grades[j][i];

}

avg = sum / ROWS;

if (avg >= 90)

Fgrades[i] = 'A';

else if (avg >= 80)

Fgrades[i] = 'B';

else if (avg >= 70)

Fgrades[i] = 'C';

else if (avg >= 60)

Fgrades[i] = 'D';

else

Fgrades[i] = 'F';

}

}

void printStudents(int COLS, char students[COLS][20])

{

int i = 0;

int numA = COLS;

for (i = 0; i

{

printf("%10s", students[i]);

}

printf(" ");

}

void getStudents(int COLS, char students[COLS][20])

{

int i = 0, len = 0;

for (i = 0; i

{

printf("Enter name for Student %d: ", i);

fgets(students[i], sizeof(students[i]), stdin);

len = strlen(students[i]);

students[i][len-1] = '\0';

}

}

void printGrades(int ROWS, int COLS, int grades[ROWS][COLS])

{

int i = 0, j = 0;

for (i = 0; i

{

for (j = 0; j

{

printf("%10d", grades[i][j]);

}

printf(" ");

}

}

void getGrades(int ROWS, int COLS, int grades[ROWS][COLS], char students[COLS][20])

{

int i = 0, j = 0;

for (i = 0; i

for (j = 0; j

{

printf("Enter grade for Assignments %d for %s: ", i, students[j]);

scanf("%d", &grades[i][j]);

}

}

This program is a modification of your program for A3a. Instead of accepting input from user through standard input, you will be taking input from a file. You must take the input file name on the command line Be sure to have simple error checking to be sure the file exists and was successfully opened The input file will have the following format: First 1ine: Number of students Second Line: Number of assignments Third Line: Student Names, space delimited Fourth+ Line(s): Grades for all students for one assignment, space delimited Example of input file format: 2 Joel Sophie 100 97 78 92 62 70 Requirements: - Your program must read input from a file in the proper format, NOT stdin - Your program should accept the filename from the commandline as shown in the example below Your program should be able to handle a file of any reasonable size. (I will not use excessively long student names, but there may be MANY students and grades.) Do not just make your arrays really large, you need to dynamically allocate them Example: $ ./a.out infile.txt Joel 100 Sophie 97 92 70

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 Design For Mere Mortals

Authors: Michael J Hernandez

4th Edition

978-0136788041

More Books

Students also viewed these Databases questions

Question

Assess various approaches to understanding performance at work

Answered: 1 week ago

Question

Provide a model of performance management

Answered: 1 week ago