Question

In: Computer Science

Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...

Multidimensional Arrays
Design a C program which uses two two-dimensional arrays as follows:
- an array which can store up to 50 student names where a name is up to 25 characters long
- an array which can store marks for 5 courses for up to 50 students
The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that is requested by the user which is greater than 50. The program will compute the average mark for each course and then display all students and their marks, as well as the average mark for each course.
A sample output produced by the program is shown below, if assumed that the user entered marks for 4 students. Please note that the computation of the average mark for each course should use type casting.


Student PRG DGS MTH ECR GED
Ann Smart 93 85 87 83 90
Mike Lazy 65 57 61 58 68
Yo Yo 78 65 69 72 75
Ma Ma 84 79 83 81 83
AVERAGE 80.0 71.5 75.0 73.5 79.0


It is required to submit your source code file, i.e. Lab5.c file as well as a file with your program's run screen captures.

Solutions

Expert Solution

Below is code in C language

#include <stdio.h>

int main()
{
    int count,i,j;
    double avg1=0, avg2=0, avg3=0, avg4=0, avg5=0;
    printf("Enter total number of students: ");
    scanf("%d", &count);
    if(count > 50)
    {
        printf("Sorry you can not enter marks for more than 50 students");
    }
    char students_name[50][25];
    int students_marks[50][5];
    
    //Take students name and 5 subjects marks
    for(i=0; i<count; i++)
    {
        printf("Enter student: %d name: ", i+1);
        getchar();
        scanf("%[^\n]s", students_name[i]);
        printf("Enter 5 subject marks for student %d: ", i+1);
        for(j=0; j<5; j++)
        {
            scanf("%d", &students_marks[i][j]);
        }
    }
    
    //Calculate subject vise average
    for(i=0; i<count; i++)
    {
            avg1 += students_marks[i][0];
            avg2 += students_marks[i][1];
            avg3 += students_marks[i][2];
            avg4 += students_marks[i][3];
            avg5 += students_marks[i][4];
    }
    
    //Type cast average
    avg1 = (double) avg1/count;
    avg2 = (double) avg2/count;
    avg3 = (double) avg3/count;
    avg4 = (double) avg4/count;
    avg5 = (double) avg5/count;
    
    //print students name, marks and subject vise average mark
    printf("Student  PRG DGS MTH ECR GED");
    for(i=0; i<count; i++)
    {
            printf("\n%s %d %d %d %d %d",students_name[i],students_marks[i][0],students_marks[i][1],students_marks[i][2],students_marks[i][3],students_marks[i][4]);
    }
    
    printf("\nAVERAGE %0.1f %0.1f %0.1f %0.1f %0.1f",avg1,avg2,avg3,avg4,avg5);
   
    
    return 0;
}

Output:


Related Solutions

Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array...
Multidimensional Arrays Design a C program which uses two two-dimensional arrays as follows: - an array which can store up to 50 student names where a name is up to 25 characters long - an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an...
Write C program Multidimensional Arrays Design a program which uses two two-dimensional arrays as follows: an array which can store up to 50 student names where a name is up to 25 characters long an array which can store marks for 5 courses for up to 50 students The program should first obtain student names and their corresponding marks for a requested number of students from the user. Please note that the program should reject any number of students that...
In C++ using a single dimensional array Create a program that uses a for loop to...
In C++ using a single dimensional array Create a program that uses a for loop to input the day, the high temperature, and low temperature for each day of the week. The day, high, and low will be placed into three elements of the array. For each loop the day, high, and low will be placed into the next set of elements of the array. After the days and temps for all seven days have been entered into the array,...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test...
C++ ASSIGNMENT: Two-dimensional array Problem Write a program that create a two-dimensional array initialized with test data. The program should have the following functions: getTotal - This function should accept two-dimensional array as its argument and return the total of all the values in the array. getAverage - This function should accept a two-dimensional array as its argument and return the average of values in the array. getRowTotal - This function should accept a two-dimensional array as its first argument...
c++ program to calculate the sum of the rows and the columns in a multidimensional array
c++ program to calculate the sum of the rows and the columns in a multidimensional array
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for...
Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. These methods MUST be your original code.   Your program should output all the values in the array and then output the average high and the...
Write a program that uses a two dimensional array to store the highest and lowest temperatures...
Write a program that uses a two dimensional array to store the highest and lowest temperatures for each month of the calendar year. The temperatures will be entered at the keyboard. This program must output the average high, average low, and highest and lowest temperatures of the year. The results will be printed on the console. The program must include the following methods: A method named inputTempForMonth whose purpose is to input a high and a low temperature for a...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array...
Write a C++ program that declares three one-dimensional arrays named miles, gallons and mpg. Each array should be capable of holding 10 elements. In the miles array, store the numbers 240.5, 300.0 189.6, 310.6, 280.7, 216.9, 199.4, 160.3, 177.4 and 192.3. In the gallons array, store the numbers 10.3, 15,6, 8.7, 14, 16.3, 15.7, 14.9, 10.7 , 8.3 and 8.4. Each element of the mpg array should be calculated as the corresponding element of the miles array divided by the...
This program needs to be in Java Exercise on Single Dimensional Arrays Declare an array reference...
This program needs to be in Java Exercise on Single Dimensional Arrays Declare an array reference variable arrayInt for an array of integers. Create the array of size 100, and assign it to arrayInt. (2 points) Write a method to populate the array with Random numbers between 1 to 25. Signature of the method is: populateArray( int[] ) which returns nothing. Call this method from main with arrayInt--> populateArray(arrayInt). (2 points) Write a method to print an array. Signature of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT