//programming by a. najafzadeh March 29, 2005 - 1384/01/07 #include #include #include #include #include void number_a(int);//func 1111111 void give_no(int);//func 22222222 void list_show(int);//func 333333 void edit_name(int);//func 444444 void sort_list(int);//func 555555 void fu_ex(int);//func 6666666666 void deldel(int);//func 777777777 void back_up1(int);//func 8888888 void del_nrecord(int);//func 9999 //starting struct 1**1*1*1*11**1**11*1**1*1*1*1*1**1*1*1* struct stmy{ char name[20]; long int stno; }stu ; //end of struct 1**1*1*1*11**1**11*1**1*1*1*1*1**1*1*1*1* int main() { int cin_num; number_a(cin_num);//func 11111 getch(); return 0; } //func 1111111111111111111111111111111111111111111111111111111111111111111111111 void number_a(int num) { while(num < 1 || num > 8) { textbackground(1); clrscr(); cout<<"what do you want to do now?\n"; cout<<"you can just enter numbers 1,2,3,4,5,6,7\n"; cout<<"1 = for enter new name to list\n2 = see the complete list\n"; cout<<"3 = for editing one record\n4 = for sorting the list\n"; cout<<"5 = for delleting one record\n"; cout<<"6 = for giving backup from records\n"; cout<<"7 = for delleting n records from list:\n"; cout<<"8 = exit from program\nenter one nuber\n"; cin>>num; } if(num == 1) give_no(num);//func 2222222222 else if(num == 2) list_show(num);//func 333333333 else if(num == 3) edit_name(num);//func 444444444 else if(num == 4) sort_list(num);//func 555555555 else if(num == 5) deldel(num);//func 777777777777 else if(num == 6) { num = 0; back_up1(num);//func 8888888 } else if(num == 7) del_nrecord(num);//func 9999999 else if(num == 8) fu_ex(num);//func 6666666666666 } //func 2222222222222222222222222222222222222222222222222222222222222222222222222 void give_no(int num) { char *al , ss; long int row = 3 , a = 0 , co_num = 0 , n = 1 , co_num1 = 0, i; al = new char[a]; char ali[5] = "exit"; clrscr(); cout<<"name stname \n"; cout<<"=============================\n"; ofstream as("bop/asd.txt" , ios::app); if(!as) { cout<<"file not found"; getch(); exit(0); } while(1) { gotoxy(1 , row); cin>>stu.name;/*refer to struct stmy*/ if(strcmp(stu.name , ali) == 0) break; gotoxy(17 , row); //*************************************************************************** while(ss = cin.get() , ss != '!') { if(!((int)ss < 48 || (int)ss > 57 || ss == ' ')) { al[a] = ss; a++; } } sss: for(i = a-1; i >= 0; i--) { co_num = (((int)al[i]) - 48); co_num = co_num * n; co_num1 += co_num; n *= 10; } a = 0; n = 1; stu.stno = co_num1; co_num = 0; co_num1 = 0; //*************************************************************************** as.write((char *) &stu , sizeof(struct stmy)); row++; stu.stno = 0; } as.close(); num = 0; number_a(num); } //func 3333333333333333333333333333333333333333333333333333333333333333333333333 void list_show(int num) { int row = 3; clrscr(); char fff; ifstream as1("bop/asd.txt"); if(!as1) { cout<<"file not found"; getch(); exit(0); } cout<<"name stname \n"; cout<<"=============================\n"; while(as1.read((char *) &stu , sizeof(struct stmy))) { if(row == 45) { gotoxy(1 , 25); cout<<"press any key to see next page"; getch(); clrscr(); gotoxy(1 , 1); cout<<"name stname \n"; gotoxy(1 , 2); cout<<"=============================\n"; row = 3; } if(row > 23) { gotoxy( 30 , 1); cout<<"name stname \n"; gotoxy( 30 , 2); cout<<"=============================\n"; gotoxy( 30 , row - 21); cout<>fff; num = 0; number_a(num); } //func 4444444444444444444444444444444444444444444444444444444444444444444444444 void edit_name(int num) { char *all , ss , nam2[20]; long int a = 0 , co_num = 0 , n = 1 , co_num1 = 0, i ; int row = 3; clrscr(); all = new char[a]; ifstream as("bop/asd.txt"); ofstream al("bop/temp.txt"); if(!as || !al) { cout<<"file not found"; getch(); exit(1); } cout<<"enter one name to edit"; cin>>nam2; while(as.read((char *) &stu , sizeof(struct stmy))) { if(strcmp(stu.name , nam2) == 0) { clrscr(); cout<<"name stname \n"; cout<<"=============================\n"; gotoxy( 1 , row); cin>>stu.name; //**##@@@@****$$$$###@@@@@**##@@@@****$$$$###@@@@@**##@@@@****$$$$###@@@@@**##@^ gotoxy(15 , row); while(ss = cin.get() , ss != '!') { if(!((int)ss < 48 || (int)ss > 57 || ss == ' ')) { all[a] = ss; a++; } } sss: for(i = a-1; i >= 0; i--) { co_num = (((int)all[i]) - 48); co_num = co_num * n; co_num1 += co_num; n *= 10; } a = 0; n = 1; stu.stno = co_num1; co_num = 0; co_num1 = 0; //**##@@@@****$$$$###@@@@@**##@@@@****$$$$###@@@@@**##@@@@****$$$$###@@@@@**##@^ } al.write((char *) &stu, sizeof(struct stmy)); } as.close(); al.close(); remove("bop/asd.txt"); rename("bop/temp.txt" , "bop/asd.txt"); num = 2; number_a(num); } //func 5555555555555555555555555555555555555555555555555555555555555555555555555 void sort_list(int num) { long int num3 = 0 , kod = 0 , kod3 = 0 , sub1 = 0 , f_lo2 = 0 , f_lo = 0 , end = 0; loop1: clrscr(); num3 = 0; ifstream as("bop/asd.txt"); ofstream so("bop/sorting.txt" , ios::app); ofstream te("bop/temp.txt"); if(!as || !so || !te) { cout<<"file not found"; getch(); exit(0); } while(as.read((char *) &stu , sizeof(struct stmy))) { kod3++; if(stu.stno > num3) { num3 = stu.stno; kod = kod3; } } f_lo++; if(f_lo == 1) f_lo2 = kod3; kod3 = 0; as.close();//kod = shomarandeie line big number ifstream as1("bop/asd.txt");//rikhtan dar temp bedoone big(contor = sub1 gias ba kod) if(!as1) { cout<<"file not found"; getch(); exit(0); } while(as1.read((char *) &stu , sizeof(struct stmy))) { sub1++; if(sub1 == kod) continue; te.write((char *) &stu , sizeof(struct stmy)); } as1.close(); te.close(); sub1 = 0;//dar temp rikhte shod bedoone big ifstream as2("bop/asd.txt"); if(!as2) { cout<<"file not found"; getch(); exit(0); } while(as2.read((char *) &stu , sizeof(struct stmy))) { sub1++; if(sub1 == kod) so.write((char *) &stu , sizeof(struct stmy)); } sub1 = 0; so.close(); as2.close(); remove("bop/asd.txt"); rename("bop/temp.txt" , "bop/asd.txt"); end++; cout<>del_name; clrscr(); ifstream as("bop/asd.txt"); ofstream al("bop/temp.txt"); if(!as || !al) { cout<<"file not found"; getch(); exit(0); } while(as.read((char *) &stu , sizeof(struct stmy))) { if(strcmp(stu.name , del_name) == 0) { del7++;//go 9 line down continue; } al.write((char *) &stu , sizeof(struct stmy)); } as.close(); al.close(); remove("bop/asd.txt"); rename("bop/temp.txt" , "bop/asd.txt"); if(del7 == 0) { clrscr(); cout<<"your entered record not in list"; } else { clrscr(); cout<<"record in file is deleted press any ke to continue"; } getch(); num = 2; number_a(num); } //func 8888888888888888888888888888888888888888888888888888888888888888888888888 void back_up1(int num) { ifstream as("bop/asd.txt"); ofstream te("back_up/asd.bak"); if(!as || !te) { clrscr(); cout<<"back up failed"; getch(); exit(0); } while(as.read((char *) &stu , sizeof(struct stmy))) te.write((char *) &stu , sizeof(struct stmy)); as.close(); te.close(); clrscr(); cout<<"backup = ok #/_"; if(num == 6) { cout<<"\nthankyou for using our software. . . . ."; cout<<"\npress anu key to exit"; getch(); exit(0); } else num = 0; cout<<"\npress anu key to return to main menu"; getch(); number_a(num); } //func 9999999999999999999999999999999999999999999999999999999999999999999999999 void del_nrecord(int num) { char *all , ss ; int num_rec = 0; long int a = 0 , co_num = 0 , n = 1 , co_num1 = 0, i , del_nu , cou_del = 0; all = new char[a]; clrscr(); cout<<"how many record do you want to dellete?\nplease type number."; //*********##############**************##############*********##############**** while(ss = cin.get() , ss != '!') { if(!((int)ss < 48 || (int)ss > 57 || ss == ' ')) { all[a] = ss; a++; } } sss: for(i = a-1; i >= 0; i--) { co_num = (((int)all[i]) - 48); co_num = co_num * n; co_num1 += co_num; n *= 10; } a = 0; n = 1; del_nu = co_num1; co_num = 0; co_num1 = 0; //*********##############**************##############*********##############**** ifstream as("bop/asd.txt"); if(!as) { clrscr(); cout<<"file not found. press any key to exit . . . ."; getch(); exit(0); } while(as.read((char *) &stu , sizeof(struct stmy))) num_rec++; as.close(); if(num_rec < del_nu) { clrscr(); cout<<"your entered number sould lower than number of records"; cout<<"\npress any key to return to main menu"; getch(); num = 0; number_a(num); } else { ifstream as1("bop/asd.txt"); ofstream te1("bop/tem.txt"); if(!as1 || !te1) { clrscr(); cout<<"file not found. press any key to exit . . . ."; getch(); exit(0); } while(as1.read((char *) &stu , sizeof(struct stmy))) { cou_del++; if(cou_del > del_nu) te1.write((char *) &stu , sizeof(struct stmy)); } as1.close(); te1.close(); remove("bop/asd.txt"); rename("bop/tem.txt" , "bop/asd.txt"); } clrscr(); cout<