

#include
#include
#include
#include
int i=-1;
void add(),assort(),dessort(),view();
struct rec {
int id;
char Lastname [30];
char Firstname [30];
char position[30];
int age;
} ;
struct rec record[100];
main()
{
char choice;
clrscr();
printf("A] Add Employee Record\n");
printf("B] View Records\n");
printf("C] Exit\n");
printf("Choice: ");
scanf("%s",&choice);
choice=toupper(choice);
//choice=tolower(choice);
switch(choice)
{
case 'A':
i++;
add();
main();
case 'B':
view();
main();
case 'C':
printf("Thank You for Using");
getch();
exit(0);
default:
printf("Only letter a,b,and c");
getch();
main();
}
}
void add()
{
clrscr();
printf("Enter Account #: ");
scanf("%d",&record[i].id);
printf("Your Last name: ");
scanf("%d",&record[i].Lastname);gets(record[i].Lastname);
printf("Enter First name: ");
scanf("%d",&record[i].Firstname);gets(record[i].Firstname);
printf("Enter Position: ");
scanf("%d",&record[i].position);gets(record[i].position);
printf("Enter your Age: ");
scanf("%d",&record[i].age);
}
// --------------------------------Ascending Sort------------------------------
void assort()
{
struct rec T;
for(int x=i-1;x>=0;x--)
{
for(int y=0;y<=x;y++) { if(record[y].id>record[y+1].id)
{
T=record[y];
record[y]=record[y+1];
record[y+1]=T;
}
}
}
}
//--------------------------------Descending Sort---------------
void dessort()
{
struct rec T;
for(int x=i-1;x>=0;x--)
{
for(int y=0;y<=x;y++) { if(record[y].id
{
T=record[y];
record[y]=record[y+1];
record[y+1]=T;
}
}
}
}
//---------------------------------View-----------------------
void view()
{
int tt;
char h;
clrscr();
printf("Account #: Name: Position: Age:\n");
for( tt=0;tt<=i;tt++) { printf("%d %7s, %s %8s %9d\n",record[tt].id,record[tt].Lastname,record[tt].Firstname,record[tt].position,record[tt].age); } gotoxy(10,20);printf("press [A] - Ascending Sort"); gotoxy(10,21);printf("press [B] - Descending Sort"); gotoxy(10,22);printf("press [C] - Main Menu"); gotoxy(10,23);printf("choice: "); scanf("%s",&h); h=toupper(h); clrscr(); printf("Account #: Name: Position: Age:\n"); switch(h) { case 'A': assort(); for(tt=0;tt<=i;tt++) { printf("%d %7s, %s %8s %9d\n",record[tt].id,record[tt].Lastname,record[tt].Firstname,record[tt].position,record[tt].age); } break; case 'B': dessort(); for(tt=0;tt<=i;tt++) { printf("%d %7s, %s %8s %9d\n",record[tt].id,record[tt].Lastname,record[tt].Firstname,record[tt].position,record[tt].age); } break; case 'C': main(); break; default: clrscr(); printf("Only a and b"); getch(); break; } getch(); main(); }
No comments:
Post a Comment