//************************************// //** **** * * ******** *** ****// //** * *** ** ** * ****** * ** *** ***// //** ** ** ** ** ** **** ** * **// //** *** * ** ** *** ** *** * ***** **// //** **** * * **** **** * ***** **// //************************************// //----( Edit by : mr nima nassiri )---// //------( tel : +98 9329000759 )------// #include //file #include //timer #include //timer #include //sound #include #include #include #include #include #include void read_id ( void ); void about ( void ); void f_co ( void ); void cls ( void ); void cls_s ( void ); void menu ( void ); void get_id ( void ); void titr ( void ); void insert ( void ); void list ( void ); void search ( void ); void del ( void ); void exit ( void ); void pass ( void ); void edit ( void ); struct student { char id[10]; char name [15]; char family [15]; }; struct student st[4]; int ch=7; int i , n=0 , found=0; int c1=7 , c2=7 , c3=7 , c4=7 , c5=7 , c6=7 , c7=2 ;//color master textback int ai , an , af , sim , len , le; char row[100]; FILE *fp; FILE *fp2; time_t td; int main () { cls(); pass(); while ( ch!=8 ) { menu (); // tabeh chap list menu switch (ch) { case 1 : { insert ();//tabeh break; }//end case 1 case 2 : { list ();//tabeh break; }//end case 2 case 3 : { search ();//tabeh break; }//end case 3 case 4 : { del ();//tabeh break; }//end case 4 case 5 : { edit ();//tabeh break; }//end case 6 case 6 : { exit ();//tabeh break; }//end case 5 case 7 : { about ();//tabeh break; }//end case 6 default : { break; }//end default }//end swich }//end while gotoxy (30,13); cout << "press any key for exit"; getch (); return 0; }// end program int main //***********( read_id )**********// void read_id ( void ) { f_co(); fgets(row,100,fp); while(!feof(fp) && found!=1) { len=strlen(row); le=0;ai=0;an=0;af=0;sim=0; found=0; while ( le<=len && sim<3) { if (row[le]==';' ) sim++; if (sim==0 && row[le]!=';') {st[3].id[ai]=row[le];ai++;} if (sim==1 && row[le]!=';') {st[3].name[an]=row[le];an++;} if (sim==2 && row[le]!=';') {st[3].family[af]=row[le];af++;} le++; } // end while le st[3].id[ai]='\0'; st[3].name[an]='\0'; st[3].family[af]='\0'; if (strcmp(st[1].id,st[3].id)==0) found=1; fgets(row,100,fp); }// end while feof(fp); fclose(fp); }// end void read_id //************( get id : )***********// void get_id ( void ) { gotoxy (25,10); cout << "Your select of menu is : " << ch << " )"; gotoxy (25,11); for (i=0 ; i<35 ; i++ ) cout << "-"; // tarahi jadval strcpy (st[1].id,"\0"); gotoxy (25,12); cout << "enter id :"; gets (st[1].id); }// end of void get_id //**********( insert data )**********// void insert ( void ) { cls_s(); strcpy (row,"\0"); strcpy (st[1].name,"\0"); strcpy (st[1].family,"\0"); strcpy (st[1].id,"\0"); do { gotoxy (54,10); cout << "Insert"; get_id (); read_id (); if ( found==1 ) { gotoxy (30,18); cout << "error : this id is use"; getch(); cls_s(); }//end if } while ( found==1 || st[1].id[0]=='\0' );// end while do { gotoxy (25,13); cout << "enter name :"; gets (st[1].name); } while ( st[1].name[0]=='\0' );// end while do { gotoxy (25,14); cout << "enter family :"; gets (st[1].family); } while ( st[1].family[0]=='\0');// end while strcpy(row,st[1].id); strcat(row,";"); strcat(row,st[1].name); strcat(row,";"); strcat(row,st[1].family); strcat(row,"\n"); f_co(); fputs(row,fp); fclose(fp); cls_s(); gotoxy (30,18); cout << "the info is save !"; getch(); }// end of void menu insert //**********( print all list )*******// void list ( void ) { int nup=1; int xy=3; int win=1,ewin=0; int page=1; char chw; titr(); f_co(); fgets(row,100,fp); while(!feof(fp) && ewin!=53) { len=strlen(row); le=0;ai=0;an=0;af=0;sim=1; while ( le<=len && sim<4) { if (row[le]==';' ) sim++; if (sim==1 && row[le]!=';') {st[2].id[ai]=row[le];ai++;} if (sim==2 && row[le]!=';') {st[2].name[an]=row[le];an++;} if (sim==3 && row[le]!=';') {st[2].family[af]=row[le];af++;} le++; } // end while le st[2].id[ai]='\0'; st[2].name[an]='\0'; st[2].family[af]='\0'; gotoxy (4,xy); printf (" %d",nup); gotoxy (10,xy); printf (" %10s ",st[2].id); gotoxy (30,xy); printf (" %15s ",st[2].name); gotoxy (52,xy); printf (" %15s \n",st[2].family); nup++; xy++; win++; fgets(row,100,fp); if (win%18==0) { gotoxy (4,xy+1); cout <<"page : "<>"; page++; chw=getch(); ewin=int(chw); if (ewin!=27) // end if ewin { cls_s(); titr(); xy=3; }// end else ewin }// end if win if (ewin==27) break ; }// end while feof(fp); fclose(fp); if (ewin!=27) { gotoxy (4,xy+1); printf("END OF Viewing LIST"); getch (); } }// end of void list //**********( search )***************// void search ( void ) { int pop=1; char rows[100]; char idss[10]; char ids[10]; char names [15]; char familys [15]; int ais,ans,afs,sims,lens,les; int founds=0; do { gotoxy (25,10); cout << "Your select of menu is : " << ch << " )"; gotoxy (25,11); for (i=0 ; i<35 ; i++ ) cout << "-"; // tarahi jadval strcpy (idss,"\0"); gotoxy (54,10); cout << "search"; gotoxy (25,12); cout << "enter id :"; gets(idss); } while ( idss[0]=='\0' );// end while founds=0; f_co(); fgets(rows,100,fp); while(!feof(fp) && founds!=1) { lens=strlen(rows); les=0;ais=0;ans=0;afs=0;sims=0; founds=0; while ( les<=lens && sims<3) { if (rows[les]==';' ) sims++; if (sims==0 && rows[les]!=';') {ids[ais]=rows[les];ais++;} if (sims==1 && rows[les]!=';') {names[ans]=rows[les];ans++;} if (sims==2 && rows[les]!=';') {familys[afs]=rows[les];afs++;} les++; } // end while le ids[ais]='\0'; names[ans]='\0'; familys[afs]='\0'; if (strcmp(ids,idss)==0) founds=1; fgets(rows,100,fp); }// end while feof(fp); fclose(fp); if ( founds==0 ) { cls_s(); titr (); gotoxy (30,18); cout << "error : this id is not use"; getch(); }//end if if ( founds==1 ) { cls_s(); titr (); gotoxy (4,3); printf (" %d",pop); gotoxy (10,3); printf (" %10s ",ids); gotoxy (30,3); printf (" %15s ",names); gotoxy (52,3); printf (" %15s \n",familys); getch(); }// end if found 1 }// end of void search //*********( delete )****************// void del ( void ) { int pop=1; char rows[100]; char idss[10]; char ids[10]; char names [15]; char familys [15]; int ais,ans,afs,sims,lens,les; int founds=0; do { gotoxy (25,10); cout << "Your select of menu is : " << ch << " )"; gotoxy (25,11); for (i=0 ; i<35 ; i++ ) cout << "-"; // tarahi jadval strcpy (idss,"\0"); gotoxy (54,10); cout << "delet"; gotoxy (25,12); cout << "enter id :"; gets(idss); } while ( idss[0]=='\0' );// end while founds=0; if(!(fp=fopen("data_save.txt","r+t")) || !(fp2=fopen("tmpfile.dat","a+t"))) { cls_s(); gotoxy (30,18); printf("Can not Open file"); getch(); } fgets(rows,100,fp); founds=0; while(!feof(fp)) { lens=strlen(rows); les=0;ais=0;ans=0;afs=0;sims=0; while ( les<=lens && sims<3) { if (rows[les]==';' ) sims++; if (sims==0 && rows[les]!=';') {ids[ais]=rows[les];ais++;} if (sims==1 && rows[les]!=';') {names[ans]=rows[les];ans++;} if (sims==2 && rows[les]!=';') {familys[afs]=rows[les];afs++;} les++; } // end while le ids[ais]='\0'; names[ans]='\0'; familys[afs]='\0'; if((strcmp(ids,idss))!=0) { fputs(rows,fp2); }//end if if((strcmp(ids,idss))==0) { founds=1; }//end if fgets(rows,100,fp); }// end while feof(fp); fclose(fp); fclose(fp2); remove("data_save.txt"); rename("tmpfile.dat","data_save.txt"); if ( founds==0 ) { cls_s(); gotoxy (30,18); cout << "error : this id is not use"; getch(); }//end if if ( founds==1 ) { cls_s(); gotoxy (30,18); cout<<"id "<< ids << " is deleted !"; getch(); } // end if found 1 }// end of void del //***********( edit )****************// void edit ( void ) { cls_s; del(); cls_s; insert(); }// end of void edit //***********( f_co )****************// void f_co ( void ) { found = 0; if (!(fp=fopen("data_save.txt","a+t"))) { gotoxy (30,18); printf("Can not Open file"); }// end if fp }// end of void f_co , contorol fko & co //*********( titr of data )**********// void titr ( void ) { cls_s(); gotoxy (4,1); cout << "n"; gotoxy (10,1); cout << "id number"; gotoxy (30,1); cout << "name"; gotoxy (52,1); cout << "family"; gotoxy (2,2); for (i=0 ; i<60 ; i++ ) cout << "-"; // tarahi jadval cout <<"\n"; }// end of void titr //***********( pass )**************// void pass ( void ) { cls(); cls_s(); char chp ; int ip=0,xp=15; char ap[10]; char pass[10]; strcpy (pass,"1234"); strcat (pass,"\0"); window(25,10,48,10); textcolor(BLACK); textbackground(WHITE); clrscr(); gotoxy (2,1); cprintf("Enter Pass :"); gotoxy (xp,1); while ( (chp!=13 && ip<10) || chp!=13 ) { chp=getch (); if (ip!=9) { if (chp>=48 && chp<=57) { gotoxy (xp,1); cprintf ("*"); gotoxy (xp,1); ap[ip]=chp; ip++; xp++; }// end if ch }// end if i if ( ip>0 && chp==8) { xp--; gotoxy (xp,1); cprintf (" "); gotoxy (xp,1); ip--; }// end if }//end while ap[ip]='\0'; if ( (strcmp(ap,pass))==0 ) { window(25,12,48,12); textcolor(BLACK); textbackground(WHITE); clrscr(); gotoxy (2,1); cprintf ("Password Is Ok Wellcom"); getch(); } if ( (strcmp(ap,pass))!=0 ) { window(24,12,49,12); textcolor(BLACK); textbackground(WHITE); clrscr(); gotoxy (1,1); cprintf ("Pass Is Not Ok Good Bye.."); getch(); exit(0); } }// end of void pass //***********( cls menu )**********// void cls ( void ) { window(1,1,80,25); textbackground(7); clrscr(); }// end void cls //***********( cls_s menu )**********// void cls_s ( void ) { window(2,2,79,24); textcolor(WHITE); textbackground(BLUE); clrscr(); }// end void cls_s //***********( about )**************// void about ( void ) { int rand=1; cls_s(); while (!kbhit()) { //date & timer gotoxy (2,22); putenv("TZ=PST8PDT"); tzset(); time(&td); printf("Date & Time : %s\n", asctime(localtime(&td))); // end date & timer if ( rand%5==0 ) { sound(random(2000)); delay(random(400)); nosound(); sound(random(2000)); delay(random(400)); nosound(); sound(random(2000)); delay(random(400)); nosound(); sound(random(2000)); delay(random(400)); nosound(); sound(random(2000)); delay(random(400)); nosound(); sound(random(2000)); delay(random(400)); nosound(); }// end if rand delay(random(300)); textcolor(random(15)); gotoxy (20,9); cprintf ("Site : WWW.MISHEH2NEMISHEH.BLOGFA.COM"); gotoxy (20,10); cprintf ("This Program Edit By : Nima Nasiri"); gotoxy (20,11); cprintf ("Email : N_1T2I_N@Yahoo.Com"); gotoxy (20,12); cprintf ("Tel : +98 932 9000759"); gotoxy (20,13); cprintf ("date : 1386/3/9"); rand++; }// end while }// end of void about //***********( print menu )**********// void menu ( void ) { char ch1,ch2; int b1,b2; cls(); while (b1!=13) { window(2,1,79,1); textbackground(7); clrscr(); window(2,1,12,1); textbackground(c1); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("1 -"); textcolor(BLACK); cprintf ("Insert"); window(14,1,22,1); textbackground(c2); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("2 -"); textcolor(BLACK); cprintf ("List"); window(24,1,34,1); textbackground(c3); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("3 -"); textcolor(BLACK); cprintf ("Search"); window(36,1,46,1); textbackground(c4); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("4 -"); textcolor(BLACK); cprintf ("Delete"); window(48,1,56,1); textbackground(c5); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("5 -"); textcolor(BLACK); cprintf ("Edit"); window(58,1,66,1); textbackground(c6); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("6 -"); textcolor(BLACK); cprintf ("Exit"); window(68,1,77,1); textbackground(c7); clrscr(); gotoxy (2,1); textcolor(RED); cprintf ("7 -"); textcolor(BLACK); cprintf ("About"); cls_s ();// clear black ch1 = getch (); b1 = int ( ch1 ); switch (b1) { case 0 : { ch2 = getch (); b2 = int ( ch2 ); switch (b2) { case 77 : if ( ch<8 ) ch++; break; case 75 : if ( ch>0 ) ch--; break; default : break ; }// end switch b2 break; }// end case 0 case 49 : ch=1;break ; case 50 : ch=2;break ; case 51 : ch=3;break ; case 52 : ch=4;break ; case 53 : ch=5;break ; case 27 : ch=6;break ; case 54 : ch=6;break ; case 55 : ch=7;break ; default : break ; }// end switch b1 switch (ch) { case 8 : ch=1; case 1 : c1=2;c2=7;c3=7;c4=7;c5=7;c6=7;c7=7;break ; case 2 : c2=2;c1=7;c3=7;c4=7;c5=7;c6=7;c7=7;break ; case 3 : c3=2;c1=7;c2=7;c4=7;c5=7;c6=7;c7=7;break ; case 4 : c4=2;c1=7;c2=7;c3=7;c5=7;c6=7;c7=7;break ; case 5 : c5=2;c1=7;c2=7;c3=7;c4=7;c6=7;c7=7;break ; case 6 : c6=2;c1=7;c2=7;c3=7;c4=7;c5=7;c7=7;break ; case 0 : ch=7; case 7 : c7=2;c1=7;c2=7;c3=7;c4=7;c5=7;c6=7;break ; default : break ; }// end switch ch }//end while b1 }// end of void menu //*************( exit )**************// void exit ( void ) { char chee; cls_s(); gotoxy (25,10); cout << "Your select of menu is : "<< ch <<" ) Exit"; gotoxy (25,11); for (i=0 ; i<35 ; i++ ) cout << "-"; // tarahi jadval gotoxy (25,12); cout << "Do you exit this program ( Y or N )"; chee = getch (); if ( chee == 'y' || chee=='Y') { exit(0); }// end if ch else ch=0; }// end of void exit