در ادامه مطلب سورس های 8 وزیر - تلفن 118 - تبدیل مبنا و ... وجود داره که بیشتر برای پروژه های دانشجویی مفید هست می تونید اینها را در یک فایل تکست بریزید و پسوندش را به cpp. تغییر دهید
موفق باشید
منو
کد:
/* Menu Shower V 1.1
Compile with visual C++ 6
Programmer:Milad Kakoli(Kitten)
E-main:hellcrueldictator@yahoo.com
Weblog:www.kitten.mihanblog.com
yek code besyar sade baraye nemayesh yek menu sade ke omidvaram
dafa'at bad betonam ziba tar va karamad taresh konam.
in code ghabliat shenakht jahhat haye bala va paiine baraye
moshakhas kardan gozine entekhab shode ra darad va ba zadan enter
halghe payan yafte gozine entekhab shode moshakhas mishavad
baraye etela'at bishtar be weblog moraje'e konid.
*/
#include<iostream.h>
#include<string.h>
#include<stdio.h>
#include<conio.h>
#include <windows.h>
int ch; //braye gereftan jahat
int row=0; //moshakhas kardan satr fa'al
#define MAX 40 // bishtarin tedad char moton
char uptext[1][MAX]; // matne balaye menu
bool chi=true;
struct Student
**
int tedad; // tedad gozinehaye ghabel entekhab
char moton[5][MAX]; // moton gozinehaye ghabel entekhab
};Student s;
/*tabe menu ke moton menu ra print mikonad*/
int menu() **
cout<< uptext[0]<<endl;//print matne balaye menu
for (int i=0 ;i < s.tedad;i++)
**
if (i==row) **
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
}//taghiir rang baraye moshakhas kardan gozine fa'al
cout<< i+1 <<"-"<<s.moton[i]<<endl;
if (i==row) **
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
}//bargardandan rang be halat aval
}
return 0;//payan tabe
}
int main()**
s.tedad=5; // moshakhas kardan tedad gozineha
strcpy(s.moton[0],"Menu Viewer V 1.0");//kopy gozine aval
strcpy(s.moton[1],"hellcrueldictator@yahoo.com");//kopy gozine 2vom
strcpy(s.moton[2],"www.kitten.mihanblog.com");//kopy gozine 3vom
strcpy(s.moton[3],"Kitten");//kopy gozine 4om
strcpy(s.moton[4],"Movafagh bashid");//kopy gozine 5om
strcpy(uptext[0],"this is my menu");//kopy matn balaye menu
while(chi) **
gotoxy(0,0); // shoro az ebteda
menu(); // >>ejraye tabe menu
ch =getch(); //up=72,down=80, enter=13
switch(ch) **
case 72://up
if (row==0) **
row=s.tedad-1;
}//bargardandan be paiin
else **
row=row-1;
}//bargardandan be bala
break;
case 80://down
if(row==s.tedad-1) **
row=0;
}//bargardandan be bala
else **
row=row+1;
}//bargardandan be paiin
break;
case 13://enter
chi=false;//baraye khoroj az halghe
break;
}
}
/*baraye anjam karhaye badi
gozineye entekhab shode tavasot karbar row+1 ast */
return 0;
}
//shabih saz gotoxy
void gotoxy(int x,int y)
**
COORD pos;
HANDLE hConsole = GetStdHandle ( STD_OUTPUT_HANDLE );
if (INVALID_HANDLE_VALUE != hConsole)
**
pos.X = x;
pos.Y = y;
SetConsoleCursorPosition( hConsole, pos );
}
}__________________
متن را اخر هر سطر فایل بازشده اضافه میکنه
کد:
#include "stdafx.h"
#include<fstream>
using std::fstream;
#include<iostream>
#include<string.h>
char pass[33];
int n= 0;
int m = 0;
int y =0;
fstream m2("c:\\2.txt");
void neveshtan(char pass[32]) **
m2<<pass<<"matn\n";
}
int main() **
std::cout<<"tedad khotot?\n";
std::cin>>y;
fstream m1("c:\\1.txt");
for (int x = 1; x<=y;x++) **
m1.getline(pass,32);
std::cout << pass << "\n";
neveshtan(pass);
_strset(pass,NULL);
}
return 0;
}__________________
ز فایل 1.txt می خونه و ان سطرهایی که دقیقا مثل هم هستند را پاک میکنه تا متن های اضافی پاک بشه و فایلی که سطر تکراری نداره را به عنوان 2.txt ذخیره می کنه
کد:
#include<iostream>
using std::cin;
using std::cout;
using std::endl;
#include<fstream>
using std::fstream;
#include<string.h>
int khat;
char id[33];
int natije;
char checkid[33];
int cmp;
char getid[33];
int check(char checkid[33]) **
fstream m3("c:\\2.txt");
for (int j = 1; j <=khat;j++) **
m3.getline(getid,32);
cmp = strcmp(checkid,getid);
if (cmp == 0) **
cout<<checkid<<endl;
return 0;
}
}
return cmp;
}
int main () **
fstream m2("c:\\2.txt");
cout<<"tedad khotot?\n";
cin >> khat;
fstream m1("c:\\1.txt");
for (int i = 1; i<=khat;i++) **
m1.getline(id,32);
natije = check(id);
if (natije == 0) **
continue;
}
else **
m2<<id<<endl;
}
}
return 0;
}__________________
عبارتهای جبری در c
این برنامه عبارتهای جبری را می گیرد و نتیجه را نمایش می دهد:
برای مثال عبارات زیر را وارد کنید و نتیجه را ببینید
کد:
A*B/C-(D+F+G*(A-V)-D)
A+B*C
V-C+(((C*B-R)-E*F)/K-R+D^E)%Nو یا هر عبارت دیگری
شاید نصف روز و یا بیشتر می نوشتمش
نکاتی در مورد برنامه
1- فاصله در بین عبارت مجاز نمی باشد
2- استفاده از 2 حرف بین یک عملگر مجاز نمی باشد
3- نمی توان عدد وارد کرد و باید حتماً حرف وارد کرد و وقتی حرف وارد کنیم معادل عددی آن را می گیرد
4- ورودی آن تا 100 کاراکتر می باشد که می توان آن را در برنامه بیشتر کرد.
5- پرانتز باز شده حتماً باید بسته شود
6- در این برنامه از پشته استفاده شده و آن هم با لیست پیوندی
7- امیدوارم مورد استفاده دوستان قرار بگیرد
8- اگر نیاز به الگوریتم آن دارید و یا توضیحاتی راجع به آن می خواهید خبرم کنید
با تشکر
کد:
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <conio.h>
#include <string.h>
//************************** stack ****************************************
struct stack
**
char info;
stack *link;
}*ss;
//************************** stack ****************************************
struct stack2
**
long info;
stack2 *link;
}*ss2;
//************************** num ***************************************
struct number
**
long value;
char chr;
number *link;
}*ns;
//************************** check num **********************************
long checknum(char chr)
**
number *ptr;
ptr = ns;
while ( ptr != NULL)
**
if ( ptr->chr == chr) return ptr->value;
ptr = ptr->link;
}
return 0;
}
//************************** insert num **********************************
void insertnum(long value, char chr)
**
number *ptr;
ptr = (number*) malloc(sizeof(number));
ptr->link = ns;
ptr->chr = chr;
ptr->value = value;
ns = ptr;
}
//************************** push ***************************************
void push(char item)
**
stack *ptr;
ptr = (stack*) malloc(sizeof(stack));
ptr->info = item;
ptr->link = ss;
ss = ptr;
}
//************************** pop ****************************************
char pop()
**
stack *ptr;
ptr = ss;
char temp;
temp = ss->info;
ss = ss->link;
free(ptr);
return temp;
}
//************************** push ***************************************
void push2(long item)
**
stack2 *ptr;
ptr = (stack2*) malloc(sizeof(stack2));
ptr->info = item;
ptr->link = ss2;
ss2 = ptr;
}
//************************** pop ****************************************
long pop2()
**
stack2 *ptr;
ptr = ss2;
long temp;
temp = ss2->info;
ss2 = ss2->link;
free(ptr);
return temp;
}
//************************** mid ****************************************
char mid ( char source[] , int position , int count , char destination[])
**
int qcount = 0 , len ;
len = strlen(source);
for ( int i = position - 1 ; i < position + count - 1 && i < len ; i++ , qcount++)
destination[qcount] = source[i];
destination[qcount] = 0;
if ( qcount == 1) return destination[0];
else return 0;
}
//************************** priority **************************************
int priority(char a , char b)
**
if ( a == '^') return 1;
if ( b == '^') return 0;
if ( a == '*' || a == '/' || a == '%' ) return 1;
if ( b == '*' || b == '/' || b == '%' ) return 0;
return 1;
}
//************************** pulish ****************************************
void pulish(char source[] , char dest[] , int len)
**
char temp , temp2[2];
int count = 0;
for ( int i = 0 ; i < len ; i++)
**
temp = mid(source , i + 1 , 1 , temp2);
switch (temp)
**
case '+':
case '-':
case '*':
case '/':
case '^':
case '%':
if (ss->info == '(' || priority(ss->info , temp) == 0 ) push (temp);
else
**
while (ss ->info != '(' && priority(ss->info , temp))
dest[count++] = pop();
push(temp);
}
break;
case '(':
push(temp);
break;
case ')':
while ( ss->info != '(')
dest[count++] = pop();
pop();
break;
default :
if ( temp >= 48 && temp <= 122)
dest[count++] = temp;
}
}
dest[count] = 0;
}
//************************** value ****************************************
long value(char source[] , int len)
**
char temp , temp2[2] ;
long a , b, result;
for ( int i = 0 ; i < len ; i++)
**
temp = mid ( source , i + 1 , 1 , temp2);
if ( temp >= 48 && temp <= 122)
**
a = checknum(temp);
if ( a == 0 )
**
printf("Please Enter %c =" , temp);
scanf("%u" ,&a);
insertnum(a , temp);
push2(a);
}
else push2(a);
}
else
**
b = pop2();
a = pop2();
switch (temp)
**
case '+':
result = a + b;
push2 (result);
break;
case '-':
result = a - b;
push2 (result);
break;
case '*':
result = a * b;
push2 (result);
break;
case '/':
result = a / b;
push2 (result);
break;
case '^':
result = pow(a,b);
push2 (result);
break;
case '%':
result = a % b;
push2 (result);
break;
}
}
}
return pop2();
}
//************************** main ****************************************
int main()
**
char p[102] , q[100];
clrscr();
int len;
scanf("%s" , p);
len = strlen(p);
for ( int i = len ; i > 0 ; i--)
p[i] = p[i-1];
p[0] = '(';
p[len + 1] = ')';
len +=2;
p[len] = 0;
pulish ( p , q , len);
len = strlen(q);
printf("\n%u\n" , value ( q , len));
getch();
return 0;
}__________________
برنامه کاربردی برای آموزش استفاده از فایل و Structها
کد:
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <ctype.h>
#include <string.h>
struct address **
char name[30] ;
char street[30] ;
char city[20] ;
char state[3] ;
char zip[10] ;
struct address *next ;
struct address *prior ;
} list_entry ;
struct address *start ;
struct address *last ;
void enter() , display() , search() ;
void save() , load() , list() , del();
void display(struct address *info, int *row);
struct address *find(char *);
int menu_select();
struct address *store(struct address *, struct address *);
int main ()
**
start = last = NULL ;
for(;;) **
switch(menu_select()) **
case 1: enter(); break ;
case 2 : del(); break ;
case 3: list() ; break ;
case 4: search(); break ;
case 5: save(); break ;
case 6: load(); break ;
case 7: exit(0) ;
}//end of switch
}//end of for
}//end of main
//****************
int menu_select()
**
char s[5];
clrscr() ;
gotoxy(25, 4) ;
printf("1. enter a name ") ;
gotoxy(25, 6) ;
printf("2. delete a name ") ;
gotoxy(25, 8) ;
printf("3. list all files ") ;
gotoxy(25, 10) ;
printf("4. search ") ;
gotoxy(25, 12) ;
printf("5. save the file ") ;
gotoxy(25, 14) ;
printf("6. load the file ") ;
gotoxy(25, 16) ;
printf("7. quit ") ;
do **
gotoxy(20, 18) ;
printf("enter your select--www.gach18.blogfa.ir(1-7):");
gets(s);
} while (atoi(s) < 0 || atoi(s) > 7) ;
return atoi(s) ;
}
//*********************
void enter ()
**
struct address *info ;
int i ;
char ch ;
clrscr() ;
gotoxy(3, 2) ;
printf(" name street city state zip");
gotoxy(3, 3) ;
printf(" ------------ -------- ");
printf("-------- ----- ------- ");
i = 4 ;
for (;;) **
info = (struct address *)malloc(sizeof(list_entry)) ;
if(!info) **
printf("\n out of memory. press a key ") ;
getch();
return ;
}
gotoxy(3, i) ;
gets(info -> name) ;
if (!info -> name[0]) **
gotoxy(15, i + 1) ;
printf("press a key to continue");
getch() ;
break ;
}//end of if
gotoxy(18, i);
gets(info -> street) ;
gotoxy(28, i) ;
gets(info -> city) ;
gotoxy(38, i) ;
gets(info -> state) ;
gotoxy(45, i) ;
gets(info -> zip) ;
i++ ;
start = store(info, start) ;
} /* entry loop */
}
//**************
struct address *store(struct address *i, struct address *top)
**
struct address *old, *p ;
if(last == NULL) **
i -> next = NULL ;
i -> prior = NULL ;
start = i;
last = i ;
return i ;
}
p = top ;
old = NULL ;
while (p != NULL) **
if(strcmp(p -> name, i -> name) < 0) **
old = p ;
p = p -> next ;
}//end of if
else **
if (p -> prior) **
p -> prior -> next=i ;
i -> next=p ;
i -> prior=p -> prior;
p -> prior=i ;
return top ;
}//end of if
i -> next = p ;
i -> prior = NULL ;
p -> prior = i ;
return i ;
}//end of if
} // end of while
old -> next = i ;
i -> next = NULL ;
i -> prior = old ;
last = i ;
return start ;
}
//******************
void del()
**
struct address *info;
char name[80];
gotoxy(20, 20) ;
printf(" enter name for delete : ") ;
gets(name) ;
info = find(name) ;
if(info == NULL) **
gotoxy(10, 20) ;
printf(" name not found! press a key to continue.");
getch() ;
}
if (info)
if (start == info)
**
start = info -> next ;
if(start)
start -> prior = NULL ;
else
last = NULL ;
} //end of if
else **
info -> prior -> next = info -> next;
if(info != last)
info -> next -> prior = info -> prior;
else
last = info -> prior ;
} //end of else
free(info) ;
gotoxy(10,20) ;
printf("name deleted, press a key to continue.");
getch() ;
}
//*******************************
struct address *find(char *name)
**
struct address *info ;
info = start ;
while(info != NULL) **
if (strcmp(name, info -> name) == 0)
return info;
info = info -> next ;
}
return NULL ;
}
//*****************
void list ()
**
struct address *info ;
int i ;
info = start ;
clrscr() ;
gotoxy(3, 2) ;
printf(" name street city state zip");
gotoxy(3, 3) ;
printf(" ------------ -------- -");
printf("------- ----- ------- ");
i = 4 ;
while(info != NULL) **
display(info, &i) ;
info = info -> next ;
}
gotoxy(15, i + 2) ;
printf("press a key to continue.");
getch() ;
}
//*******************
void display(struct address *info, int *row)
**
gotoxy(3, *row) ;
printf("%s", info -> name) ;
gotoxy(18, *row) ;
printf("%s", info -> street) ;
gotoxy(28, *row) ;
printf("%s", info -> city) ;
gotoxy(38, *row) ;
printf(info -> state) ;
gotoxy(47, *row) ;
printf(info -> zip) ;
*row = *row + 1 ;
}
//**************************
void search()
**
char name[40] ;
int i ;
struct address *info;
gotoxy(20, 20) ;
printf(" enter name to find : ");
gets(name) ;
info = find(name) ;
if(info == NULL) **
gotoxy(10, 20) ;
printf(" name not found! press a key to continue.");
getch() ;
}//end of if
else **
clrscr() ;
gotoxy(3, 2) ;
printf(" name street city state zip");
gotoxy(3, 3) ;
printf(" ------------ -------");
printf("- -------- ----- ------- ") ;
i = 4 ;
display(info ,&i) ;
gotoxy(15, i + 2) ;
printf("press a key to continue.");
getch() ;
}//end of else
}
//*********************
void save()
**
struct address *info ;
FILE *fp ;
if((fp = fopen("l.dat","wb")) == NULL) **
printf("\n cannot open file. ") ;
getch();
exit(1) ;
}//end of if
gotoxy(20, 20) ;
printf("<< saving file >>") ;
info = start ;
while(info) **
fwrite(info, sizeof(struct address), 1, fp);
info = info -> next ;
}//end of while
fclose(fp) ;
gotoxy(15, 22) ;
printf("file successfuly saved press a key...") ;
getch() ;
}
//********************
void load ()
**
struct address *info , *temp = NULL;
FILE *fp ;
fp = fopen("l.dat","rb") ;
if(fp == NULL) **
printf("\n cannot open file.");
getch();
exit(1) ;
}
while(start) **
info = start -> next ;
free(info) ;
start = info ;
}
gotoxy(20,20) ;
printf(" << loading file >> ") ;
start = NULL ;
while (!feof(fp)) **
info = (struct address *)
malloc(sizeof(struct address)) ;
if(1 != fread(info, sizeof(struct address), 1, fp))
break ;
if(start == NULL) **
temp = start = info ;
info -> prior = NULL ;
info -> next = NULL ;
}//end of if
else **
info -> next = NULL ;
temp -> next = info ;
info -> prior = temp ;
temp = info;
}
}//end of while
last = temp ;
fclose(fp) ;
gotoxy(15,22) ;
printf("file successfuly loaded press a key ...") ;
getch();
}
---------------------------------------------------------------------------__________________
تغییر رنگ نوشته متن :
کامپایلر : Borland C++ 5.02
روش اول :
کد:
#include <iostream>
#include <conio>
int main()**
for(int i=1;i<=4;i++)**
textcolor(i+8);
cprintf("Welcome to C++ World");
cout<<endl;}
getch();
}روش دوم :
کد:
#include <iostream>
#include <conio>
#include <stdlib>
int main()**
for(int i=1;i<=4;i++)**
system("color 0A");
cout<<"Welcome to C++ World\n";
}
getch();
}__________________
دفتر تلفن ساده با کلاس ها
مناسب برای دانشجویان
کد:
#include <iostream.h>
#include <conio.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
//=====================================
//=====================================
struct address **
char name[30] ;
char street[30] ;
char city[20] ;
char state[3] ;
char number[14] ;
struct address *next ;
struct address *prior ;
} list_entry ;
//=====================================
//=====================================
struct address *start ;
struct address *last ;
void enter() , display() , search() ;
void list() , del();
void display(struct address *info, int *row);
struct address *find(char *);
int menu_select();
struct address *store(struct address *, struct address *);
//=====================================
//=====================================
//****************
int menu_select()
**
char s[5];
system("cls");
gotoxy(25,4) ;
printf("1. enter a name ") ;
gotoxy(25,6) ;
printf("2. delete a name ") ;
gotoxy(25, 8) ;
printf("3. list all files ") ;
gotoxy(25, 10) ;
printf("4. search ") ;
gotoxy(25, 12) ;
printf("5. quit ") ;
do **
gotoxy(20, 18) ;
printf("enter your select--power By majid (1-5):");
gets(s);
} while (atoi(s) < 0 || atoi(s) > 5) ;
return atoi(s) ;
}
//*********************
void enter ()
**
struct address *info ;
int i ;
char ch ;
system("cls") ;
gotoxy(3, 2) ;
printf(" name street city state number");
gotoxy(3, 3) ;
printf(" ------------ -------- ");
printf("-------- ----- ------- ");
i = 4 ;
for (;;) **
info = (struct address *)malloc(sizeof(list_entry)) ;
if(!info) **
printf("\n out of memory. press a key ") ;
getch();
return ;
}
gotoxy(3, i) ;
gets(info -> name) ;
if (!info -> name[0]) **
gotoxy(15, i + 1) ;
printf("press a key to continue");
getch() ;
break ;
}//end of if
gotoxy(18, i);
gets(info -> street) ;
gotoxy(28, i) ;
gets(info -> city) ;
gotoxy(38, i) ;
gets(info -> state) ;
gotoxy(45, i) ;
gets(info -> number) ;
i++ ;
start = store(info, start) ;
} /* entry loop */
}
//**************
struct address *store(struct address *i, struct address *top)
**
struct address *old, *p ;
if(last == NULL) **
i -> next = NULL ;
i -> prior = NULL ;
start = i;
last = i ;
return i ;
}
p = top ;
old = NULL ;
while (p != NULL) **
if(strcmp(p -> name, i -> name) < 0) **
old = p ;
p = p -> next ;
}//end of if
else **
if (p -> prior) **
p -> prior -> next=i ;
i -> next=p ;
i -> prior=p -> prior;
p -> prior=i ;
return top ;
}//end of if
i -> next = p ;
i -> prior = NULL ;
p -> prior = i ;
return i ;
}//end of if
} // end of while
old -> next = i ;
i -> next = NULL ;
i -> prior = old ;
last = i ;
return start ;
}
//******************
void del()
**
struct address *info;
char name[80];
gotoxy(20, 20) ;
printf(" enter name for delete : ") ;
gets(name) ;
info = find(name) ;
if(info == NULL) **
gotoxy(10, 20) ;
printf(" name not found! press a key to continue.");
getch() ;
}
if (info)
if (start == info)
**
start = info -> next ;
if(start)
start -> prior = NULL ;
else
last = NULL ;
} //end of if
else **
info -> prior -> next = info -> next;
if(info != last)
info -> next -> prior = info -> prior;
else
last = info -> prior ;
} //end of else
free(info) ;
gotoxy(10,20) ;
printf("name deleted, press a key to continue.");
getch() ;
}
//*******************************
struct address *find(char *name)
**
struct address *info ;
info = start ;
while(info != NULL) **
if (strcmp(name, info -> name) == 0)
return info;
info = info -> next ;
}
return NULL ;
}
//*****************
void list ()
**
struct address *info ;
int i ;
info = start ;
system("cls") ;
gotoxy(3, 2) ;
printf(" name street city state number");
gotoxy(3, 3) ;
printf(" ------------ -------- -");
printf("------- ----- ------- ");
i = 4 ;
while(info != NULL) **
display(info, &i) ;
info = info -> next ;
}
gotoxy(15, i + 2) ;
printf("press a key to continue.");
getch() ;
}
//*******************
void display(struct address *info, int *row)
**
gotoxy(3, *row) ;
printf("%s", info -> name) ;
gotoxy(18, *row) ;
printf("%s", info -> street) ;
gotoxy(28, *row) ;
printf("%s", info -> city) ;
gotoxy(38, *row) ;
printf(info -> state) ;
gotoxy(47, *row) ;
printf(info -> number) ;
*row = *row + 1 ;
}
//**************************
void search()
**
char name[40] ;
int i ;
struct address *info;
gotoxy(20, 20) ;
printf(" enter name to find : ");
gets(name) ;
info = find(name) ;
if(info == NULL) **
gotoxy(10, 20) ;
printf(" name not found! press a key to continue.");
getch() ;
}//end of if
else **
system("cls") ;
gotoxy(3, 2) ;
printf(" name street city state number");
gotoxy(3, 3) ;
printf(" ------------ -------");
printf("- -------- ----- ------- ") ;
i = 4 ;
display(info ,&i) ;
gotoxy(15, i + 2) ;
printf("press a key to continue.");
getch() ;
}//end of else
}
//*********************
int main()
**
start = last = NULL ;
for(;;) **
switch(menu_select()) **
case 1: enter(); break ;
case 2 : del(); break ;
case 3: list() ; break ;
case 4: search(); break ;
case 5: exit(0) ;
}//end of switch
}//end of for
}//end of main__________________
کتابخانه با امکان ورود - ویرایش- حذف -به امانت گرفتن و پس دادن کتاب
کد:
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
//===========================
//===========================
class book
**
friend class library;
private:
char book_name[11];
char explain[51];
char aouther[11];
char part;
char user[11];
int reserved;
book *next;
public:
book();
void edit();
void reserv();
void getback();
}
//---------------------------
book::book()
**
clrscr();
cout<<"============ add a new book =================="
<<"\n\nto insert new book ,enter flow informations:"
<<"\n\nbook name?";
gets(book_name);
book_name[10]=NULL;
cout<<"\naouther name?";
gets(aouther);
aouther[10]=NULL;
cout<<"\nany explain?";
gets(explain);
explain[50]=NULL;
part=book_name[0];
reserved=0;
next=NULL;
cout<<"\n\ninformathions set!";
getch();
}
//---------------------------
void book::edit()
**
cout<<"error ";
}
//---------------------------
void book::reserv()
**
clrscr();
cout<<"\n=========== reserving book ===================";
if(reserved==0)
**
cout<<"\n\nuser name?";
gets(user);
user[11]=NULL;
reserved=1;
}
if(reserved==0)
**
cout<<"\n\nsorry! book has been reserved befor"
<<"by user:";
puts(user);
}
getch();
}
//---------------------------
void book::getback()
**
reserved=0;
cout<<"\n\nbook got bak.";
getch();
}
//===========================
//===========================
class library
**
public:
library();
void run_menu();
private:
book *parts[24];
void insert(book*);
void find();
void search();
}
//---------------------------
library::library()
**
for(int i=0;i<=23;i++)
parts[i]=NULL;
}
//---------------------------
void library::run_menu()
**
char ch='n';
while(ch!='4')
**
clrscr();
cout<<"================= LIBRARY =================="
<<"\n\n1:add a new book."
<<"\n2:find a book."
<<"\n3:search a book."
<<"\n4:exit."
<<"press numbers:";
ch=getch();
if(ch=='1')
**
book *n=new book;
insert(n);
}
if(ch=='2')
**
find();
}
if(ch=='3')
**
search();
}
}//while
}
//---------------------------
void library::insert(book *s)
**
int d=s->part-97;
if(parts[d]==NULL)
**
parts[d]=s;
}
else
**
book *p=parts[d],*q;
while(p!=NULL && strcmp(p->book_name,s->book_name)<0)
**
q=p;
p=p->next;
}
q->next=s;
s->next=p;
}
}
//---------------------------
void library::find()
**
clrscr();
cout<<"=========== edit / delete books ============"
<<"\nenter exact book name:";
char name[11];
gets(name);
name[11]=NULL;
int d=name[0]-97;
book *p=parts[d],*q;
while(p!=NULL && strcmp(p->book_name,name)!=0)
**
q=p;
p=p->next;
}
if(p==NULL)
**
cout<<"not found!";
}
if(p!=NULL)
**
cout<<"\n\ndelete it?('d') or edit?('e')"
<<" or reserv?('r') or getback?('g') :";
char ch=getch();
if(ch=='d')
**
q->next=p->next;
delete p;
}
if(ch=='e')
**
p->edit();
}
if(ch=='r')
**
p->reserv();
}
if(ch=='g')
**
p->getback();
}
}
getch();
}
//---------------------------
void library::search()
**
char ch='6';
while(ch!='4')
**
clrscr();
cout<<"================== SEARCH ===================";
cout<<"\n\n1:search for name."
<<"\n2:search for aouther."
<<"\n3:search for explanations."
<<"\n4:back to main menu.(press numbers)";
ch=getch();
if(ch=='1')
**
cout<<"\n\nenter exact name:";
char name[10];
gets(name);
name[11]=NULL;
int d=name[0]-97;
book *p=parts[d];
while(p!=NULL && strcmp(p->book_name,name)!=0)
**
p=p->next;
}
if(p==NULL)
**
cout<<"\nnot founded!";
}
else
**
cout<<"\n\n";
cout<<"name:";puts(p->book_name);
cout<<"aouther:";puts(p->aouther);
cout<<"explain:";puts(p->explain);
if(p->reserved==1)
**
cout<<"RESERVED by:";
puts(p->user);
}
else
**
cout<<"NOT RESERVES";
}
}//else
getch();
}//1
if(ch=='2')
**
cout<<"\n\nenter exact aouther name:";
char name[11];
gets(name);
name[11]=NULL;
int f=0;
for(int i=0;i<=23;i++)
**
book *p=parts[i];
while(p!=NULL)
**
if(strcmp(p->aouther,name)==0)
**
f++;
cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"aouthor:";puts(p->aouther);
cout<<"explain:";puts(p->explain);
if(p->reserved==1)
**
cout<<"RESERVED BY";
puts(p->user);
}
else
**
cout<<"NOT RESERVED";
}
}
p=p->next;
}//while
}
getch();
}//2
if(ch=='3')
**
cout<<"\n\nenter key(15char):";
char name[16];
gets(name);
name[15]=NULL;
int f=0;
for(int i=0;i<=23;i++)
**
book *p=parts[i];
while(p!=NULL)
**
char *tokenptr;
tokenptr=strtok(p->explain," ");
while(tokenptr!=NULL)
**
if(strcmp(tokenptr,name)==0)
**
f++;
cout<<"\n"<<f<<":";
cout<<"name:";puts(p->book_name);
cout<<"aouthor:";puts(p->aouther);
cout<<"explain:";puts(p->explain);
if(p->reserved==1)
**
cout<<"RESERVED BY";
puts(p->user);
}
else
**
cout<<"NOT RESERVED";
}
}
tokenptr=strtok(NULL," ");
}
p=p->next;
}//while
}//for i
getch();
}//3
}
}
//===========================
//===========================
int main()
**
clrscr();
library l1;
l1.run_menu();
return(0);
}__________________
سلام به همه دوستان عزیز
چند مثال و دستور :
ب م م (و ک م م) بازگشتی
کد:
include
#include
int m(int,int);
int main()
**
clrscr();
int x,y,z;
cin>>x>>y;
z=m(x,y);
cout<<"BMM: "<<<<"KMM: "<<(x*y)/z;
getch();
return 0;
}
int m(int a,int b)
**
if(a
else if(b==0)return a;
else return m(b,a%b);
}__________________
--------------------------------------------------------------------------------
کد کردن نوشته و دکد کردن آن (کد اسکی)
کد:
#include
#include
void ch(void);
void co(void);
void F(void);
char b;
int a;
void main()**
F();
char q;
cout<<"\n Character to Code? (y/invert) ";
cin>>q;
if(q=='y') ch();
else co();
getch();
}
//functions
void co(void)**
while(1)**
cin>>a;
b=a;
cout<
} }
void ch(void)**
while(1)**
cin>>b;
a=b;
cout<<<'\t';
}}
void F(void)**
char F[11]=**-87,65,76,73,82,69,90,65,46,72};
cout<
}__________________
تجزیه به عامل های اول
کد:
#include
#include
void main()
**
long n;
cin >> n;
clrscr();
for(int i = 2;i <= n;)
if((n%i) == 0)
**
cout << n << "\t" << i << endl;
n/=i;
}
else i++;
cout << n << endl;
} توسط:ALiReza.H MobHam__________________
اعداد اول
کد:
#include
#include
int main()
**
int x,r,s,i;
clrscr();
cin>>x;
for(x=1;x<5;x++)
**
i=2;
s=0;
while(i<(x/2) && s==0)
**
r=x%i;
i++;
if(r==0) s=1;
}
if(s==0)
cout<<
else
cout<<"no prime="<
}
getch();
return 0;
}__________________
یک برنامه 118 ساده
کد:
#include
#include
#include
#include
void insert ();
void search ();
void del(void);
void list(void);
//******************************************************************//
struct **
char name[20];
char lastname[20];
char phone[15];
char address[50];
}tel[100];
//******************************************************************//
void main()
**
int key;
textcolor(12);
textbackground(0);
clrscr();
printf("\n\n\t Inormation of Phone Number [118] !\n\n");
printf("\n\n\t Welcome to my program !\n\n");
printf("\n\n\t Program Writen By Hamid Abedi !\n\n");
gotoxy(25,44);
printf("Press any key to exit!");
getch();
textcolor(10);
textbackground(8);
clrscr();
printf("\t Please select and choice number !\n\n");
printf("\t1.Insert In the list !\n\n");
printf("\t2.Search In the list !\n\n");
printf("\t3.View all of the list !\n\n");
printf("\t4.Exit !\n\n=>");
scanf("%d",&key);
while(key!=4)** switch(key)**
case 1:
insert(); break;
case 2:
search();break;
case 3:
list();break;
default:
printf("\n\nBad command !!");
}
textcolor(12);
textbackground(8);
clrscr();
printf("\r Press any key to select !\n\n");
printf("\r 1.Insert In the list !\n\n");
printf("\r 2.Search In the list !\n\n");
printf("\r 3.View all of the list !\n\n");
printf("\r 4.Exit !\n\n=>");
scanf("%d",&key);
}
}
//******************************************************************//
void insert ()
**
int i=0;
FILE *telph;
textbackground(1);
textcolor(14);
clrscr();
telph=fopen("tel.txt","a");
if(telph==NULL){puts("Can not open the file");return;}
puts("\n Enter 'end' to exit"
"\n--------------------");
printf("\nName :");
scanf("%s",tel[i].name);
while(strcmp(tel[i].name,"end"))
**
printf("\nLast Name :");
scanf("%s",tel[i].lastname);
printf("\nPhone Number :");
scanf("%s",tel[i].phone);
printf("\nAddress :");
scanf("%s",tel[i].address);
fwrite(&tel,sizeof tel[i],1,telph);
printf("\nName :");
i++;
scanf("%s",tel[i].name);
}
fclose(telph);
gotoxy(25,44);
printf("Press any key to exit!");
getch();
}
//*****************************************************************//
void list(void)
**
int i=0;
FILE *telph;
textbackground(15);
textcolor(1);
clrscr();
telph=fopen("tel.txt","a+t");
if(telph==NULL){puts("Can not open the file");return;}
puts("\n LastName Name Number Address"
"\n-----------------------------------------------------------------------\n");
while(fread(&tel,sizeof tel[i],1,telph))
**
printf(" %-15s %-15s %-15s %-15s \n",tel[i].lastname,tel[i].name,tel[i].phone,tel[i].address);
}
gotoxy(25,44);
printf("Press any key to exit!");
getch();
}
//*********************************************************************//
void search (void)
**
int i=0;
char nam[50];
FILE *telph;
textbackground(15);
textcolor(4);
clrscr();
telph=fopen("tel.txt","a+t");
if(telph==NULL){puts("Can not open the file");return;}
printf("\n ** Welcom To Phone Information **\n");
printf("\n ** Please enter the family for searching:>!\n");
scanf("%s",nam);
printf("\n Last Name Name Phone No Address ");
printf("\n ححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححححح");
while(fread(&tel[i],sizeof tel[i],1,telph))
**
if(strcmp(tel[i].lastname,nam)==0)
printf("\n %-10s %-10s %-10s %-10s \n",tel[i].lastname,tel[i].name,tel[i].phone,tel[i].address);
i++;
}
gotoxy(25,44);
printf("Press any key to exit!");
getch();
}
/*******************************************************************/__________________
حل معادله نیوتن رافسون
کد:
#include
#include
#include
void main(void)
**
float h,x1,f,f1,g,a,b,x;
int i,conter;
top: clrscr();
printf(" \n******************************in file**************************");
printf("\ninput [a,b]");
printf("\ninput a=");
scanf("\n%f",&a);
printf("input b=");
scanf("\n%f",&b);
printf("\nbaseh f(x)=> [%f,%f]",a,b);
x=a;
/**************** f(x) ****************/
f=x*pow(2,x)-1;
g=x*x*2;
/*******************************************/
printf("\nf(a)=%f",f);
x=b;
/***************** f(x) ***************/
f1=x*pow(2,x)-1;
/*******************************************/
printf("\nf(b)=%f",f1);
if ((f1*f)<0)
printf("\nIF ONE TRUE");
else
**
printf("\n IF ONE FALSE --F(a)F(B)<0--");
goto top;
}
//****************************************************************
printf("\ninput x1:=");
scanf("%f",&x1);
printf("\nnumber repeter :=");
scanf("%d",&conter);
printf("\n************************out file****************************");
for(i=1;i<=conter;i++)
**
h=x1-(f/g);
printf("\n%f ",h);
x1=h;
}
getch();
}با تشکر فراوان از اقای فرهانی بخاطر مطالب عالی شون
__________________
دنباله ی فیبوناچی
کد:
#include<stdio.h>
#include<conio.h>
int fibonachi(int n);
void main() **
int number;
clrscr();
scanf("%d",&number);
printf("\n%d",fibonachi(number));
getch();
}
int fibonachi(int n) **
static int pre; // this varibale save value of the fibonachi(n-2)
int tmp1; // tmp1 temporary value of the fibonachi(n-1)
int tmp2; // tmp2 temporary value of the fibonachi(n-2)
if (n=<0) return 0;
if (n==1) **
pre = 1;
return 1;
}
tmp1 = fibonachi(n-1);
tmp2 = pre;
pre = tmp1; // tmp1 is the fibonachi(n-2) at upper level
return tmp1 + tmp2;
}__________________
مقایسه ی اعداد فیبوناچی
کد:
#include<stdio.h>
#include<conio.h>
#include<time.h>
long double f( long double i);
long int fibonachi(int n);
long int fibo(long int,long int a=3,long int b=1,long int c=1);
void main() **
int number;
time_t t1,t2;
clrscr();
printf("please wait");
t1 = time(NULL);
for (int k=0;k<1000;k++)
for (int j=0;j<1000;j++)
for (int i=0;i<40;i++)
**
f(i);
}
t2 = time(NULL);
printf("\n%ld",t2-t1);
t1 = time(NULL);
for (k=0;k<1000;k++)
for (j=0;j<1000;j++)
for (i=0;i<40;i++)
**
fibonachi(i);
}
t2 = time(NULL);
printf("\n%ld",t2-t1);
t1 = time(NULL);
for (k=0;k<1000;k++)
for (j=0;j<1000;j++)
for (i=0;i<40;i++)
**
fibo(i);
}
t2 = time(NULL);
printf("\n%ld",t2-t1);
printf("\npress any key...");
getch();
}
long double f( long double i)**
static long double oldf[6]; //buffer for old value
static long double oldn[6]; //buffer for old number
static long cntm=0;
long double lngTmp;
long double lngTmp2;
long fd;
//if our number reaches zero then our functions returns nothing
if (i<=0) return 0;
//if our number equal 1 or 2 then our function return 1
if (i==1 || i==2) return 1;
// Check our number exist in our array or not?
// if exist find function value index from our array index
fd=-1; // set Parameter value to detected found index or not
// now check to found if value has last returned value
for(int y=0;y<=5 && y-1<=cntm;y++)
if (oldn[y]==i)**
fd=y;
y=6;}
// if the number is new one so call function again
// for calculating new value
if (fd==-1)**
lngTmp=f(i-2)+f(i-1);
// our buffer just store 5 last returaned value and number
// so we check if our buffer is empty or not
// if emtpy new value and number added to end of buffer
// if not. we role buffer to down to free last buffer
// so we do not need so many memory for buffering all value and #
if (cntm>=5)**
oldf[cntm]=lngTmp; //store this value for latter usage
oldn[cntm]=i; //store this number for latter usage
cntm++; // one added to our array counter.
}else{
// free last buffer index for add new value
for(y=0;y<=4;y++)**
oldf[y]=oldf[y+1];
oldn[y]=oldn[y+1];}
oldf[y]=lngTmp;
oldn[y]=i;
}
}else lngTmp=oldf[fd]; //we have this value so set it!
return lngTmp; // finished new number calculating send back this value
}
long int fibonachi(int n) **
static long int pre; // this varibale save value of the fibonachi(n-2)
long int tmp1; // tmp1 temporary value of the fibonachi(n-1)
long int tmp2; // tmp2 temporary value of the fibonachi(n-2)
if (n<=0) return 0;
if (n==1 || n==2) **
pre = 1;
return 1;
}
tmp1 = fibonachi(n-1);
tmp2 = pre;
pre = tmp1; // tmp1 is the fibonachi(n-2) at upper level
return tmp1 + tmp2;
}
long int fibo(long int x, //user number
long int n, //curent number
long int p1, //fibo(n-1)
long int p2) //fibo(n-1)
**
if(x<=0) //if number is negative
return 0;
if(x==1 || x==2) //fibo(1)=fibo(2)=0
return 1;
if(x==n) //fibo(n)=fibo(n-1)+fibo(n-2)
return p1+p2;
//if x!=n then find fibo(n+1) and return its value
return fibo(x, //final number
n+1, //next nuuber
p1+p2, //fibo(n)
p1 //fibo(n-1)
);
}خروجی
کد:
please wait
52
19
21
press any key...__________________
شون دادن اعداد بالای 10 به صورت کاراکتری :
کد:
#include<iostream.h>
#include<conio.h>
int chrtoint(char c)
**
if((c>='a')&&(c<='f'))
return c-87;
else if((c>='A')&&(c<='F'))
return c-55;
else if((c>='0')&&(c<='9'))
return c-48;
else
return -1;
}
void ten_to(long int x,int base)
**
int m,n=0;
long int save=x;
while(x>0)
**
x=x/base;
n++;
}//end of while
m=n;
x=save;
cout<<"\n Answer => ";
for(int i=1;i<=m;i++)
**
for(int j=1;j<=n-1;j++)
x=x/base;
if((x%base)>=10)
cout<<(char)((x%base)+55);
else
cout<<x%base;
n--;
x=save;
}//end of for
}
//------ Main -----
int main()
**
char a;
long int x=0;
int sb,db;
clrscr();
cout<<"Enter source base: ";
cin>>sb;
if((sb<=1)||(sb>=17))
**
cout<<"### Error : Base must be beetween 2 , 16 .";
getch();
return 0;
}
cout<<"Enter number: ";
while((a=getch()) != 13)
**
if((chrtoint(a) < sb) && (chrtoint(a) != -1))
**
cout<<a;
x=x*sb+chrtoint(a);
}
}//end of while
cout<<"\nEnter destination base: ";
cin>>db;
ten_to(x,db);
getch();
return 0;
}__________________
برنامه ی معروف 8 وزیر :
کد:
#include<stdio.h>
#include<conio.h>
void shat3(int x,int y,int nx,int ny,int tnx,int tny,int cse,int csi);
void main()
**
int y[8]={0},i,j,k,l,s=0,x;
char ch;
textbackground(1);
clrscr();
textcolor(1);
do
**
x=l=0;
y[0]++;
while(y[x]>7&&x!=7)
**
y[x]=0;
x++;
y[x]++;
}
for(i=0;i<7;i++)
**
for(j=i+1;j<8;j++)
if(y[i]==y[j] || y[i]+i-j==y[j] || y[i]-i+j==y[j])
**
l=1;
break;
}
if(l==1)break;
}
if(l==0)
**
s++;
shat3(10,1,8,3,8,8,0,7);
for(k=0;k<8;k++)
**
gotoxy(13+8*y[k],(k+1)*3-1);
if((y[k]+k)%2==0)
textattr(4);
else
textattr(7<<4^4);
cprintf("XX");
}
if(y[7]%2==0)
textcolor(7);
else
textcolor(0);
ch=getch();
if(ch=='q')break;
}
}while(y[7]<8);
textbackground(1);
clrscr();
textcolor(2);
gotoxy(35,13);
cprintf("%d",s);
getch();
}
void shat3(int x,int y,int nx,int ny,int tnx,int tny,int cse,int csi)
**
int i,j,k,l,m=0;
gotoxy(x,y);
for(i=0;i<tny;i++)
for(j=0;j<ny;j++)
**
m++;
for(k=0;k<tnx;k++)
**
if((i+k)%2==0)
textbackground(cse);
else
textbackground(csi);
for(l=0;l<nx;l++)
cprintf(" ");
}
gotoxy(x,y+m);
}
}__________________
اعداد مختلط
کد:
/*
Name:Complex class compiler:dev-c++ 4.9.9.2
Copyright: www.codecorona.com
Author: Mohammad yazdani
Description: This class make complex number like a simple data type in c++.
*/
//**********************header files********************************************
#include <iostream>
#include <conio.h>
using namespace std;
//***************designing class************************************************
class complex{
public:
complex(int=0,int=0);
complex operator+(complex);
complex operator+(int);
complex operator-(complex);
complex operator-(int);
complex operator*(complex);
complex operator*(int);
complex operator/(complex);
complex operator/(int);
friend ostream&operator<<(ostream&,complex);
friend istream&operator>>(istream&,complex&);
private:
float real;
float unreal;
};
//*********implementing member functions****************************************
complex::complex(int a,int b)
**
real=a;
unreal=b;
}
//*********************************
complex complex::operator+(complex b)
**
complex c;
c.real=real+b.real;
c.unreal=unreal+b.unreal;
return c;
}
//**********************************
complex complex::operator+(int a)
**
this->real+=a;
this->unreal+=a;
return *this;
}
//***********************************
complex complex::operator-(complex b)
**
complex c;
c.real=real-b.real;
c.unreal=unreal-b.unreal;
return c;
}
//************************************
complex complex::operator-(int a)
**
this->real-=a;
this->unreal-=a;
return *this;
}
//************************************
complex complex::operator*(complex b)
**
complex c(0,0);
c.real=this->real*b.real;
c.unreal=this->unreal*b.unreal*(-1);
return c;
}
//*************************************
complex complex::operator*(int a)
**
this->real*=a;
this->unreal*=a;
return *this;
}
//**************************************
complex complex::operator/(complex b)
**
complex c;
c.real=real/b.real;
c.unreal=unreal/b.unreal;
return c;
}
//***************************************
complex complex::operator/(int a)
**
this->real/=a;
this->unreal/=a;
return *this;
}
//***************************************
ostream&operator<<(ostream&out,complex b)
**
out<<b.real<<(b.unreal>0?'+':' ')<<b.unreal<<'i';
return out;
}
//****************************************
istream&operator>>(istream&in,complex& b)
**
cout<<"please enter the the real section:";
in>>b.real;
cout<<"\nplease enter the unreal section:";
in>>b.unreal;
return in;
}
//****************************************main function*************************
int main()
**
complex a(4,3),b(2,6);
cout<<endl<<a*b;
cout<<endl<<a;
cout<<endl<<a/b;
cout<<endl<<a-2;
getch();
return 0;
}
//******************************************************************************__________________
بازی مار و پله بسیار ساده :
کد:
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<stdlib.h>
#include<math.h>
#include<dos.h>
void hadese(int );
void partab(int ,int );
void nobat(int );
void board();
void pelle();
void mar();
void start();
void rasm(int,int[]);
void redraw();
void welcome();
int p1[2],p[2];
int pos[2];
int passport[2]={0,0};
//************************************************************************
main()**
clrscr();
int driver , mode ;
driver = DETECT ;
mode = 0 ;
initgraph( &driver , &mode , "c:\\tc\\bgi");
randomize();
//************************************************************************
board();
pelle();
mar();
welcome();
redraw();
start();
//**********************************************************************
return 0;
}//main()
void board()**
int size = 10;
for(int k=0 ; k<= size ;k++) **
line(120 , 40+k*(400/(size)) , 120+size*(400/size) , 40+k*(400/size));
line(120 , 41+k*(400/(size)) , 120+size*(400/size) , 41+k*(400/size));
}//for
for( k=0 ; k<=size ; k++) **
line(120+k*(400/size),40,120+k*(400/size),40+size*(400/size));
line(121+k*(400/size),40,121+k*(400/size),40+size*(400/size));
}//for
setcolor(3);
char string[4];
settextstyle(0,0,1);
outtextxy(122,405,"start");
for(int i=0 ; i<= 9 ;i++)**
for(int j=0 ; j<= 9 ;j++)**
if (j%2 == 1)itoa(abs(10-i)+j*10,string, 10);
else itoa(i+1+j*10,string, 10);
//outtextxy(125 + i*40 , 405-j*40 , string);
}//for
}//for
}//board()
void pelle()**
int x[2],y[2] ;
int temp;
int count = 1 ;
while ( count <= 7)**
if(count == 1)x[0] = 340 , y[0] = 420 , x[1] = 380 , y[1] = 300;
if(count == 2)x[0] = 180 , y[0] = 340 , x[1] = 180 , y[1] = 220;
if(count == 3)x[0] = 340 , y[0] = 300 , x[1] = 260 , y[1] = 180;
if(count == 4)x[0] = 460 , y[0] = 420 , x[1] = 500 , y[1] = 380;
if(count == 5)x[0] = 180 , y[0] = 100 , x[1] = 220 , y[1] = 60;
if(count == 6)x[0] = 420 , y[0] = 180 , x[1] = 420 , y[1] = 100;
if(count == 7)x[0] = 260 , y[0] = 140 , x[1] = 260 , y[1] = 100;
setcolor(6);
line(x[0],y[0],x[1],y[1]);
line(x[0]+10,y[0],x[1]+10,y[1]);
line(x[0]+1,y[0],x[1]+1,y[1]); //for bold
line(x[0]+11,y[0],x[1]+11,y[1]); //for bold
float temp1 ;
if(x[1]-x[0] == 0 ) temp1 = 1000000 ;// baraye binahayat
else temp1=fabs(float(y[1]-y[0])/float(x[1]-x[0]));
int i;
if (y[0]<=y[1] && x[0]<=x[1]){for(i=1 ; i<=abs(y[1]-y[0])/10-1 ; i++){line( x[1]-int(i*10./temp1) , y[1]-10*i , x[1]+10-int(i*10./temp1) , y[1]-10*i);line( x[1]-int(i*10./temp1) , y[1]-10*i+1 , x[1]+10-int(i*10./temp1) , y[1]-10*i+1);}}//if
else if (y[0]<=y[1] && x[0]> x[1]){for(i=1 ; i<=abs(y[1]-y[0])/10-1 ; i++){line( x[1]+int(i*10./temp1) , y[1]-10*i , x[1]+10+int(i*10./temp1) , y[1]-10*i);line( x[1]+int(i*10./temp1) , y[1]-10*i+1 , x[1]+10+int(i*10./temp1) , y[1]-10*i+1);}}//if
else if (y[0]> y[1] && x[0]<=x[1]){for(i=1 ; i<=abs(y[1]-y[0])/10-1 ; i++){line( x[0]+int(i*10./temp1) , y[0]-10*i , x[0]+10+int(i*10./temp1) , y[0]-10*i);line( x[0]+int(i*10./temp1) , y[0]-10*i+1 , x[0]+10+int(i*10./temp1) , y[0]-10*i+1);}}//if
else if (y[0]> y[1] && x[0]> x[1]){for(i=1 ; i<=abs(y[1]-y[0])/10-1 ; i++){line( x[0]-int(i*10./temp1) , y[0]-10*i , x[0]+10-int(i*10./temp1) , y[0]-10*i);line( x[0]-int(i*10./temp1) , y[0]-10*i+1 , x[0]+10-int(i*10./temp1) , y[0]-10*i+1);}}//if
count++;
}//while()
}//pelle()
void mar()**
int zaribx0[8]={0,1,9,6,4,0,8,0},zaribx1[8]={0,2,8,5,2,1,7,0},zariby0[8]={0,1,6,8,1,7,9,6},zariby1[8]={0,0,4,5,7,9,0,1};
int x[2],y[2];
int count = 1;
while(count <= 7)**
for(int i=1;i<=7;i++)
if(count == i)x[0]=140+40*zaribx0[i],y[0]=420-40*zariby0[i],x[1]=140+40*zaribx1[i],y[1]=420-40*zariby1[i];
count++;
setcolor(3);
line ( x[0] ,y[0] , x[1] ,y[1]);
setcolor(8);
line ( x[0]+1 ,y[0] , x[1]+1 ,y[1]);
line ( x[0]+2 ,y[0] , x[1]+2 ,y[1]);
line ( x[0]+3 ,y[0] , x[1]+3 ,y[1]);
setcolor(3);
line ( x[0]+4 ,y[0] , x[1]+4 ,y[1]);
}//while()
}//mar()
void start()**
//sleep(3);
int n=0;
pos[0]=pos[1] = -1 ;
p[0] = 125 , p1[0] =428;
p[1] = 125 , p1[1]=405;
rasm(n,pos);
int random1;
char ch=' ';
//randomize();
while(1)**
if(passport[n] == 0)**
nobat(n);
if(n==0) ch=getch();
if(n==1) ch=50; //for computer
while(ch>57 || ch<48)**
ch=getch();
}
if(n==0) random1 = (ch+random(100))%6+1;
else random1 = random(100)%6+1;
//sleep(1);
partab(n,random1);
if(random1 == 6)**
//printf("congrulation");
pos[n]=1;
if(n==0){p[n]=125,p1[n]=428;}
if(n==1){p[n]=125,p1[n]=405;}
redraw();
rasm(n,pos);
passport[n] = 1;
}//if
n=(n+1)%2;
}//if
else **
nobat(n);
if(n==0) ch=getch();
if(n==1) ch=50; //for computer
while(ch>57 || ch<48)**
ch = getch();
}
if(n==0)** random1 = (ch+random(100))%6+1;p[n]=125,p1[n]=428;}
else ** random1 = random(100)%6+1;p[n]=125,p1[n]=405;}
partab(n,random1);
if(pos[n]+random1 >100) goto l1;
// printf("ran = %d" ,random1);
pos[n] = pos[n]+random1;
redraw();
rasm(n,pos);
if(pos[n]==100) ** if(n==0){printf("You Win");getch();exit(0);}
else {printf("Computer Wins"); getch();exit(0);}//else
}//if
if(n==6 ||n==9 ||n==22||n==35||n==68||n==77||n==82||n==19||n==61||n==99||n==78||n==87||n==92||n==70)**
hadese(n);
if(pos[n] == 6)pos[n]=34;
if(pos[n] == 9)pos[n]=11;
if(pos[n] == 22)pos[n]=59;
if(pos[n] == 35)pos[n]=64;
if(pos[n] == 68)pos[n]=88;
if(pos[n] == 77)pos[n]=84;
if(pos[n] == 82)pos[n]=98;
//************************
if(pos[n] == 19)pos[n]=3;
if(pos[n] == 61)pos[n]=20;
if(pos[n] == 99)pos[n]=80;
if(pos[n] == 78)pos[n]=16;
if(pos[n] == 87)pos[n]=55;
if(pos[n] == 92)pos[n]=8;
if(pos[n] == 70)pos[n]=49;
redraw();
rasm(n,pos);
}//if
l1: if(random1 == 6 ) continue;
n = (n+1)%2;
}//else
}//while()
}//start
void rasm(int n,int pos[])**
for(int i=1;i<=2;i++)**
n = (n+1)%2;
if(n==0)setcolor(1);
else setcolor(14);
int h,y;
h = (pos[n]-1)/10;
if(h%2 == 0) y = (pos[n]-1)%10;
else y = abs(10 - pos[n]%10)%10;
int x0,y0;
x0 = p[n]+y*40 ; y0 = p1[n]-40*h;
//setcolor(2);
for(int i=1;i<=8;i++)
line(x0,y0+i,x0+8,y0+i);
// printf("pos[%d]= %d",n,pos[n]);
}//for
getch();
}//rasm()
void redraw()**
//clrscr();
setcolor(0);
for(int i=0;i<=480;i++)
line(0,0+i,640,0+i);
//rectangle(0,0,640,480);
setfillstyle(0,0);
floodfill(50,50,0);
setcolor(15);
board();
pelle();
mar();
}//redraw()
void nobat(int n)**
setcolor(0);
for(int i=1;i<=120;i++)
line(200,180+i,440,180+i);
setcolor(9);
if(n==0){outtextxy(220,210,"It's time for you");
outtextxy(220,220,"press key(0-9)");}
//if(n==1);//outtextxy(220,210,"nobat computer");
if(passport[n]== 0)**
if(n==0){outtextxy(220,230,"you must take 6 ");
outtextxy(220,240,"for enter the game");}
//if(n==1)outtextxy(220,230,"nobat computer");
}//if
// if(passport[n]== 1)**
//if(n==0)outtextxy(220,250,"throw tas ");
//if(n==1)outtextxy(220,250,"");
// }//if
setcolor(15);
rectangle(205,185,435,295);
rectangle(202,182,438,298);
// getch();
}//nobat()
void welcome()**
setcolor(0);
for(int i=1;i<=120;i++)
line(200,180+i,440,180+i);
setcolor(9);
outtextxy(220,240," welcome to the game");
setcolor(15);
rectangle(205,185,435,295);
rectangle(202,182,438,298);
getch();
}//welcome()
void partab(int n , int random1 )**
setcolor(0);
for(int i=1;i<=120;i++)
line(200,180+i,440,180+i);
setcolor(4);
char string[2];
itoa(random1,string,10);
if(n==0){outtextxy(238,225,"you take");outtextxy(250,240,string);}
if(n==1){outtextxy(238,225,"computer takes");outtextxy(250,240,string);}
setcolor(15);
rectangle(205,185,435,295);
rectangle(202,182,438,298);
getch();
}//partab()
void hadese(int n)**
setcolor(12);
setcolor(0);
for(int i=1;i<=120;i++)
line(200,180+i,440,180+i);
setcolor(15);
rectangle(205,185,435,295);
rectangle(202,182,438,298);
if(pos[n]==6 || pos[n]==9 ||pos[n]== 22 || pos[n]==68 || pos[n]==77 ||pos[n]== 82 ||pos[n]==35)
{outtextxy(248,225,"ladder");}
else if(pos[n]==87 || pos[n]==78 ||pos[n]== 99 || pos[n]==61 || pos[n]==19 ||pos[n]== 70 || pos[n]==92)
{outtextxy(248,225,"snake");}
else return;
getch();
}//hadese()__________________