//ASSIGNMENT NO- 4
//EMPLOYEE DATABASE
#include<stdio.h>
#include<conio.h>
//STRUCTURE DEFINATION
struct emp1
{
int id;
int dflag;
char name[10];
float salary;
};
int main()
{
//INITIALISATION
struct emp1 e[20]={0,0,"\0",0.0};
int accept(struct emp1 [],int);
int display(struct emp1 [],int);
int append(struct emp1 [],int);
int delete1(struct emp1 [],int,int);
int modify(struct emp1 [],int,int);
int no=0,v=0,u=0,ch=0,count=0;
char ans='\0';
clrscr();
do
{
printf("\n\t\tMENU");
printf("\n\t1:ACCEPT");
printf("\n\t2:DISPLAY");
printf("\n\t3:APPEND");
printf("\n\t4:DELETE");
printf("\n\t5:MODIFY");
printf("\n\nEnter the choice:");
scanf("%d",&ch);
if(ch>2&&count==0)
{
printf("NULL INPUT");
}
else
{
switch(ch)
{
case 1:
printf("\nEnter the of entries u want:");
scanf("%d",&no);
if(no==0)
{
printf("\nNULL SET");
}
else
{
printf("\n");
no=accept(e,no);
printf("\nNo. of enteries entered=%d",no);
count=count++;
}
break;
case 2:
no=display(e,no);
printf("\nNo. of enteries displayed=%d\n",no);
break;
case 3:
printf("append a record:");
no=append(e,no);
no=display(e,no);
printf("\nNo. of enteries displayed=%d\n",no);
break;
case 4:
printf("Enter the id u want to delete");
scanf("%d",&u);
no=delete1(e,no,u);
no=display(e,no);
printf("\nNo. of enteries displayed=%d\n",no);
break;
case 5:
printf("Enter the id u want to modify");
scanf("%d",&v);
no=modify(e,no,v);
no=display(e,no);
printf("\nNo. of enteries displayed=%d\n",no);
break;
default:
printf("\nInvalid entry");
}}
printf("\n\nDo u want to contnuie(y/n):");
flushall();
scanf("%c",&ans);
}while(ans=='y'||ans=='Y');
getch();
return(0);
}
int accept(struct emp1 a[20],int n)
{
float sal=0.0;
int i=0;
for(i=0;i<n;i++)
{
printf("%d.enter the i.d=",i+1);
scanf("%d",&a[i].id);
if(a[i].id==0)
{
printf("\n invalid id\n");
accept(a,n);
}
else
{
printf("%d.enter the name=",i+1);
scanf("%s",a[i].name);
printf("%d.enter the salary=",i+1);
scanf("%f",&sal);
a[i].salary=sal;
}
printf("pre\n");
}
return n;
}
int display(struct emp1 a[20],int n)
{
int i=0;
printf("\n");
printf("\nID\t\tNAME\t\tSALARY ");
for(i=0;i<n;i++)
{
if(a[i].dflag!=-1)
{
printf("\n\n");
printf("%d\t\t%s\t\t%f",a[i].id,a[i].name,a[i].salary);
printf("\n");
}
}
return n;
}
int append(struct emp1 a[20],int n)
{
if(n==0)
{
printf("\nEmpty set");
}
else
{
float sal=0.0;
printf("enter the i.d=");
scanf("%d",&a[n].id);
printf("enter the name=");
flushall();
scanf("%s",a[n].name);
printf("enter the salary=");
scanf("%f",&sal);
a[n].salary=sal;
n++;
printf("the appended data is:");
}
return n;
}
int delete1(struct emp1 a[20],int no,int u)
{
int i=0;
char ans='\0';
printf("\nAre you sure you want to delete(y/n):");
scanf("%d",&ans);
if(ans=='y'||ans=='Y')
{
for(i=0;i<no;i++)
{
if(u==a[i].id&&a[i].dflag!=-1)
{
a[i].dflag=-1;
break;
}
}
}
else if(ans!='y'||ans!='Y')
{
printf("\n You have not deleted");
}
return no;
}
int modify(struct emp1 a[20],int n,int v)
{
int i=0;
float sal=0.0;
if(n==0)
{
printf("\nEmpty set");
}
else
{
for(i=0;i<n;i++)
{
if(v==a[i].id)
{
if(a[i].dflag!=-1)
{
printf("Enter the new record for the id");
printf("\nEnter the name:");
scanf("%s",a[i].name);
printf("enter the salary:");
scanf("%f",&sal);
a[i].salary=sal;
}
else
{
printf("\nthe record is deleted");
}
}
}
}
return n;
}
neeraj goswami 0 Newbie Poster
Recommended Answers
Jump to PostHere you go!
#include <stdio.h> int main(int argc, char** argv) { printf("Hello World\n"); return 0; }
Jump to PostWhat is the meaning of this?
It's obvious that neeraj goswami did not want you to know what this is about, otherwise he would have said something by now. So use this rare opportunity to use your imagination!
I have attached a visual aid of the concept of imagination …
All 5 Replies
N1GHTS 102 Posting Whiz in Training
Lordvivi 0 Newbie Poster
N1GHTS 102 Posting Whiz in Training
greatparthi 0 Newbie Poster
N1GHTS 102 Posting Whiz in Training
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.