#include<conio.h>
#include<alloc.h>
#include<stdio.h>
struct data{
char name[45];
int roll,m1,m2,m3,t;
float avg;
};
struct stu{
struct data d;
struct stu *next;
}*head=NULL,*temp,*node;
void in(char *,int,int,int,int), dis(void);
void main()
{
char *n;
int r,x,y,z;
printf("\nMain
Menu\n1.Insert details\n2.Display\n3.Exit\nEnter choice:");
scanf("%d",&r);
switch(r)
{
case 1:
getc(stdin);
printf("Enter
name of the student:");
gets(n);
printf("Enter
roll number:");
scanf("%d",&r);
printf("Enter
marks of three subjects:");
scanf("%d%d%d",&x,&y,&z);
in(n,r,x,y,z);
break;
case 2:
clrscr();
if(head==NULL)
printf("EMPTY
RECORDS!!");
else
{
puts("\nThe
records are:\n");
printf("\tName\t\tRoll\tMarks\tMarks\tMarks\tTotal\tAverage\n");
dis();
}
break;
case 3:
clrscr();
exit();
default:
clrscr();
printf("WRONG
INPUT!!");
}
main();
}
void in(char *n,int r, int x,int y, int z)
{
if(head==NULL)
{
head=(struct
stu*)malloc(sizeof(struct stu));
strcpy(head->d.name,n);
head->d.roll=r;
head->d.m1=x;
head->d.m2=y;
head->d.m3=z;
head->d.t=x+y+z;
head->d.avg=head->d.t/3;
head->next=NULL;
}
else
{
temp=head;
while(temp->next!=NULL)
temp=temp->next;
node=(struct
stu*)malloc(sizeof(struct stu));
strcpy(node->d.name,n);
node->d.roll=r;
node->d.m1=x;
node->d.m2=y;
node->d.m3=z;
node->d.t=x+y+z;
node->d.avg=node->d.t/3;
temp->next=node;
}
}
void dis(void)
{
int max=head->d.t;
temp=head;
while(temp!=NULL)
{
printf("%s\t%d\t%d\t%d\t%d\t%d\t%.2f\n",temp->d.name,
temp->d.roll,temp->d.m1,temp->d.m2,temp->d.m3,temp->d.t,temp->d.avg);
if(temp->d.t>max)
max=temp->d.t;
temp=temp->next;
}
printf("The
student to obtain highest marks is:\nName: %s\nRoll: %d\nMarks: %d, %d and
%d\nTotal: %d\nAverage:
%.2f",temp->d.name,temp->d.roll,temp->d.m1,temp->d.m2,temp->d.m3,temp->d.t,temp->d.avg);
}
No comments:
Post a Comment