Telephone directory which can be used to store, edit, search data

#include<iostream.h>
#include<fstream.h>
#include<graphics.h>
#include<process.h>
#include<io.h>
#include<dos.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
class telephone
{
char name[25];
char address[40];
char phoneno[15];
public:
telephone(){ }
telephone(char nam[25], char add[40], char phone[15])
{
strcpy(name,nam);
strcpy(address,add);
strcpy(phoneno,phone);
}
void init();
void button(int x1,int y1,int x2,int y2,char str[]);
int press(int,int,int,int);
int unpress(int,int,int,int);
int mouseini();
int showmp();
int hidemp();
int getmp(int *button,int *x,int *y);
int setmp();
int click(int x1,int y1,int x2,int y2,char str[]);
int screen();
void login();
void search();
void delete1();
void insert();
void update();
void display()
{
cout<<"
Name
: "<<name;
cout<<"
Address : "<<address;
cout<<"
Phone Number: "<<phoneno;

}
int compare(char nam1[25])
{
if(strcmp(nam1,name)==0)
return 1;
else
return 0;
}
};
void telephone::login()
{
setcolor(15);
line (320-150,320-13,320+150,320-13);
line (320-150,320+12,320+150,320+12);
line (320-150,320-13,320-150,320+12);
line (320+150,320+12,320+150,320-13);
int s=30,w;
gotoxy(20,23);
cout<<"LOADING . . .";
for (int x1=171,x2=171,y1=308,y2=331,y=1,S=0;x1<470;x1++,x2++,y++,S++)
{
setcolor(1);
line (x1,y1,x2,y2);
w=(x1-169)/3;
for (int i=34; i<=78; i++)
{
gotoxy(i,23) ;
cout <<" " ;
}
gotoxy(34,23); cout<<w<<"%";
if (x2>270) s=45; if (x2>370) s=10;
if (x2==320) delay(999); else
delay(s);
}
delay(800);
for (int i=27; i<=78; i++)
{
gotoxy(i,23) ;
cout <<" " ;
}
}
void telephone::insert()
{
telephone tel1;
fstream file;
file.open("Phone.txt",ios::app);
tel1.init();
file.write((char *) &tel1, sizeof(tel1));
setcolor(7);

} void telephone::delete1() { telephone tel1."Deleting Record.close() . char nam[25].nam). while (file. cout<<"Enter the Name to be deleted: ". } file.read((char *) &tel1. ios::out) .open("Phone."").txt".getline(phoneno."Inserting Record.close() . file. } void telephone::init() { cout<<" Enter Name : ".").open("Phone.open("temp..read((char *) &tel1.. temp."). temp. delay(3000). strcpy(nam1. cin.txt". ios::in) . sizeof(telephone)) ... sizeof(telephone)) . temp.compare(nam)) temp.250. if(strlen(nam1)!=0) { file. sizeof(telephone))) { if(!tel1. setcolor(7). cin.seekg(0. } else .close() . else strcpy(nam1..outtextxy(250.open("temp.25).. } file. cin>>nam.write((char *) &tel1.ios::beg) .seekg(0. file. cout<<" Enter Address : ". cout<<" Enter Phone Number: ".getline(name. ios::out) .getline(address. outtextxy(250.. file.40).txt". sizeof(telephone))) { file. fstream temp .nam1[25].. while (temp. temp.close() .250. ios::in) .ios::beg) .write((char *) &tel1. cin. temp.15).close().txt". fstream file .

add. ios::out) ..open("temp.. sizeof(tel1)). while (file.write((char *) &tel1.write((char *) &tel1.getline(ph.write((char *) &tel1.ios::beg) . strcpy(nam1. file. char nam[25]. file."). cout<<"Enter the Name to be updated: ". temp.nam1[25].txt". sizeof(telephone)) .open("Phone.250. while (temp. outtextxy(250.cin. char nam[25].seekg(0.read((char *) &tel1.. ios::in) .read((char *) &tel1.250.txt".close() . cin>>nam.ph). fstream file . fstream temp . sizeof(telephone))) { file.txt".outtextxy(250.. temp. cin. temp.add[40]."Updating Record.close() . cout<<" Enter Name : ". cout<<" Enter Address : ". temp.25).compare(nam)) temp. temp. } file.getline(nam.txt". delay(3000).seekg(0.close() .""). file.txt". .40). tel1=telephone(nam. ios::in) .open("Phone.ph[15]. file.ios::beg) . cout<<" Enter Phone Number: ". setcolor(7).15). else strcpy(nam1. if(strlen(nam1)!=0) { file."Record not found"). cin.open("temp.open("Phone.getline(add. file. sizeof(telephone)) . } void telephone::update() { telephone tel1. ios::out) .ios::app).close(). } file.close() . cin. sizeof(telephone))) { if(!tel1.nam).getline(nam.25).

} } file. char nam[25]. } xc=(x2-x1)/2+x1-l.txt". file.int y1.y2).display().compare(nam)) { tel1.int y2. file. settextstyle(0.i=0. cin>>nam.y1.l=0. } getch(). sizeof(telephone))) { if(tel1.seekg(0.close() . yc=(y2-y1)/2+y1.ios::in).read((char *) &tel1.yc. } void telephone:: button(int x1. delay(3000).yc.250.str)."Record not found").x2. outtextxy(250. i++.int x2. while(i<strlen(str)) { l+=4. cout<<"Enter name to be Searched: ". } . telephone tel1. break . while(file. } void telephone::search() { fstream file."Record not found").} else outtextxy(250. if(i) { setcolor(7). int i=1. i=0. setcolor(11). outtextxy(xc.0).ios::beg). unpress(x1.open("Phone.250.0.char str[]) { int xc.

x2.y1.y2).y2).x.&i. line(x2. line(x1.&o). } int telephone:: press(int x1.y2.&o). line(x1.y1. return 0.1. setfillstyle(1.o. line(x1.x2.1).o.y2).1).y1.1.1).y1.x. int86(0x33.y1. line(x1. } int telephone:: showmp() { union REGS i. bar(x1.y1. line(x1.ax=1. return 0. setcolor(0). return 0.ax=2. line(x2.int telephone:: unpress(int x1. i. setcolor(WHITE). i.x2.x2.x2.&o).x2.int y2) { setlinestyle(0.y2).y2.x1.&i.y1).ax=0. return 0.y1.y2).o.int x2. } int telephone:: hidemp() { union REGS i.&i. int86(0x33. } int telephone:: mouseini() { union REGS i. return(o.int y1. line(x1.x2. int86(0x33.y1.y2).y2).y1). i.1).x2. setcolor(WHITE). setcolor(0).x. } . bar(x1.int y2) { setlinestyle(0.int x2.int y1.x.ax). setfillstyle(1.y2).x1.

while(i<strlen(str)) { l+=4.x.&i.y2).ax=3. setcolor(11). return 0.x. settextstyle(0.x.x.y2).x2.o.yc.str). *x=o. } int telephone:: click(int x1.&x.&o). press(x1. int86(0x33.i=0. *y=o. .char str[]) { int button. unpress(x1.&o). if( (x>x1 && x<x2) && (y>y1 && y<y2) && button==1) { hidemp(). getmp(&button. return 0.int *x. i. while((button==1)) getmp(&button.x.0. i.&y). int mx=getmaxx(). i.&y).cx. yc=(y2-y1)/2+y1.my=getmaxy(). settextstyle(0.yc.cx=(3*mx/4)+20. } int telephone:: setmp() { union REGS i. outtextxy(xc.0). int86(0x33.x.int telephone:: getmp(int *button. showmp().0.o.int y2.int y1.0).x.x2. hidemp(). *button=o.dx.dx=(3*my/4)+20.y1. } xc=(x2-x1)/2+x1-l.y1.int *y) { union REGS i.y.&i.int x2.x.ax=4. int xc. showmp().l=0.&x. i.bx. setcolor(11). i++.

400.150.300. settextstyle(0. } if(click(250. setcolor(11). } showmp().0."Search")==0) { .250.400."Insert"). setcolor(11). button(250. setmp(). return 0.300."Exit").str).400. insert().400.i<500. } if(click(250. return 0.350.400.6). return 0. } else return 1.150.400. nosound(). outtextxy(600. while(1) { if(click(250."Insert")==0) { cleardevice().250.outtextxy(xc."Delete"). sound(i+200).300. button(250. } int telephone:: screen() { settextstyle(0.200. } if(click(250. button(250. outtextxy(xc.400.1.400."TELEPHONE").yc. button(250. return 0.100.30.200.200."Search").400. for(i=50.100. button(250.250.250. outtextxy(100. delete1()."Update").yc.30.150."Delete")==0) { cleardevice(). update()."DIRECTORY").0).200.str)."Update")==0) { cleardevice().i=i+50) { delay(10).150.

in which two balls are bounchback from the wall of the console. char op[8]. outtextxy(250.0.. outtextxy(335. } if(click(250. tel."Exit")==0) exit(0).cleardevice().250. outtextxy(250."User Name:").""). while(1) { cleardevice().").*pass.showmp()..250.gmode.400.cp[8]."Illegal User. initgraph(&gdriver.np[8]."Password :").. settextstyle(0.screen(). return 0. } } else { cleardevice(). if(strcmp(pass.pass1)==0) { cleardevice().1).300. search().265. tel. } } void main() { char user[25]="User Name". tel. } } } Moving ball screensaver.*pass1="user". settextstyle(0. tel.350.login(). delay(3000). while(1) { cleardevice(). */ . outtextxy(250.0. pass=getpass("").2). telephone tel. int gdriver=DETECT.user).mouseini().&gmode.250.

0.0.12.12.12.12.12.12.12.0}.0.12.12. {0. {0.0.12. {0.12.12.0}.12.12.12.0.0.0}. void *ptr1[4].12.12.12.12.0.12.0}.12.12.12.0}.0.12.12.12.0.12.12.12.0.0.12.12.0.0.12.0.12.0.0}.12.12.12.12.12.12.12.12.12.0}.12.12.0.0.0. {0.12.12.0.12.12.12. {0.12.12.12.12.12.12.12.0. {0.12.12.0.12. {0.12.15.12.12. {0.12.0}.12.0}.12.12.0.12. } /* This sub-routine will check which path to follow on stiking the wall of the container */ void state(int x.12.12.12.12.12.12.0.y)&&!kbhit()) { putimage(x.12.12.12.12.0.getmaxy()-y.12.0.12.15.0.0.12.12.12.15.12.12.0.12. {0.12.0.0}.0.12.12.0.12.0.12. {0.12.12.12.12.12.12.12.12.12.12.12.0.12.15.12.0.12.int mode).12.12.12.12.12.12.12.12.12.0.12.12.COPY_PUT).0.12.12.12.15.0.12.12. int i.12.0.12.12.12.COPY_PUT).12.12.12.12.0. {0.0.12.12.0}.12.12.h" #include"dos.12.12.15.12.0.12.int mode) { while(COND(x.12.12.0.12.12.0. {0.12.12.12.12.12.0.12.0.12.12.h" #include"conio. {0. {0.12.12.12.12.12.12. /* Condition to check out of range */ int COND(int x.12.0.0}.12.12.0.12.12.12.0.12.12.0.0.12.0. .12.12.12.12.0}.int y) { if (x>10 && x<getmaxx()-10 && y>10 && y<getmaxy()-10) return 1.12.12.12.0.*ptr2[4].0}.12. {0.12.12.12.0.0.12.12.0.12.12.12.12.12.ptr1[4].12.12.15. {0.12.12.0.0} }.12. else return 0.12.0.12.12.0.0.12.12.0.12.12.12.y.12.0.12.12.12.12.12.12.12.12.15.12.12.12.0.12.0.0.12.12.12.12.#include"graphics.12. {0.0.12.12. {0.0}.12.12.12.0.12.0.0.12.0.0.12.0.12.12.12.12.12.15.12.12.12.12.12.12.12.12.ptr1[4].int y. /* 3d Ball */ char ball[20][20]= { {0.12.0.15.h" #include"stdlib.12.12.0.0.12.0}.0}.12.12.12.h" #define DELAY 1 #define SOUND 3500 void state(int x.0.12.12.12.12.12.0. putimage(getmaxx()-x.int y.12.0.12.12.0.12.12.12.0}.12.0.12.12.12.12.12.12.0.12. {0.12.12.0.12.12.0.0}.15.12.12.

switch(mode) { case 0: x++. case 2: state(++x. nosound(). break. putimage(getmaxx()-x.3). } delay(DELAY). break. case 2: x--.y.1).++y. case 3: x--. switch(mode) { case 0: state(--x.COPY_PUT). break.ptr2[4]. case 1: x++. putimage(x.--y. break.++y. break. case 3: state(++x. if(x>=(getmaxx()-10)||x<=10) { sound(SOUND). switch(mode) { . } cleardevice(). y++.--y.2). y--. } } else if(y>=getmaxy()-10||y<=10) { sound(SOUND).ptr2[4]. y++.0). break.getmaxy()-y. break. break.COPY_PUT). case 1: state(--x. y--.

ptr2[4]).case 0: state(--x. } void main() { int gm. case 1: state(--x.1).j++) if(ball[i][j]!='0') putpixel(10+i.v1. int stp.++y.10.30.e2.p2.dsp.h> #include<conio. break.j. } } else exit(0).2).10+j.v2. int xr.10.30.h> #include<stdio.&gm.yr.i++) for(j=0.0).h> class Snake { int p1. break. break. int i.ball[j][i]).30.--y. case 2: state(++x.prev.egGen. initgraph(&gd.h> #include<graphics.n.20) */ state(20.j<20. case 3: state(++x.now.3). break. /* start with (20.20.dly. .h> #include<dos. void caught().0). getch(). getimage(10."\tc\tc\bgi").gd=DETECT.h> #include<stdlib. } Snake Game #include<iostream.i<20.ptr1[4]).h> #include<time.h> #include<string.++y.m.cnt. cleardevice().e1.--y.colr. for(i=0.v3. getimage(10.30.

Snake(Snake*). Snake::Snake() { } Snake::~Snake() { } void Snake::checkEgg() { if((e1 == p1) && (e2 == p2)) {sndEt(). int strtX. void check().strtY. void chngDir(). void sndCgt(). void score(). } } void Snake::sndEt() {nosound(). delay(2). score(). void sndEt(). void gnrtUnCond(). dly--. void gnrtCond().endX. .endY.public: long scr.x>0. delay(1). void checkEgg(). ~Snake(). int test(). } void Snake::sndCgt() {nosound(). void egg(). for(int x=1000. sound(2500). void move(). n++. }. void transpose(). int pos[100][2]. nosound().x--) {sound(x). Snake(). void show(). void init(). egg().

settextstyle(8. } ltoa(scr. outtextxy(585.1).40.p). prev = now. prev = now.10).p). } void Snake::gnrtCond() {if(n < 367) {if(now == 8 && (prev != 8 && prev != 2)) {pos[0][0] = p1. pos[0][1] = p2.0.dsp. outtextxy(585. . } } } void Snake::gnrtUnCond() { if( prev == 8 ) {pos[0][0] = p1. ltoa(scr. } if(now == 2 && (prev != 8 && prev != 2)) {pos[0][0] = p1. } if( prev == 4 ) {pos[0][0] = p1 + dsp. } void Snake::score() { char *p. setcolor(10).dsp.dsp. pos[0][1] = p2 .10).} nosound(). pos[0][1] = p2 + dsp.p.40. } if(now == 4 && (prev != 4 && prev != 1)) {pos[0][0] = p1 + dsp.p. pos[0][1] = p2 . prev = now. if(egGen != 1){ scr = scr + dly / 10. prev = now. pos[0][1] = p2. setcolor(0). } if(now == 1 && (prev != 1 && prev != 4)) {pos[0][0] = p1 .

setcolor(colr).dsp. } if( prev == 1 ) {pos[0][0] = p1 . pos[0][1] = p2.yr).i < n.pos[0][1] = p2.9). } void Snake::check() { if(p1 > endX) {p1 = strtX. if(egGen == 2) egGen--. p2 = pos[0][1].} else if(p1 < strtX) {p1 = endX. setfillstyle(1. } p1 = pos[0][0]. break.i++) { if(p1 == pos[i][0] && p2 == pos[i][1]) {caught(). } else egGen = 0. pos[0][1] = p2.v2. if(now == 8 || now == 2) .} else if(p2 < strtY) {p2 = endY.getbkcolor()). if(egGen != 1) { setcolor(getbkcolor()). pos[0][1] = p2 + dsp. setfillstyle(1. } if( prev == 2 ) {pos[0][0] = p1.} pos[0][0] = p1. fillellipse(v1. } } } void Snake::show() { int x = getcolor(). for(int i = 1.yr.} if(p2 > endY) {p2 = strtY.

show(). delay(dly/4).xr).i >= 1. gnrtCond(). do{ if(!kbhit()) {checkEgg().i--) {pos[i][0] = pos[i-1][0]. } void Snake::transpose() { int i. } }while(stp).yr).x.fillellipse(pos[0][0]. } else if(stp){ chngDir(). else st = 0. } void Snake::init() {time_t tm.j. p1 = pos[0][0]. check(). delay(dly/4). v2 = pos[n-1][1].pos[0][1]. . st = 1. delay(dly/4). pos[i][1] = pos[i-1][1]. for(i = n-1. setcolor(x).xr. delay(dly/4). gnrtUnCond(). p2 = pos[0][1]. if(!egGen){ v1 = pos[n-1][0]. srand(time(&tm)). } else egGen = 0. dsp = 20. check(). if(!st) show(). transpose().yr. } } void Snake::move() { int st = 0.pos[0][1]. else if(now == 4 || now == 1) fillellipse(pos[0][0].y.

3).endY+25. line(endX+25.40.135. dly = 150. setcolor(11). settextstyle(8. outtextxy(514.getmaxx()-15. outtextxy(522. } strtX = 21. } void Snake::caught() . line(endX+25. setlinestyle(0.getmaxx()-15.195.0.1). score().strtY+275.strtY-15. egg().strtY-15. now = prev.1).110. setcolor(x). pos[i][1] = 301.1.0.strtY+75.strtY+200. settextstyle(8.1).9). colr = 14.175. setcolor(14)."SNAKE"). yr = 9. prev = 4.getmaxx()-15.getmaxy()-5). line(endX+25. xr = 3. for(int i = 4. egGen = 1. endX = 481.strtY+75).getmaxx()-15. outtextxy(524.endY+15). settextstyle(11.i ."e = EXIT"). dsp = 20." -MOVEMENT").205.n = 5. rectangle(endX+25. setcolor(15). outtextxy(512.0.endY+15). rectangle(strtX-15.155. setlinestyle(0.1."g = RESUME").endX+15. scr = 0.strtY+275).i >= 0. endY = 361. stp = 111. outtextxy(522. outtextxy(522."ARROWS"). outtextxy(getmaxx()-500. setcolor(14). strtY = 21. outtextxy(513.strtY+200).getmaxx()-15.5).0. settextstyle(4." CONTROLS ")."p = PAUSE"). int x = getcolor().i--) {pos[i][0] = 201 + (n .getmaxy()-110."SCORE"). rectangle(strtX-15. cnt = -1.1) * dsp.

250.{ stp = 0.i++) {if(i%2) {setcolor(10)."GAME OVER").0. } } sleep(1). while(1) {if(kbhit()) {int c = getch(). delay(500).endY-10. else if(x == 80) now = 2."PAUSE"). settextstyle(11. else if(x == 75) now = 1. . outtextxy(512. break. for(int i=0.getmaxy()-160). fillsettingstype *p. sndCgt(). else if(x == 'e') caught(). if(c == 'g') {clr = getcolor()."GAME OVER"). } else {setcolor(0).9). setcolor(10).250. outtextxy(endX+60. else if(x == 77) now = 4. setcolor(0). char x = getch().i<=7. rectangle(endX+40. } void Snake::chngDir() {int clr. if(x == 72) now = 8. } } else {if(twnkl%2) {clr = getcolor(). delay(900). outtextxy(512. else if(x == 'p') {//int y = getcolor().endY-29.getmaxx()-35. int twnkl = 1.

else return 0. } settextstyle(8. } int Snake::test() { for(int i=0.getmaxy()-160). if(v1 == e1 && v2 == e2) break. } void Snake::egg() { do {e1 = (rand() % 100) * dsp + strtX.e2. }while(test()). egGen = 2.endY-29. if((e1 >= endX+1) || (e2 >= endY+1)) break. rectangle(endX+40. int x = getcolor(). setcolor(7).getmaxx()-35.getmaxx()-35.endY-10. fillellipse(e1.getmaxy()-160).xr+2).xr+2.i++) {if(e1 == pos[i][0] && e2 == pos[i][1]) break. setfillstyle(1. outtextxy(endX+60.i<n.0.random(15)+1).endY-29. } . } } Snake::Snake(Snake *p) { *p=NULL."PAUSE").rectangle(endX+40. } else { clr = getcolor(). setcolor(clr). e2 = (rand() % 100) * dsp + strtY.endY-10. setcolor(0). outtextxy(endX+60. } if(i != n) return 1. delay(1000). delay(1000). setcolor(x).1). } } twnkl++."PAUSE").

restorecrtmode().k.void main() {Snake snk.move(). closegraph().init().&gm.y.gm. int gd=DETECT.i. snk. } .x. clrscr(). initgraph(&gd.j."E:\Turboc3"). snk.

Sign up to vote on this title
UsefulNot useful