Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Design a program in C, using the method of call by reference, which generates st

ID: 3763954 • Letter: D

Question

Design a program in C, using the method of call by reference, which generates statistics on the grades in a class consisting of M students and N quizzes given during the course of a semester. The quizzes all carry equal weighting, with the grade in each quiz being out of 10 points. The program is to do the following in the indicated sequence when the program is executed:

1.       Ask the user to type on the keyboard the number of number of students M and the number of quizzes N, with M representing the number of rows and N representing the number of columns in a two-dimensional array x[M][N] of floating-point numbers.

2.       Ask the user to type on the keyboard the values of all the elements of the array x[M][N].

3.       Display on the console the M rows and N columns of inputted array element values.

4.       Generate and display on the console the elements of a one-dimensional array p[M] where each element of this array p[M] represents the average grade over the semester of each of the M students.

5.       Generate and display on the console the elements of a one-dimensional array q[N] where each element of q[N] represents the average grade in the class in each of the N quizzes .

6.       Generate and display on the console the averge grade z for the entire class over the entire semester.

  

Explanation / Answer

#include <stdio.h>
#include <ctype.h>
#define NAME_LEN 50
#define STUD_LEN 100

int read_line(char str[], int n);
int find_students(int students);

struct test_result {
char name[NAME_LEN+1];
int number;
int grade1;
int grade2;
int midterm;
int final;
float numeric;
}studen[STUD_LEN];

void insert(void);
void print(void);

int num_students = 0;

int main(void)
{
struct test_result test;
printf("Enter the student's name: ");
read_line(test.name, NAME_LEN);
printf("Enter the student's grade for quiz #1: ");
scanf("%d", &test.grade1);
printf("Enter the student's grade for quiz #2: ");
scanf("%d", &test.grade2);
printf("Enter the student's grade for midterm: ");
scanf("%d", &test.midterm);
printf("Enter the student's grade for final: ");
scanf("%d", &test.final);
test.numeric = (((test.grade1 + test.grade2) * 1.25) + (test.midterm * 0.25) + (test.final * 0.50));
printf("%s's numeric score for the entire course is %.1f ", test.name, test.numeric);

char code;
for (;;) {
printf(" ");
printf("Would you like to enter another student record? y(yes) or n(no)?");
scanf(" %c", &code);
while (getchar() != ' ') /* skips to end of line */
;

switch (code) {
case 'y': insert();
break;
case 'n': print();
return 0;
default: printf("Invalid entry. Try again. ");
return 0;
}
}
}

int find_students(int students)
{
int i;

for (i = 0; i < num_students; i++)
if (studen[i].number == students)
return i;
return -1;
}


void insert(void)
{
int part_number;
if (num_students == STUD_LEN) {
printf("Sorry, cannot enter any more students. ");
return;
}

studen[num_students].number = part_number;
printf("Enter the student name: ");
read_line(studen[num_students].name, NAME_LEN);
printf("Enter the student's grade for quiz #1: ");
scanf("%d", &studen[num_students].grade1);
printf("Enter the student's grade for quiz #2: ");
scanf("%d", &studen[num_students].grade2);
printf("Enter the student's grade for midterm: ");
scanf("%d", &studen[num_students].midterm);
printf("Enter the student's grade for final: ");
scanf("%d", &studen[num_students].final);

studen[num_students].numeric =
(((studen[num_students].grade1 + studen[num_students].grade2) * 1.25) + (studen[num_students].midterm * 0.25) + (studen[num_students].final * 0.50));
printf("%s's numeric score for the entire course is %.1f ", studen[num_students].name, studen[num_students].numeric);
num_students++;
}


void print(void)
{
printf("The average score on quiz1 is ");
printf("The average score on quiz2 is ");
printf("The average score on midterm is ");
printf("The average score on the final is ");
printf("The average score for the entire course is ");

}


int read_line(char str[], int n)
{
int ch, i = 0;

while(isspace(ch = getchar()))
;
str[i++] = ch;
while ((ch = getchar()) != ' ') {
if (i < n)
str[i++] = ch;
}
str[i] = '';
return i;
}

OUTPUT:

The average score on quiz1 is 7.5

The average score on quiz2 is 8.5

The average score on midterm is 83.5

The average score on final is 91

The average score for the entire course is 86.375

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote