विचार धाराका अनेक, मध्ये एकको यो विवेक ।

C Programming-Projects(Part–1)

Analog and Digital Clock:

Display:

(99)

Codes:

#include<graphics.h>
#include<dos.h>
#include<stdlib.h>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<process.h>
void frame();
void draw_numbers(int,int,int);
void line_at_angle(int,float,int);
void beep(int,int);

void clear(int,int,int,int,int);
void main()
{
clrscr();
int gdriver=DETECT,gmode,errorcode;
struct time t,i;
int key, k=0, x,y,t_sec,t_min,midx,midy;
char tim[5];

float hour,ang_sec,ang_min,ang_hour;
initgraph(&gdriver,&gmode,"c:\turboc++\disk\turboc3\bin");
errorcode=graphresult();
if(errorcode!=grOk)
{
printf("Graphics error %s",grapherrormsg(errorcode));
printf("Press any key to halt.");
exit(1);
}
gettime(&t);
midx=getmaxx()/2;
midy=getmaxy()/2;
frame();
while(1)
{
if(kbhit())
{
key=getch();
if(key==27)
break;
}
gettime(&t);
if(t.ti_hour>=12)
hour=t.ti_hour-12;
else
hour=t.ti_hour;
ang_sec=t.ti_sec*6;
ang_min=(t.ti_min*6)+(ang_sec/60);
ang_hour=(hour*30)+(ang_min/12);
setcolor(4);
setfillstyle(1,9);
circle(midx,midy,6);
line_at_angle(150,ang_min,2); //min
setcolor(12);
setfillstyle(1,4);
line_at_angle(130,ang_hour,3); //hour
setcolor(14);
line_at_angle(170,ang_sec,1); //sec
line_at_angle(20,180+ang_sec,1); //sec
setfillstyle(1,4);
setcolor(13);
x=520,y=460;
gettime(&t);
if(t.ti_hour>12)
{
outtextxy(x+80,y,"PM");
sprintf(tim,"%d",t.ti_hour-12);
}
else
{
outtextxy(x+80,y,"AM");
sprintf(tim,"%d",t.ti_hour);
}
outtextxy(x,y,tim);
outtextxy(x+16,y,":");
outtextxy(x+42,y,":");
sprintf(tim,"%d",t.ti_min);
outtextxy(x+26,y,tim);
sprintf(tim,"%d",t.ti_sec);
outtextxy(x+50,y,tim);
k++;
if(k==1)
{
k=0;
beep(100,50);
}
else
delay(100);
t_sec=t.ti_sec;
t_min=t.ti_min;
clear(x+50,y,x+70,y+8,0);
if(t_sec>=59)
clear(x+26,y,x+46,y+8,0);
if(t_min>=59)
clear(x,y,x+20,y+8,0);
setcolor(0);
setfillstyle(1,0);
line_at_angle(130,ang_hour-6,1);
line_at_angle(150,ang_min-4,1);
line_at_angle(170,ang_sec,1);
line_at_angle(20,180+ang_sec,1);
ang_sec++;
}
closegraph();
}
void frame()
{
int midx,midy,i;
float angle=0;
float x,y;
midx=getmaxx()/2;
midy=getmaxy()/2;
setlinestyle(1,1,3);
setcolor(2);
circle(midx,midy,223);
setcolor(15);
circle(midx,midy,220); //white line angle
setcolor(12);
circle(midx,midy,217);
setlinestyle(1,1,3);
setfillstyle(1,2);
setcolor(4);
for(i=0; i<=60; i++)
{
x=cos((angle/180)*M_PI)*190; //round dot line
y=sin((angle/180)*M_PI)*190;
if((int)angle%30!=0)
circle(midx+x,midy+y,2);
angle+=6;
}
angle=0;
setfillstyle(1,4);
setlinestyle(0,1,2);
for(i=0;i<12;i++)
{
setcolor(13);
x=cos((angle/180)*M_PI)*190;
y=sin((angle/180)*M_PI)*190;
setcolor(10);
draw_numbers(midx+x,midy+y,i);
angle+=30;
}
}
void line_at_angle(int radius, float angle, int flag)
{
float x,y,x1,y1,x2,y2,x3,y3;
int midx, midy;
int poly1[10];
angle-=90;
midx=getmaxx()/2;
midy=getmaxy()/2;
x=cos((angle/180)*M_PI)*radius;
y=sin((angle/180)*M_PI)*radius;
setlinestyle(0,1,3);
if(flag==1)
line(midx,midy,midx+x,midy+y);
if(flag==2)
{
setlinestyle(0,1,1);
x2=cos(((angle+3)/180)*M_PI)*(radius-25);
y2=sin(((angle+3)/180)*M_PI)*(radius-25);
x3=cos(((angle-3)/180)*M_PI)*(radius-25);
y3=sin(((angle-3)/180)*M_PI)*(radius-25);
poly1[0]=midx;
poly1[1]=midy;
poly1[2]=midx+x2;
poly1[3]=midy+y2;
poly1[4]=midx+x;
poly1[5]=midy+y;
poly1[6]=midx+x3;
poly1[7]=midy+y3;
poly1[8]=midx;
poly1[9]=midy;
fillpoly(5,poly1);
setcolor(0);
x2=cos(((angle)/180)*M_PI)*(radius+1);
y2=sin(((angle)/180)*M_PI)*(radius+1);
x3=cos(((angle-4)/180)*M_PI)*(radius-25);
y3=sin(((angle-4)/180)*M_PI)*(radius-25);
line(midx+x2,midy+y2,midx+x3,midy+y3);
line(midx+x,midy+y,midx+x3,midy+y3);
}
else if(flag==3)
{
setlinestyle(0,1,1);
x2=cos(((angle+5)/180)*M_PI)*(radius-30);
y2=sin(((angle+5)/180)*M_PI)*(radius-30);
x3=cos(((angle-5)/180)*M_PI)*(radius-30);
y3=sin(((angle-5)/180)*M_PI)*(radius-30);
poly1[0]=midx;
poly1[1]=midy;
poly1[2]=midx+x2;
poly1[3]=midy+y2;
poly1[4]=midx+x;
poly1[5]=midy+y;
poly1[6]=midx+x3;
poly1[7]=midy+y3;
poly1[8]=midx;
poly1[9]=midy;
fillpoly(5,poly1);
setcolor(0);
x2=cos(((angle)/180)*M_PI)*(radius+1);
y2=sin(((angle)/180)*M_PI)*(radius+1);
x3=cos(((angle-6)/180)*M_PI)*(radius-30);
y3=sin(((angle-6)/180)*M_PI)*(radius-30);
line(midx+x2,midy+y2,midx+x3,midy+y3);
line(midx+x,midy+y2,midx+x3,midy+y3);
}
}
void beep (int fre,int wait)
{
sound(fre);
delay(wait);
nosound();
}
void draw_numbers(int x,int y, int position)
{
char stpos[5]=" ";
position+=3;
if(position>12)
position=position%12;
itoa(position,stpos,10);
outtextxy(x,y,stpos);
}
void clear(int x1, int y1, int x2, int y2, int col)
{
int x,y;
for(x=x1;x<=x2; x++)
for(y=y1; y<=y2; y++)
putpixel(x,y,col);
}




Employee Management Information System:


Display:


http://dahalsuman.blogspot.com


http://dahalsuman.blogspot.com


Code:

#include<graphics.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<process.h>
typedef struct Employee
{
char empId[15];
char fname[20];
char lname[20];
int age;
float bsal;
long phone;
}Employee;
FILE*fp;
Employee emp;
char fileName[]="EMP.txt";
char tempFileName[]="temp.txt";
/*functions used in project*/
void AddEmployee();
void ListEmployee();
void SearchEmployee();
void ModifyEmployee();
void DeleteEmployee();
void first();
char file();
void main()
{
char ch='a';
clrscr();
first();
fp=fopen(fileName,"rb+");
if(fp==NULL)
{
fp=fopen(fileName,"wb+");
if(fp==NULL)
{
printf("Can't Open File");
exit(0);
}
}
while(ch!='6')
{
ch=file();
switch(ch)
{
case '1':
AddEmployee();
break;
case '2':
ListEmployee();
break;
case '3':
SearchEmployee();
break;
case '4':
ModifyEmployee();
break;
case '5':
DeleteEmployee();
break;
case '6':
exit(0);
break;
default:
textcolor(RED+BLINK);
gotoxy(30,10);
cprintf("Wrong Choice!!!");
getch();
break;
}
}
}
void AddEmployee()
{
char another,ch;
do
{
clrscr();
fseek (fp,0,SEEK_END);
another='Y';
gotoxy(25,3);
textcolor(RED);
cprintf("ADD EMPLOYEE RECORD");
gotoxy(25,6);
textcolor(GREEN);
cprintf("1.Enter EMPLOYEE ID:");
gets(emp.empId);
gotoxy(25,7);
cprintf("2.ENTER FIRST NAME OF EMPLOYEE:");
gets(emp.fname);
gotoxy(25,8);
cprintf("3.ENTER LAST NAME OF EMPLOYEE:");
gets(emp.lname);
gotoxy(25,9);
cprintf("4.ENTER AGE OF EMPLOYEE:");
scanf("%d",&emp.age);
gotoxy(25,10);
cprintf("5.ENTER SALARY OF EMPLOYEE:");
scanf("%f",&emp.bsal);
gotoxy(25,11);
cprintf("6.ENTER PHONE OF EMPLOYEE:");
scanf("%ld",&emp.phone);
gotoxy(28,15);
textcolor(MAGENTA+BLINK);
cprintf("SAVE CHANGES (Y/N)?");
ch=getche();
if(ch=='Y'||ch=='y')
{
fwrite(&emp,sizeof(emp),1,fp);
fflush(stdin);
}
gotoxy(28,15);
cprintf("ADD ANOTHER EMPLOYEE(Y/N)?");
fflush(stdin);
another=getche();
fflush(stdin);
textcolor(WHITE);
}
while(another=='Y'||another=='y');
}
void ListEmployee()
{
int i;
fseek(fp,0,SEEK_SET);
textcolor(RED);
gotoxy(1,1);
cprintf("LIST OF EMPLOYEE RECORD");
textcolor(GREEN);
gotoxy(1,2);
cprintf("EMP_ID");
gotoxy(14,2);
cprintf("FIRST NAME");
gotoxy(27,2);
cprintf("LAST NAME");
gotoxy(40,2);
cprintf("AGE");
gotoxy(53,2);
cprintf("SALARY");
gotoxy(66,2);
cprintf("PHONE");
for(i=1;i<=80;i++)
{
textcolor(YELLOW);
gotoxy(i,3);
cprintf("_");
}
i=4;
while(fread(&emp,sizeof(emp),1,fp)==1)
{
gotoxy(1,i);
cprintf("%s",emp.empId);
gotoxy(14,i);
cprintf("%s",emp.fname);
gotoxy(27,i);
cprintf("%s",emp.lname);
gotoxy(40,i);
cprintf("%d",emp.age);
gotoxy(53,i);
cprintf("%.2f",emp.bsal);
gotoxy(66,i);
cprintf("%ld",emp.phone);
i++;
}
getch();
}
void SearchEmployee()
{
int i,datafound=0;
char employeeId[15];
char another,ch;
do
{
clrscr();
fseek(fp,0,SEEK_SET);
gotoxy(1,1);
textcolor(RED);
cprintf("SEARCH EMPLOYEE RECORD");
gotoxy(5,2);
textcolor(GREEN);
cprintf("ENTER EMPLOYEE ID:");
gets(employeeId);
while(fread(&emp,sizeof(emp),1,fp)==1)
{
if(strcmp(emp.empId,employeeId)==0)
{
datafound=1;
break;
}
}
if(datafound==1)
{
textcolor(RED);
gotoxy(4,4);
cprintf("RECORD OF EMPLOYEE");
textcolor(GREEN);
gotoxy(4,5);
cprintf("------------------------------");
gotoxy(4,6);
cprintf("EMPLOYEE ID:");
cprintf("%s",emp.empId);
gotoxy(4,7);
cprintf("FIRST NAME:");
cprintf("%s",emp.fname);
gotoxy(4,8);
cprintf("LAST NAME:");
cprintf("%s",emp.lname);
gotoxy(4,9);
cprintf("AGE:");
cprintf("%d",emp.age);
gotoxy(4,10);
cprintf("BASIC SALARY:");
cprintf("%.2f",emp.bsal);
gotoxy(4,11);
cprintf("PHONE:");
cprintf("%ld",emp.phone);
}
else
{
gotoxy(10,8);
cprintf("EMPLOYEE NOT FOUND!!!!");
}
gotoxy(25,15);
textcolor(RED+BLINK);
cprintf("SEARCH ANOTHER EMPLOYEE(Y/N)?");
fflush(stdin);
another=getche();
fflush(stdin);
textcolor(WHITE);
}
while(another=='Y'|| another=='y');
}
void ModifyEmployee()
{
int i,datafound=0,recordNo=0;
char employeeId[15];
char another,ch;
do
{
clrscr();
fseek(fp,0,SEEK_SET);
rewind(fp);
gotoxy(1,1);
textcolor(RED);
cprintf("MODIFY EMPLOYEE RECORD");
textcolor(GREEN);
gotoxy(2,2);
cprintf("ENTER EMPLOYEE ID TO BE MODIFIED:");
gets(employeeId);
while(fread(&emp,sizeof(emp),1,fp)==1)
{
if(strcmp(emp.empId,employeeId)==0)
{
datafound=1;
break;
}
recordNo++;
}
if(datafound==1)
{
gotoxy(5,3);
textcolor(RED);
cprintf("OLD RECORD IS:");
gotoxy(5,4);
textcolor(GREEN);
cprintf("EMPLOYEE ID:");
cprintf("%s",emp.empId);
gotoxy(5,5);
cprintf("FIRST NAME:");
cprintf("%s",emp.fname);
gotoxy(5,6);
cprintf("LAST NAME:");
cprintf("%s",emp.lname);
gotoxy(5,7);
cprintf("AGE:");
cprintf("%d",emp.age);
gotoxy(5,8);
cprintf("BASIC SALARY:");
cprintf("%.2f",emp.bsal);
gotoxy(5,9);
cprintf("PHONE:");
cprintf("%ld",emp.phone);
gotoxy(5,11);
textcolor(RED);
cprintf("ENTER NEW INFORMATION:");
gotoxy(5,12);
textcolor(GREEN);
cprintf("EMPLOYEE ID:");
gets(emp.empId);
gotoxy(5,13);
cprintf("FIRST NAME:");
gets(emp.fname);
gotoxy(5,14);
cprintf("LAST NAME:");
gets(emp.lname);
gotoxy(5,15);
cprintf("AGE:");
scanf("%d",&emp.age);
gotoxy(5,16);
cprintf("BASIC SALARY:");
scanf("%f",&emp.bsal);
gotoxy(5,17);
cprintf("PHONE:");
scanf("%ld",&emp.phone);
fseek(fp,sizeof(emp)*(recordNo),SEEK_SET);
gotoxy(10,19);
if(fwrite(&emp,sizeof(emp),1,fp)==1)
cprintf("THE RECORD HAS BEEN MODIFIED!!!");
else
cprintf("ERROR DURING MODIFICATION!!!!");
}
else
{
gotoxy(10,19);
cprintf("EMPLOYEE NOT FOUND!!!!!!");
}
gotoxy(10,21);
textcolor(RED+BLINK);
cprintf("MODIFY ANOTHER EMPLOYEE(Y/N)?");
fflush(stdin);
another=getche();
fflush(stdin);
textcolor(WHITE);
}
while(another=='Y' || another=='y');
}
void DeleteEmployee()
{
int i,datafound=0;
char employeeId[15];
FILE*fpTemp;
char another,ch;
do
{
clrscr();
fseek (fp,0,SEEK_SET);
rewind(fp);
textcolor(RED);
gotoxy(1,1);
cprintf("DELETE EMPLOYEE RECORD");
textcolor(GREEN);
gotoxy(2,2);
cprintf("ENTER EMPLOYEE ID TO BE DELETED:");
gets(employeeId);
while(fread(&emp,sizeof(emp),1,fp)==1)
{
if(strcmp(emp.empId,employeeId)==0)
{
datafound=1;
break;
}
}
if(datafound==1)
{
fpTemp=fopen(tempFileName,"wb");
rewind(fp);
while(fread(&emp,sizeof(emp),1,fp)==1)
{
if(strcmp(emp.empId,employeeId)!=0)
fwrite(&emp,sizeof(emp),1,fpTemp);
}
fclose(fp);
fclose(fpTemp);
remove(fileName);
rename(tempFileName,fileName);
fp=fopen(fileName,"rb+");
gotoxy(6,8);
cprintf("SUCCESSFULLY DELETED!!!!!!!!");
}
else
{
gotoxy(2,6);
cprintf("EMPLOYEE NOT FOUND!!!!");
}
gotoxy(10,20);
textcolor(RED+BLINK);
cprintf("DELETE ANOTHER EMPLOYEE(Y/N)?");
fflush(stdin);
another=getche();
fflush(stdin);
textcolor(WHITE);
}
while(another=='Y'||another=='y');
}
void first()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\turboc++\disk\turboc3\bin");
setcolor(GREEN);
settextstyle(4,0,3);
outtextxy(100,190,"EMPLOYEE INFORMATION SYSTEM:");
settextstyle(1,0,1);
setcolor(RED);
outtextxy(480,350,"DEVELOPED BY:");
setcolor(BLUE);
outtextxy(480,370,"YOUR NAME");
outtextxy(480,400,">>>>>>>>>>>>");
getch();
restorecrtmode();
}
char file()
{
int gdriver=DETECT,gmod;
char i;
initgraph(&gdriver,&gmod,"c:\turboc++\disk\turboc3\bgi");
setcolor(RED);
setcolor(GREEN);
settextstyle(7,0,3);
setcolor(YELLOW);
outtextxy(260,95,"MAIN MENU");
settextstyle(0,0,0);
setcolor(MAGENTA);
outtextxy(200,145,"1>>ADD EMPLOYEE RECORD");
outtextxy(200,170,"2>>LIST RECORDS OF ALL EMPLOYEE:");
outtextxy(200,195,"3>>SEARCH A PARTICULAR EMPLOYEE:");
outtextxy(200,220,"4>>MODIFY INFORMATION OF A EMPLOYEE:");
outtextxy(200,245,"5>>DELETE A EMPLOYEE:");
outtextxy(200,270,"6>>EXIT SYSTEM:");
setcolor(GREEN+BLINK);
outtextxy(200,360,"ENTER YOUR CHOICE:");
i=getche();
restorecrtmode();
return (i);
}





शेयर गर्नुहोस्:

1 comment:

Test

टुइटर टुइट

अरुको ब्लग पनि पढ्नुहोस्

यूट्युव च्यानल

नेपाली क्यालेन्डर

आफ्ना कुरा पठाउनुहोस्

Name

Email *

Message *