Write in C language Description You have 2 tables, courses and scores. courses consists 3 columns, sid, student_id, and course_id. scores consists 2 columns,sid and score. Please find that how many students failed on at least one course. Input First line consists 2 integers m and n, shows number of rows in courses and scores. Followed m lines are records of courses. student_id are 8-digits numbers begin with non-zero digit. sid and scores are positive integers smaller than 1000. Followed n lines are records of scores. sid are positive integers smaller than 1000. score are integers in range [0, 100]. Output

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write in C language

Description

You have 2 tables, courses and scorescourses consists 3 columns, sidstudent_id, and course_idscores consists 2 columns,sid and score. Please find that how many students failed on at least one course.

Input

First line consists 2 integers m and n, shows number of rows in courses and scores.

Followed m lines are records of coursesstudent_id are 8-digits numbers begin with non-zero digit. sid and scores are positive integers smaller than 1000.

Followed n lines are records of scoressid are positive integers smaller than 1000. score are integers in range [0, 100].

Output

Student will be flunked when his/her average score in the course less than 60. Output is 2 integers shows number of student and student failed on at lease one course.

Sample Input 1 

2 4
1 10800001 5
2 10800002 5
1 90
1 29
2 65
2 60

Sample Output 1

2 1

Expert Answer (Sample Input and Output need to be the same as the input and output nothing else)

 
Step 1

There are 2 tables, courses and scores. The courses consists of 3 columns, sidstudent_id, and course_id whereas scores consists 2 columns, sid and score.

The ask is to find out the total number of students and the number of students who have failed in atleast one course.

Step 2

The scores table contains multiple scores of a student for a course. So, we would need to find out the average score obtained in a given course for a student.

So, we would need to start with defining 2-D arrays to store the courses and scores details.

#include<stdio.h>
int main(){
   /* 2D array declaration*/
   int m=0;
   int n=0;
   printf("Enter value for m:");
   scanf("%d",&m);
   printf("Enter value for m:");
   scanf("%d",&n);
   int course[m][3];
   /*Counter variables for the loop*/
   int i, j;
   for(i=0; i<m; i++) {
      for(j=0;j<3;j++) {
         printf("Enter value for course[%d][%d]:", i, j);
         scanf("%d", &course[i][j]);
      }
   }
    int score[n][2];
   /*Counter variables for the loop*/
   
   for(i=0; i<n; i++) {
      for(j=0;j<3;j++) {
         printf("Enter value for score[%d][%d]:", i, j);
         scanf("%d", &score[i][j]);
      }
   }

 int prevSid=0, prevScore=0, noOfOccurence=0, noOfFailedStudents=0;
 for(i=0;i<n; i++) {
  
  sid = score[i][0];
  if(prevSid==sid) {
   totalScore=prevScore+score[i][1];
   prevSid=sid; noOfOccurence++;
  } else {
   if(totalScore/noOfOccurence<60) {
    noOfFailedStudents++;
   }
   prevSid=0; prevScore=0;
  }
 }

 printf("Output: ");
 printf("%d", m);
  printf("%d", noOfFailedStudents);
   return 0;
}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Computing Algorithms
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education