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

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.
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...
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...
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Write a program the declares and uses two parallel arrays. One array for storing the names...
Write a program the declares and uses two parallel arrays. One array for storing the names of countries and a second array for storing the populations of those countries. As you can see per the following the Country name and it's corresponding Population are stored at the same element index in each array. China 1367960000 India 1262670000 United States 319111000 Indonesia 252164800 Brazil 203462000 Pakistan 188172000 Nigeria 178517000 Bangladesh 157339000 Russia 146149200 Japan 127090000 In the main method write a...
Write a program that uses two identical arrays of at least 25 integers. It should call...
Write a program that uses two identical arrays of at least 25 integers. It should call a function that uses the bubble sort algorithm to sort one of the arrays in descending order. The function should keep a count of the number of exchanges it makes. The program then should call a function that uses the selection sort algorithm to sort the other array. It should also keep count of the number of exchanges it makes. Display these values on...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number...
[C++ Coding question] write a program which inputs data to a two-dimensional array: - Input number of rows r aand number of columns c - Create a two-dimensional array of integers int numbers[r][c] -input data for each element of numbers Your program must compute and display the largest number is each row and column of the number array
C++ DO not use arrays to write this program. Write a program that repeatedly generates three...
C++ DO not use arrays to write this program. Write a program that repeatedly generates three random integers in the range [1, 100] and continues as follows: If the right-most digit of all the three integers is equal, the program displays them in ascending order on the screen and continues. If the generated integers have different right-most digits, they are not displayed and the program continues. The program terminates once the right-most digits of all the three random numbers are...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT