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

You are given a student data file which consists of the student\'s name, student

ID: 3782057 • Letter: Y

Question

You are given a student data file which consists of the student's name, student ID, and GPA. Data set is provided below:

            Name             ID                    GPA

          Alice              8234               2.7

            Mark               2672               3.0

            Joanne        1234               3.7

            John               3291               2.0

          Tim                 3212               3.8

            Alford             1034               2.7

            Benson        6290               2.5

            Nancy            4234               3.7

            Oscar              1672               1.0

            Larry               1004               2.7

Write a program to process this student data. First, input these records into a record structure. Then, sort them in ascending order using Student ID as a key. Display the sorted output.

You are limited to use ONLY the concepts of one dimension array and record (struct).

Explanation / Answer

#include<conio.h>
#include<stdio.h>
struct student
{
char name[50];
int id;
float gpa;
};

void main()
{
clrscr();
int i,d,temp;
float gpa1;
struct student records[10];
for(i=0;i<10;i++)
{
printf("Enter Name ");
scanf("%s",&records[i].name);
printf("Enter ID ");
scanf("%d",&records[i].id);
printf("Enter gpa ");
scanf("%f",&gpa1);
records[i].gpa=gpa1;
}
for (int i = 1 ; i <=9; i++)
{
d = i;
while ( d > 0 && records[i].id < records[i-1].id)
{
temp = records[i].id;
records[i].id = records[i-1].id;
records[i-1].id = temp;
records[i-1].name=records[i].name;
records[i-1].gpa=records[i].gpa
d--;
}
}
printf("NAME ID GPA");
printf(" Your data ");
for(i=0;i<10;i++)
{
printf("%s %d %d ",records[i].name,records[i].id,records[i].gpa);
}
getch();
}

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