ایجاد منو برای تغییر رنگ پس زمینه
ایجاد منو برای تغییر رنگ پس زمینه
کد PHP:
#include <stdio.h>
#include <conio.h>
f_lines();
up_key();
down_key();
void main()
{
int i;
char c1,c2;
textbackground(0);
gotoxy(wherex(),11);
f_lines();
do
{
c1=getch();
/*******if insert ENTER key*******/
if (c1==13)
{
if (wherey()==19)
{
textbackground(2);
f_lines();
}
if (wherey()==15)
{
textbackground(1);
f_lines();
}
if (wherey()==11)
{
textbackground(4);
f_lines();
}
}
/*******if insert UP key*******/
if (c1==0)
{
c2=getch();
if (((c1==0) && (c2==72)))
{
up_key();
}
/*******if insert DOWN key*******/
if (((c1==0) && (c2==80)))
{
down_key();
}
}
}while(c1!=27);
}
/***********( FUNCTION )**********/
f_lines()
{
int w,i;
w=wherey();
textcolor(15);
clrscr();
printf("%c",201);
for (i=0; i<78; i++)
{
printf("%c",205);
}
printf("%c",187);
for (i=0; i<23; i++)
{ printf("%c\n",186); }
printf("%c",200);
for (i=0; i<77; i++)
{
printf("%c",205);
}
printf("%c",188);
for (i=2; i<25; i++)
{ gotoxy(80,i);
printf("%c",186); }
/*************** Drow KEY ****************/
/******* Red key *******/
gotoxy(34,9);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(34,10);
printf("%c RED %c",186,186);
gotoxy(34,11);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,188);
/******* Blue key *******/
gotoxy(34,13);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(34,14);
printf("%c Blue %c",186,186);
gotoxy(34,15);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,188);
/******* Green key *******/
gotoxy(34,17);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",201,205,205,205,205,205,205,205,205,205,205,187);
gotoxy(34,18);
printf("%c Green %c",186,186);
gotoxy(34,19);
printf("%c%c%c%c%c%c%c%c%c%c%c%c",200,205,205,205,205,205,205,205,205,205,205,188);
gotoxy(wherex(),w);
}
up_key()
{
if ((wherey()==19) || (wherey()==15))
{
int k;
k=wherey()-4;
gotoxy(wherex(),k);
}
}
down_key()
{
if ((wherey()==15) || (wherey()==11))
{
int k;
k=wherey()+4;
gotoxy(wherex(),k);
}
}
برنامه ساده برای کار با کلیدهای مکان نما
برنامه ساده برای کار با کلیدهای مکان نما
کد PHP:
#include <graphics.h>
#include <conio.h>
#include <iostream.h>
#define RIGHT 0x4d /* define keyboard arrow keys */
#define LEFT 0x4b
#define DOWN 0x50
#define UP 0x48
#define ENTER 13
void draw( int, int);
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\tc\\bgi\\");
int x, y;
char c;
x = 50;
y = 300;
setfillstyle(1,1);
circle(x,y,10);
floodfill(x+1,y+1, getmaxcolor());
do
{
c = getch();
if ( c == UP )
{
y-=1;
draw(x, y);
}
if ( c == DOWN )
{
y+=1;
draw(x, y);
}
if ( c == RIGHT )
{
x+=1;
draw(x, y);
}
if ( c == LEFT )
{
x-=1;
draw(x, y);
}
if ( c == ENTER )
{
for ( int i = x; i < getmaxx()+10; i++)
draw( i, y);
}
}while( c != ENTER );
getch();
closegraph();
return 0;
}
void draw( int x , int y)
{
cleardevice();
setfillstyle(SOLID_FILL,BLUE);
circle(x,y,10);
floodfill(x+1,y+1,getmaxcolor());
}
گرافیک در توربو سی پلاس پلاس
کد PHP:
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
#include <dos.h>
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "C:\\tc\\bgi\\");
int x, y, maxx, maxy, color;
maxx = getmaxx();
maxy = getmaxy();
srand( time ( 0 ) );
for ( int i = 0; i < 500; i++ )
{
if(kbhit()) break;
x = rand() % maxx;
y = rand() % maxy;
color = rand() % 12;
setcolor(color);
for (int xx = 0, yy = 10; xx <= 360; xx+= 5, yy += 5 )
{
pieslice ( x, y, xx, yy, 10);
delay(10);
}
}
getch();
closegraph();
return 0;
}
دترمینان یک ماتریس n در n
برنامه ای برای بدست آوردن دترمینان یک ماتریس n در n
کد PHP:
#include <iostream.h>
#include <conio.h>
int calc(int [],int dim);
void revmatrix( int [],int dim);
void main()
{
int matrix[1000];
int dim,temp;
double leftsum,rightsum;
cout<<" PLEASE ENTER MATRIX DIMENSION : ";
cin>>dim;
cout<<"\n\n\n";
for( int i = 0;i<( dim*dim );i ++ )
{
cout<<"ENTER ELEMAN : ";
cin>>temp;
matrix[i] = temp;
clrscr();
cout<<" PLEASE ENTER MATRIX DIMANTION : "<<dim;
cout<<"\n\n\n";
}//for i
if ( dim > 2 )
{
leftsum = calc( matrix , dim );
cout<<"LEFTSUM of the matrix = "<< leftsum <<"\n\n";
revmatrix( matrix , dim );
rightsum = calc( matrix ,dim );
cout<<"RIGHTSUM of the matrix = "<< rightsum <<"\n\n\n\n\n\n" ;
cout<<" ( DETERMINAN OF THE MATRIX = "<< leftsum - rightsum<<" )";
}
else
cout<<" ( DETERMINAN OF THE MATRIX = "<<(matrix[0] * matrix[3] - matrix[1] * matrix[2])<<" )";
getch();
}//end main
/////////////////calc function//////////
int calc( int matrix[ ], int dim )
{
int sum = 0, bul, x = 1;
for( int l = 0; l<( dim*dim );l += ( dim+1 ) )//ghotr asli
x *= matrix[l];
sum = x;
x = 1;
for( int c = 1;c<dim;c ++ )
{
bul=c;
for( int m = 0;m<dim;m ++ )
{
if( ( bul+1 )%dim != 0 )
{
x *= matrix[bul];
bul +=( dim + 1 );
}
else
{
x = x * matrix[bul];
bul += 1;
}
}//for m
sum += x;
x = 1;
}//for c
return sum;
}
////////////////////revmatriv determinan
void revmatrix(int matrix[ ],int dim)
{
int end,temp,counter;
for( int t = dim-1;t <= dim*dim;t = t + dim )
{
end=t;
counter = end -( dim-1 );
while( end > counter )
{
temp = matrix[end];
matrix[end] = matrix[counter];
matrix[counter] = temp;
++ counter;
-- end;
}
}
}
پاسخ : پروژه هاي برنامه نويسي
این در این برنامه هر عددی بین 1 تا 99 را وارد کنید معادل اسم عدد رو چاپ می کند مثلا اگر عدد 2 را وارد کنیم معادل اسمش یعنی towرا چاپ میکند این برنامه رو میتونید گسترش بدین..
کد PHP:
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int num,div,res,rem;
cout<<"enter and Digit 1 to 99 = ";
cin>>num;
if (num>=1 && num<=20)
{
if (num==1)
cout<<"one";
if (num==2)
cout<<"two";
if (num==3)
cout<<"";
if (num==4)
cout<<"four";
if (num==5)
cout<<"five";
if (num==6)
cout<<"six";
if (num==7)
cout<<"seven";
if (num==8)
cout<<"eight";
if (num==9)
cout<<"nine";
if (num==10)
cout<<"ten";
if (num==11)
cout<<"eleven";
if (num==12)
cout<<"twelve";
if (num==13)
cout<<"thirteen";
if (num==14)
cout<<"fourteen";
if (num==15)
cout<<"fifteen";
if (num==16)
cout<<"sixteen";
if (num==17)
cout<<"seventeen";
if (num==18)
cout<<"eighteen";
if (num==19)
cout<<"ninteen";
if (num==20)
cout<<"twenty";
}
if (num>=21 && num<=99)
{
rem=num%10;
res=num-rem;
div=res/10;
switch (div)
{
case 2:
cout<<"twenty"; break;
case 3:
cout<<"thirty";break;
case 4:
cout<<"fourty";break;
case 5:
cout<<"fifty";break;
case 6:
cout<<"sixty";break;
case 7:
cout<<"seventy";break;
case 8:
cout<<"eighty";break;
case 9:
cout<<"ninety";break;
}
switch (rem)
{
case 1:
cout<<"one";break;
case 2:
cout<<"two";break;
case 3:
cout<<"three";break;
case 4:
cout<<"four";break;
case 5:
cout<<"five";break;
case 6:
cout<<"six";break;
case 7:
cout<<"seven";break;
case 8:
cout<<"eight";break;
case 9:
cout<<"nine";break;
}
}
getch();
}
برنامه تبدیل عبارات میانوندی به پسوندی
برنامه تبدیل عبارات میانوندی به پسوندی
کد PHP:
#include <iostream>
#include <conio>
void pop(char,int*,char*);
void print(char*);
char push(int*,char*);
char in[50],out[50],stack[50],ch;
int main()
{
int top=-1,i,j=0;
clrscr();
cout<<"\n\nPlease enter your prasse:";
cin>>in;
for(i=0;i<50;i++)
{
if((in[i]>96&&in[i]<123)||(in[i]>64&&in[i]<91))
{
out[j]=in[i];
++j;
}
else if(in[i]!=')')
pop(in[i],&top,stack);
else if(in[i]==')')
{
while(top>-1)
{
ch=push(&top,stack);
if(ch!='(')
{
out[j]=ch;
++j;
}
}
}
}
print(out);
print(stack);
getch();
return 0;
}
//*************************************
void pop(char x,int* up,char *stack)
{
*up+=1;
if(*up>49)
cout<<"Sorry Stack Is Full";
else
stack[*up]=x;
}
//*************************************
char push(int *up,char *stack)
{
if(*up<0)
cout<<"\nSorry Stack Is Empety\n\n";
else
*up-=1;
return stack[*up+1];
}
//*************************************
void print(char*s)
{
for(int i=0;i<50;i++)
if(s[i])
cout<<s[i];
}