Question

In: Computer Science

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 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

Code:

#include <stdio.h>
int main()
{
    int number_of_students;
    // taking input from user
    printf("Enter the number of students\n");
    scanf("%d",&number_of_students);
    // creating a two dimensional array for 50 students where a name is up to 25 characters long
    char names[50][25];
    // creating a two dimensional array which can store marks for 5 courses for up to 50 students
    int marks[50][5];
    int i, j;
    // taking input from user
    for(i=0; i<number_of_students; i++) {
        printf("Enter the name of student %d\n",i+1);
        scanf(" %[^\n]",names[i]);
        printf("Enter the marks of the student %s\n",names[i]);
        for(j=0;j<5;j++){
            scanf("%d",&marks[i][j]);
        }
    }
    // printing the output
    printf("%-25s%-7s%-7s%-7s%-7s%-7s\n","Student","PRG","DGS","MTH","ECR","GED");
    for(i=0; i<number_of_students; i++) {
        printf("%-25s",names[i]);
        for(j=0;j<5;j++){
            printf("%-7d",marks[i][j]);
        }
        printf("\n")  ;
    }
   printf("%-25s","AVERAGE");
   j=0;
   // calculating the average of the marks for each course
   while(j<5){
       int sum =0;
       double avg=0;
       for(int i=0;i<number_of_students;i++){
           sum=sum+marks[i][j];
       }
       // type casting the average
       avg=(double)sum/number_of_students;
       printf("%.1f%-3s",avg," ");
       j++;
   }
   return 0;
}

Screenshot of the code:

Screenshot of the 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...
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...
In C++, write a program that uses two identical arrays of ten randomly ordered integers. It...
In C++, write a program that uses two identical arrays of ten randomly ordered integers. It should display the contents of the first array, then call a function to sort it using the most efficient descending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using descending order selection sort, modified to print out the...
Write a program which shows how two-dimensional arrays which contain multiple copies of your id number...
Write a program which shows how two-dimensional arrays which contain multiple copies of your id number and age are passed to methods. Explain in your own words each method and class used in the program. My id number is 12133149
Write a program which shows how two-dimensional arrays which contain multiple copies of your id number...
Write a program which shows how two-dimensional arrays which contain multiple copies of your id number and age are passed to methods. Explain in your own words each method and class used in the program.
This is for c++ Write a program that works with two arrays of the same size...
This is for c++ Write a program that works with two arrays of the same size that are related to each other in some way (or parallel arrays). Your two arrays must be of different data types. For example, one array can hold values that are used in a formula that produces the contents of the second array. Some examples might be:  from a previous program, populations and the associated flowrates for those populations (an int array of populations...
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers....
using c++ 10. Sorting Orders Write a program that uses two identical arrays of eight integers. It should display the contents of the first array, then call a function to sort it using an ascending order bubble sort, modified to print out the array contents after each pass of the sort. Next the program should display the contents of the second array, then call a function to sort it using an ascending order selection sort, modified to print out the...
Program must be in C++! Write a program which: Write a program which uses the following...
Program must be in C++! Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to...
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...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT