#include<stdio.h>
#define size 21
#define max 10
typedef struct id
{
int idnum,q1,q2,q3;
char fn[size];
char ln[size];
char mi[2];
float ave;
}id;
id l[max];
id a;
int menu()
{
int i,s=0;
while(s<1 || s>4)
{
clrscr();
gotoxy(5,5);
printf("MENU");
gotoxy(5,7);
printf("1. insert");
gotoxy(5,9);
printf("2. delete");
gotoxy(5,11);
printf("3. display");
gotoxy(5,13);
printf("4. exit");
gotoxy(5,15);
printf("select 1-4: ");scanf("%d",&s);
}
return (s);
}
void initialize()
{
int i;
for(i=0;i<max;i++);
l[i].idnum=-1;
}
int end()
{
int i=0;
while(l[i].idnum!=-1)
i++;
return(i);
}
void insert(id a)
{
int i,p;
i=p=0;
while(a.idnum>l[i].idnum && l[i].idnum!=-1)
i++;
if (l[i].idnum==-1)
{
l[p].idnum=a.idnum;
strcpy(l[p].fn,a.fn);
strcpy(l[p].ln,a.ln);
strcpy(l[p].mi,a.mi);
l[p].q1=a.q1;
l[p].q2=a.q2;
l[p].q3=a.q3;
l[p].ave=(float)(a.q1+a.q2+a.q3)/3.0;
}
else{
for(i=end();i>p;i--);
{
l[i].idnum=l[i-1].idnum;
strcpy(l[i].fn,l[i-1].fn);
strcpy(l[i].ln,l[i-1].ln);
strcpy(l[i].mi,l[i-1].mi);
l[i].q1=l[i-1].q1;
l[i].q2=l[i-1].q2;
l[i].q3=l[i-1].q3;
l[i].ave=l[i-1].ave;
}
l[p].idnum=a.idnum;
strcpy(l[p].fn,a.fn);
strcpy(l[p].ln,a.ln);
strcpy(l[p].mi,a.mi);
l[p].q1=a.q1;
l[p].q2=a.q2;
l[p].q3=a.q3;
l[p].ave=(float)(a.q1+a.q2+a.q3)/3.0;
}
getch();
}
void delete(id a)
{
int i,p;
i=p=0;
clrscr();
while(a.idnum!=l[i].idnum && l[i].idnum!=-1)
i++;
p=i;
if(l[i].idnum==-1)
{
printf("record not found");
getch();
}
else
for(i=p;i<end();i++)
{
l[i].idnum=l[i+1].idnum;
strcpy(l[i].fn,l[i+1].fn);
strcpy(l[i].ln,l[i+1].ln);
strcpy(l[i].mi,l[i+1].mi);
l[i].q1=l[i+1].q1;
l[i].q2=l[i+1].q2;
l[i].q3=l[i+1].q3;
l[i].ave=l[i+1].ave;
}
}
void displayall()
{
int i;
printf("idnum 1stnme lastnme midtial q1 q2 q3 average");
for(i=0;i<end();i++)
{
gotoxy(1,i+3);
printf("%d",l[i].idnum);
gotoxy(10,i+3);
printf("%s",l[i].fn);
gotoxy(20,i+3);
printf("%s",l[i].ln);
gotoxy(32,i+3);
printf("%s",l[i].mi);
gotoxy(46,i+3);
printf("%d",l[i].q1);
gotoxy(55,i+3);
printf("%d",l[i].q2);
gotoxy(63,i+3);
printf("%d",l[i].q3);
gotoxy(68,i+3);
printf("%.2f",l[i].ave);
}
getch();
}
main()
{
int i;
id b;
initialize();
while(1)
{
i=menu();
if(i==1)
{ clrscr();
printf("\n input id number: "); scanf("%d",&b.idnum);
printf("input firstname: "); scanf("%s",b.fn);
printf("input lastname: "); scanf("%s",b.ln);
printf("input mid initial: "); scanf("%s",b.mi);
printf("input quiz1:");scanf("%d",&b.q1);
printf("input quiz2:");scanf("%d",&b.q2);
printf("input quiz3:");scanf("%d",&b.q3);
insert(b);}
else
if(i==2) {
clrscr();printf("input id number:");scanf("%d",&b.idnum);
delete(b); }
else
if(i==3){
clrscr();displayall();}
else
exit(0);
getch();
}
}
comp_sci11 0 Light Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.