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

A professor has posted a list of student numbers and marks. Write a program to r

ID: 668378 • Letter: A

Question

A professor has posted a list of student numbers and marks. Write a program to read the marks and compute the rank of a student in class; the rank is computed using the usual manner as follows: if the student has the top mark (or is tied for the top mark) his rank is 1; if he has the second best mark (or is tied) his rank is 2, and so on.

Input (from a file called rank.in)

The input consists of several test cases. Each case begins with Ahmed's student number, an integer between 1000000 and 9999999. Following the student number are a number of lines, each containing a student number between 1000000 and 9999999 and a mark between 0 and 100. A line with a student number and mark of 0 terminates each test case. There are no more than 1000 students in the class, and each has a unique student number.

Output (to a file called rank.out)

For each test case, output a line giving Ahmed's rank in the class.

Sample Input

1234567 1212121 100 1234567 33 2222222 22 9898765 33 00

1234567 1212121 100 1234567 22 2222222 33 9898765 33 00

Output for Sample Input

2 4

Explanation / Answer

#define STUDENTS 5                                            
#define SUBJECTS 4                                            
#include <string.h>                                             
main()                                                          
{                                                               
char name[STUDENTS][20];                                    
int marks[STUDENTS][SUBJECTS+1];                   
printf("Input students names & their marks in four subjects ");
get_list(name, marks, STUDENTS, SUBJECTS);                  
get_sum(marks, STUDENTS, SUBJECTS+1);                       
printf(" ");                                               
print_list(name,marks,STUDENTS,SUBJECTS+1);                 
get_rank_list(name, marks, STUDENTS, SUBJECTS+1);           
printf(" Ranked List ");                                
print_list(name,marks,STUDENTS,SUBJECTS+1);
}                                                               
/*Input student name and marks*/
get_list(char *string[ ],                                  
int array [ ] [SUBJECTS +1], int m, int n)                                      
{
int   i, j, (*rowptr)[SUBJECTS+1] = array;                  
for(i = 0; i < m; i++)                                      
{                                                           
scanf("%s", string[i]);                                  
for(j = 0; j < SUBJECTS; j++)                            
scanf("%d", &(*(rowptr + i))[j]);                     
}                                                           
}
/*Compute total marks obtained by each student*/
get_sum(int array [ ] [SUBJECTS +1], int m, int n)            
{                                                               
int   i, j, (*rowptr)[SUBJECTS+1] = array;                  
for(i = 0; i < m; i++)                                      
{
(*(rowptr + i))[n-1] = 0;                                
for(j =0; j < n-1; j++)                                  
(*(rowptr + i))[n-1] += (*(rowptr + i))[j];           
}                                                           
}                                                               
/*Prepare rank list based on total marks*/
get_rank_list(char *string [ ],                                 
int array [ ] [SUBJECTS + 1]                     
int m, int n                                   
{                                                               
int i, j, k, (*rowptr)[SUBJECTS+1] = array;                 
char *temp;                                                 
for(i = 1; i <= m-1; i++)                                   
for(j = 1; j <= m-i; j++)                                
if( (*(rowptr + j-1))[n-1] < (*(rowptr + j))[n-1])   
{                                                    
swap_string(string[j-1], string[j]);                
for(k = 0; k < n; k++)                              
swap_int(&(*(rowptr + j-1))[k],&(*(rowptr+j))[k]);
}                                                     
}                                                               
/*Print out the ranked list*/
print_list(char *string[ ],                                 
int array [] [SUBJECTS + 1],                      
int m, int n                                      
{                                                               
int i, j, (*rowptr)[SUBJECTS+1] = array;                   
for(i = 0; i < m; i++)                                      
{                                                           
printf("%-20s", string[i]);                              
for(j = 0; j < n; j++)                                   
printf("%5d", (*(rowptr + i))[j]);                    
printf(" ");                                         
}                                                           
}                                                               
/*Exchange of integer values*/
swap_int(int *p, int *q)                                
{                                                               
int temp;                                                  
temp = *p;                                                  
*p   = *q;                                                  
*q   = temp;                                                
}   
/*Exchange of strings*/
swap_string(char s1[ ], char s2[ ])                    
{                                                               
char swaparea[256];                                        
int   i;                                                    
for(i = 0; i < 256; i++)                                    
swaparea[i] = '';                                      
i = 0;                                                      
while(s1[i] != '' && i < 256)                             
{                                                           
swaparea[i] = s1[i];                                     
i++;                                                     
}                                                           
i = 0;                                                      
while(s2[i] != '' && i < 256)                             
{                                                           
s1[i] = s2[i];                                           
s1[++i] = '';                                          
}                                                           
i = 0;                                                      
while(swaparea[i] != '')                                  
{                                                           
s2[i] = swaparea[i];                                     
s2[++i] = '';                                          
}                                                           
}                      

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