0 like 0 dislike
8k views

Write a program with following requirements:

  • Define the structure type student with fields: name, code, and grade.
  • Write a function to sort the structures in grade ascending order and another function to display the data of the students who got a higher grade than the average grade of all students. If there is only 1 student in the list, display the data of that student.
  • Write a program that uses this type to read the data of 100 students and store them in an array of such structures. If the user enters the grade −1, the insertion of student data should terminate. Then print the data of the students who got a higher grade than the average grade of all students. 

 Example input:

Edgar
20161123
78
Robert
20161523
75
Rebecca
20166123
66
Todd
20161673
86
End
1
-1

Example output:

Students who got a higher grade than the average grade of all students:
Name: Edgar
Code: 20161123
Grade: 78
Name: Todd
Code: 20161673
Grade: 86

 

[Exercise] Coding (C) - asked in C
ID: 23560 - Available when: Unlimited - Due to: Unlimited
| 8k views
0 1
Called for Help
0 0
Called for Help
0 0
Called for Help

64 Answers

0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



struct inform

{
** * ** * ***** * * * * * name[100];

    int ID;

    int grade;

};

void bubble(struct inform stu[],int n)

{

    int i,j,swap1,swap2;

    char swapch;
* * * * * * *** * *** * *** * ** * *

    {
*** * * * ********** *** * * ***** ******* *** ***
**** *** * ** * *** * * * *** * * * *
* ***** *** * * * ** * * ** ** ** * **** **** ***
*** ***** *** ******** * * * * ***** * ** ** * **** **** * *** **
** ** * ** ******* *** ***** *** ** **** * * *** *** * * * * * * * *** * ** * ** * ** * **
** **** ** * * ***** * *** * ** *** * *** * ** * * ** * * **
**** ** * * **** ** ***** * * ** ** ** ** * * ***** ** *** ** *** ** *
** *** * * * ******** ** ** *** * *** * * **** ***** * ** *** * *** *** ** * * * ** *
* * ** *** ** * ** * * * **** *** * * **** * *** * * *** * * ** * * ** ******** *** *** * ***** **** ** ***** *
*** ** * * ** ** ******** * *** * * * * * * * ****** *** **** ** *** * * ** * **** * ** * ** ** ** * * * **** *** * * *****
* ***** **** ** *** * * *********** ** * **** * * ***** * ***** *** * *** * * * * * * * ** * *** * ***** * * * * * ** *****
* * * **** * * * *** **** * **** ** * * ***** *** * * *** * *** ****** * ** **** * ** ** * ** **
* * * * * ** *** * * * ** * * * ** * ** ** ** * **** **** * * ** ** * ** * *** * ** ** * ** *** ** ** ***** **
* ** ** ** * ** * ** * * * * * *** * * * * * * ******* ** * * * * ** * * **** * ** * * *** * *** ** *
**** * ** ** * * * * * * *** ** ** *** **** * ** * *** **** * * *** ****** *** * *** *** * * * ** ** * * * *
* ** * * * ** * **** * * *** * ** ** * * ** ** * * ** * ** ** * *** ** * *** ** * **** * * * ** *
* ** *** **** ** * ** ** ** * * * **** ** *** *** * * ** ***** * * * * * * **** *** * * *** **** * ** ** * **
** **** * * *** * * * *** *** *** * ** * * ******* ** * * *** * * * * * * **** ** * ** ** * ** * * * **** *
**** * ** ********* ** * ** * ** * * * * ***** *** ** **** * * ** ** ** **** * * * * ** ** * * * * * *** * ** ** *
** * * ** * * * * ** ******* * * * **** * * * ** *** ***** * * ***** *** * * **
** ** * ** ****** *** ** * ** * * **

    }
* ** ** * * ** ** ** **** ****** * *

    {
*** * ** * * ** **** ** * ** * ** * * * *** who got a higher grade than the average grade of all students:\n");
* ******** ** * * ** *** * * *** * ** ** * * ****** **** ** * %s\n",stu.name);
** * * * * * * * * ** ****** ** ** ** ** * ** * *** * %d\n",stu.ID);
* *** * * * * ******** ** * *** *** * ****** ** * %d",stu.grade);
* *** ** * ** * * * * * * ** * ** *** *** *

    }

    

}

struct select(struct infrom stu[],n)

{   
* * ** * * * * * ** ** * infrom select[];

    
****** ** * * ** * * sum=0;

    int i;
** * * ** ** *** * **** ******** ** **

    {
* * * * * * *** * * ** * * * ** **** * ** *** * *

    }
** * ** ******* * * average=sum/n;

    int j=0
***** * * *** * * * * * ***

    {
***** * ** ******* ** ** * ** ** *** *** **
***** * * ** *** ** **** * ** * * * * * ***
* * ** * *** ****** *** ***** ** * ** * * *** *** * * *** ** ** * *
** * **** ** **** ** ** ** * ** * *** * ** * ** ** * * * ***** **
* * ** * * * * ** * * * ****** * ** * ** **** *** ** ** ** * * *
* * * * ** * * **** *** * * * ** *** *** * * * ****
** *** * * ** * ****** ** ** ** ** ** * **

    }
* * * * * ** * * * * select;

    

}

int main(void)

 {
* ** * *** * ** ** inform stu[100];

    int n=0;
* * ** * * ** * **** *******

    {
**** * * * ** * ** ** *** * ** * ** ****** ****** ** ",stu.name);
** * ** *** *** * ** ** ** * **** *** ****** ",&stu.ID);
* * * ** ** ** ** * * ** ** ******** ** * * * *** * **** ",&stu.grade);
* *** * * * **** ** ** * * * * * ** *

    }
**** * ** * ** ** ** * * * * ** *

 }
answered by (-412 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>

#include <string.h>

typedef struct

{
** * ** * * * ** *** * **** name[20];
* *** * * ***** * ** ** code;
* * * ** *** * ***** grade;

}data;

int main(void)

{
*** * * *** ***** * * ** *********** NULL, _IONBF, 0);
* ** ** * ****** * * * * * NULL, _IONBF, 0);
** ** * ** *** **** * *** sol[100];
**** * * * ** heigher;
* ** * * ** * ** ** * ** i=0;

    int max=0,sum=0;


** ** * *** * *** ** * ***

    {
* * * *** * ** * * ***** * ** * *** * * * * ** ** * *** * ** *
* ** ** * ** *** * * *** * * * * * * ** ** ** * *** * * * * ***
*** * * * *** * * *** * * ** ** *** * * * * *** * *** * * ****** ****
* * ** *** ** * * * * * ** * * * ** ** * * ******* * *
** ****** * * * **** * *** * * ** *** ** * * *****
** * * ** **** *** * * **** *** ** *** * * * ** * **** ** *
** * * * * * *** * ***** * * * ***** ** *
* * * **** * *** * * *** * ** ****** if(sol[i].grade>max)
****** ** **** * ** * **** *** * * *** *
** ****** * * * * ***** * * * ** ** * * * * ** * *** * * ** ** *** * * ***** * * * * **
* * * ** ****** * * ****** ** * * * * *
* * ** * *** * * * * ** * ** * * *** ** *
* * *** *** * * * ** ** * **** **** ** * ** * ** * **

    }
* ********* *** * * *** ** ** * * who got a higher grade than the average grade of all students:\n");
** ******* ** ******* * * * * * * * *** * * **
**** ** * * * * **** * * *** * ** ******** **
**** ********* * * * ** ***** ** * *** ** * * * * * * * *** ** **
* ** *** ** **** *** * ***** ****** *
*** * **** * * * * * * * *** EXIT_SUCCESS;

}
answered by (0 points)
0 like 0 dislike
Hidden content!
#include <stdio.h>

#include <stdlib.h>



struct studlist{
* * * * * * * **** name[50];
* * *** * * ** **** * code[50];
** * ** *** * ** ** * grade;

};



void sort(int i, struct studlist List[])

{
* * **** ***** ** ** ** j, k;
* * ** * * * ** * ** j<i; j++)
** * * ** *** **** ** * *
** * * ***** ** **** ** *** * * ** * * ** k<i-j; k++)
****** * ****** ** ** **** * *** * * *** *
* ** ** * * * * **** * * * * ** * ** ** *** ** ****** *** ** ** ***** *** ** > List[k+1].grade)
** * * *** ** ** * ** * ****** *** *** * * ** * * *** **** **** *
* ** * ** *** **** * * * ** * **** * ** * * * *** ** *** *** ** ** ** *** ** * **** studlist temp = List[k+1];
** ** * * ***** * * * ** * * * * *** * ** * ** *** ** ** * * ** ** * ** * ** ** ** *** ** *** = List[k];
**** * * **** ** * ** * **** * ** ** * *** ** **** * ** ****** ** * * ** = temp;
** * * * * **** *** * *** *** * *** * *** * * * * ** ** **** * * **
*** * **** ******* * ***** ** * ** * ** *
** ** * * * ** ** ** * *

}



void printList(int i, struct studlist List[])

{
*** *** *** ** * *** * j, sum=0;
** **** * * * ** *** ** j<=i; j++)
*** * * * * ** *
** *** * * ** * * * *** ** * ****** * ** ** *** * += List[j].grade;
* * *** * * ** ** * *
** * ** ** *** * avg = sum/i;
* ** *** ** ** * * * ** * who got a higher grade than the average grade of all students:\n");
********* * * * ** ***** j<=i; j++)
* *** ** * * ***** **
* * * ***** **** ** ** **** *** * ** *** * * *** **** > avg)
* ** ** ** ** * *** *** * *** * ** *
* * * ** *** * **** * ** * *** * * ** * ** * * * * * %s\n", List[j].name);
*** * * ***** * **** * ** ***** ** **** ** *** *** *** * * * * ** * * *** %s\n", List[j].code);
* *** * **** *** * * * ** ** ******** * ** ** * * * * ** ** **** *** ** %d\n", List[j].grade);
**** * ** * * ** * * ** ****** * * * ****
* ******** ** * *** * *

}



int main()

{
****** **** * *** *** * i;
*** *** * ** *** ** studlist List[100];


** * ** * **** *** * ***** * i<100; i++)
** * ** ***** **
** * *** * *** ***** * * ** ***** * ** *** * * *** * List[i].name);
** * ****** * *** * * ** ** *** **** * *** ** ** ** ** * List[i].code);
*** * ** ** * ** * *** *** * ** * ** * **** * ** * ** &List[i].grade);
** * *** ** ** * * ** * ** * * * * * ** ** == -1)
* * **** * * ** ** *** * *** ******** *** **** * * ** ********** * *

    }


** ** ******* * *** * ** * List);
** * * ** ** * * *** List);


* * * * ** 0;

}
answered by (5.2k points)
0 like 0 dislike
Hidden content!
#include<stdio.h>

#include<string.h>



typedef struct Student

{
* * ** ** **** *** *** * *** name[1000];
** ***** * * *** ** ** ** code;
** ** **** ** * * * * grade;

} Student_t;



void compare(Student_t *student, int count);

void display(Student_t *student, int count);



int main ()

{
** * * ** ** ** ** ** **** student[100];
* * * *** * * ** count=0;
* ** * * ** **** * ** *** * ** * ** *** *** *
* ** * * * ** * **** * * * * * * * * *** ** * * **
* ******** ** ** * ** ** * * ** * * * ** * * *
* ** * * *** * ****** ** **

    {
* * * ** * ** ** ** ***** ** ** *** * ** * ** * ***
** * *** * *** * * ** ** ***** * ***** ******* * ** * ** ***** ** *
* * * * * ***** ** * ** * * * * * *** ** ** * **** **** * * * * * * *
* * * * * *** ** ***** * **** ****** * ****** * ** * ****** * ** **

    }
* ** ***** ** ** ** * * * * * *** * ** * * count);
* ** * * * ** * ** ** *** * **** *** ** count);
**** ** * *** * * * ***** 0;

}

void compare(Student_t *student, int count)

{
* * **** ** ** * i, j;
**** * * * ** * * * ** t;
* * * * *** ***** **** * * i<count; i++)

    {
* ** ** ** * * * ** * ** *** * *** * * ** * ** j<count; j++)
* * * ** ** ** * * ** *** * * **** * ****
*** ******* *** * *** * * ** * ** ** * * * * ** *** * ** ** * * ** * * **** * * ** * ** *** *
* ** * ** *** *** * * ** ** *** *** ****** * * * ** ** ** * * * * ***
** ** ** **** ** ** * * * * ***** ** * ** * ** * ** **** * * ** * * *** * * * ******* ** *** * **
** ** *** * * ** * * * * * ** * ** ** * ****** *** ** * * * * * * *** **** ** *** **** * * *
* ****** * ** * * * * * ****** ***** * ***** * * * * ***** *** * * **** ** * * ** * * *
** ** * **** * ******** * * * * * *** * * *** * ** *** ** * *
** *** * * *** *** * * *** * * * ** *** ** * *

    }

}



void display(Student_t *student, int count)

{
* *** ** * *** * * * * ** i, avg=0;
* ** * * **** ** * * ** * ** i<count; i++)

    {
* * *** * * * * ** * *** ** * * ** ***** ** ** ** * ***
* *** *** * * * *
* * * * ** ** * * **
** ** ** * * ** * ***** * who got a higher grade than the average grade of all students:\n");
* * ** ** * * * * ** i<count; i++)
* ** ** * *****
* * * ** ******* ** ** * * ***** * * * ** * * * * ** *
* ** ** *** * * ** * *** * ** * *** ** ** ** **
** **** ** *** ** ** * ** * * * **** * ***** ** * * * * *** * * ** ***** ** %s\n",student[i].name);
** * * * *** ** * ***** *** ** ** **** *** *** * * * ** *** * * *** * *** ****** ***** %d\n",student[i].code);
* ** ** ** * * ** * ** *** * ** * * *** * ** * *** * ** * * * ** *** * %d\n",student[i].grade);
* **** * *** ****** * * **** **** * ** * *** ***
* ** * * ** * *

}
answered by (-367 points)
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.68.159.47
©2016-2025

Related questions

0 like 0 dislike
32 answers
[Exercise] Coding (C) - asked Apr 6, 2017 in C
ID: 23557 - Available when: Unlimited - Due to: Unlimited
| 4.6k views
0 like 0 dislike
18 answers
[Exercise] Essay (Open question) - asked Apr 20, 2017 in C
ID: 24219 - Available when: Unlimited - Due to: Unlimited
| 3.4k views
12,783 questions
183,442 answers
172,219 comments
4,824 users