سلام دوستان عزیز
قصد دارم چندتا سورس کد آماده واستون بزارم...
همه کدها به زبان ++C یا C هست
لطفا از درخواست هرگونه پروژه در این قسمت خودداری کنید...
Printable View
سلام دوستان عزیز
قصد دارم چندتا سورس کد آماده واستون بزارم...
همه کدها به زبان ++C یا C هست
لطفا از درخواست هرگونه پروژه در این قسمت خودداری کنید...
اولین کد بازی دوز هست::::::::::::::::::
[PHP]#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
char matrix[3][3];
char check(void);
void init_matrix(void);
void get_player_move(int);
void get_remove_player(int);
void disp_matrix(void);
//*********************************
int main(void)
{
char done;
int rep=0;
clrscr();
cout << "This is the game of Tic tac Toe" << endl;
cout << "You Will playing against computer" << endl;
done=' ';
init_matrix();
disp_matrix();
do{
if (rep<3) get_player_move(1);
else get_remove_player(1);
disp_matrix();
done=check();
if (done!=' ') break;
if (rep<3) get_player_move(2);
else get_remove_player(2);
disp_matrix();
done=check();
rep++;
}while (done==' ');
if (done=='1') cout << "player1 won!" << endl;
else cout << "player2 !!!" << endl;
getch();
return 0;
}
//*********************************
void init_matrix(void)
{
int i,j;
for(i=0;i<3;i++)
for(j=0;j<3;j++) matrix[i][j]=' ';
}
//*********************************
void get_player_move(int m)
{
int x,y;
gotoxy (15,0);
cout << "Enter player " << m << " [X,Y]:" ;
cin >> x >> y;
int test=(x>3 || y>3 || x<0 || y<0);
x--; y--;
if ( matrix[x][y]!=' ' || test ) {
cout << " Invalid move ,try again " << endl ;
get_player_move(m);
}
else
if (m==1) matrix[x][y]='1';
else matrix[x][y]='2';
}
//*********************************
void get_remove_player(int m)
{
int x,y;
gotoxy (0,m+19);
cout << "Enter remove player" << m << " [X,Y]:";
cin >> x >> y;
int test=(x>3 || y>3 || x<0 || y<0);
x--; y--;
if ( matrix[x][y]!=48+m || test ) {
cout << " Invalid move ,try again " << endl;
get_player_move(m);
}
else
matrix[x][y]=' ';
get_player_move(m);
}
//*********************************
void disp_matrix(void)
{
gotoxy(0,5);
for(int i=0;i<3;i++){
cout << " " << matrix[i][0] << " | " << matrix[i][1] << " | " << matrix[i][2];
if (i!=2) cout << endl << "---|---|---" << endl;
}
cout << endl;
}
//*********************************
char check(void)
{
for(int i=0;i<3;i++)
if(matrix[i][0]==matrix[i][1] && matrix[i][0]==matrix[i][2]) return matrix[i][0];
for(i=0;i<3;i++)
if(matrix[0][i]==matrix[1][i] && matrix[0][i]==matrix[2][i]) return matrix[0][i];
for(i=0;i<3;i++)
if(matrix[0][0]==matrix[1][1] && matrix[1][1]==matrix[2][2]) return matrix[0][0];
for(i=0;i<3;i++)
if(matrix[0][2]==matrix[1][1] && matrix[1][1]==matrix[2][0]) return matrix[0][2];
return ' ';
}
[/PHP]
یه کد که یه سری اعمال روی ماتریس ها انجام میده::::::::::::
[PHP]#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
void fill_matrix(int matrix[20][20],int n);
void disp_matrix(int matrix[20][20],int n);
void test_range(int *i1,int *j1,int n);
//*********************************
int main(void)
{
int n, matrix[20][20]={0};
clrscr();
cout << "Please Enter n:";
cin >> n;
fill_matrix(matrix,n);
disp_matrix(matrix,n);
getch();
return 0;
}
//*********************************
void fill_matrix(int matrix[20][20],int n)
{
int i,j,i1,j1;
n--;
i=0;j=n/2;
matrix[i][j]=1;
for(int m=1;m<(n+1)*(n+1);m++)
{
i1=i-1;
j1=j-1;
test_range(&i1,&j1,n);
if (matrix[i1][j1]!=0) {i1=i+1;j1=j; test_range(&i1,&j1,n);}
matrix[i1][j1]=m+1;
i=i1; j=j1;
}
}
//*********************************
void test_range(int *i1,int *j1,int n)
{
if (*i1>n) *i1=0;
if (*i1<0) *i1=n;
if (*j1>n) *j1=0;
if (*j1<0) *j1=n;
}
//*********************************
void disp_matrix(int matrix[20][20] ,int n)
{
for(int i=0;i<n;i++){
for(int j=0;j<n;j++)
if(matrix[i][j]<10) cout << " " << matrix[i][j];
else if(matrix[i][j]<100) cout << " " << matrix[i][j];
else cout << " " << matrix[i][j];
cout << endl;
}
}[/PHP]
سورت 45 عدد:::::::::::::
[PHP]#include <iostream.h>
#include <stdlib.h>
#include <conio.h>
void pInput(int *, int);
void bubble(int *, int);
void median(int *, int, float *);
void pOutput(int *, int);
int main()
{
int n, *p;
float mead;
clrscr();
cout << "Enter number of items(n):";
cin >> n;
p = new int[10];
if(!p){
cout << " Allocation failure!";
getch();
exit(1);
}
pInput(p, n);
bubble(p, n);
cout << "\n Sorted data are:";
pOutput(p, n);
median(p, n, &mead);
cout << "\n Median = " << mead;
delete p;
getch();
return 0;
}
//*****************************
void pInput(int *p, int n)
{
int i;
for(i = 0; i < n; i ++){
cout << "Enter number " << (i + 1) << ": ";
cin >> *(p + i);
}
}
//*****************************
void bubble(int *temp, int len)
{
int i, j, item;
for(i = len - 1 ; i > 0; i --)
for(j = 0; j < i ; j++)
if(*(temp + j) > *(temp + j + 1)) {
item = *(temp + j);
*(temp + j) = *(temp + j + 1);
*(temp + j + 1) = item ;
}//end of if
}
//*************************
void median(int *x, int n, float *mead)
{
if(n % 2 == 0)
*mead =(float) (*(x + ((n - 1) / 2)) + *(x + (n / 2))) / 2;
else
*mead = *(x + (n - 1) / 2);
}
//****************
void pOutput(int *p, int n)
{
for(int i = 0; i < n; i ++){
cout << *(p + i) << " ";
}
cout << endl;
}
[/PHP]
حرکت اسب (64 حرکته ):::::::::::ک
[PHP]#include <stdio.h>
#include <conio.h>
#include <iostream.h>
#include <process.h>
#include <iomanip.h>
#include<dos.h>
#include<time.h>
#include<stdlib.h>
struct ChessMoves
{
int sx;
int sy;
}
sto[8]; // sto[]--> 8 Possible horse`s moves in chessboard (L-Like moves)
int xx,yy,x,y,sum,av,st,j,i,k,feld[8][8];
// i,j,k --> Counter
// x,y --> Current Position
// sum --> Temporary counter for choosing the best stable(Number of available moves)
// av --> Available moves
// st --> Chosen stable
// feld[][] --> Really chessboard , full holes are 0 and empty ones are 1
int mov(int,int);
void draw();
void main()
{
sto[0].sx=-2; sto[0].sy=-1;
sto[1].sx=-1; sto[1].sy=-2;
sto[2].sx=1; sto[2].sy=-2;
sto[3].sx=2; sto[3].sy=-1;
sto[4].sx=2; sto[4].sy=1;
sto[5].sx=1; sto[5].sy=2;
sto[6].sx=-1; sto[6].sy=2;
sto[7].sx=-2; sto[7].sy=1;
clrscr();
cout << "Input Row : ";
cin >> x;
cout << "Input Column : ";
cin >> y;
if((x>8) || (x<1) || (y>8) || (y<1))
exit(1);
x--;
y--;
for(i=0;i<8;i++)
for(j=0;j<8;j++)
feld[i][j]=1;
feld[x][y]=0;
draw();
for(k=2;k<65;k++)
{
av=8;
st=0;
for(j=0;j<8;j++)
{
sum=0;
xx=x+sto[j].sx;
yy=y+sto[j].sy;
if((xx>=0) && (yy>=0) && (xx<8) && (yy<8) && mov(xx,yy))
{
for(i=0;i<8;i++)
if(mov(xx+sto[i].sx,yy+sto[i].sy))
sum+=1;
if(av>sum)
{
av=sum;
st=j;
}
}
}
x=x+sto[st].sx;
y=y+sto[st].sy;
feld[x][y]=0;
draw();
cout <<"\n\nEnd Of Moved:::"<<" x: (" << x+1<<")" << " y: (" << y+1<<")" << "\t\t\t\t\t";
}
gotoxy(25,25);
cout <<"\n\n\n\n END OF PROGRRAM !!";
getch();
}
// if a move possible ?
int mov(int a,int b)
{
if((a>=0) && (b>=0) && (a<8) && (b<8))
return(feld[a][b]);
else
return(0);
}
// draw current state of chessboard
void draw()
{
int ii,jj;
clrscr();
cout << " A B C D E F G H\n";
cout << " عؤؤؤؤؤآؤؤؤؤؤآؤؤؤؤؤآؤؤؤؤؤآ ؤؤؤؤؤآؤؤؤؤؤآؤؤؤؤؤآؤؤؤؤؤ؟\n ";
for(ii=0;ii<8;ii++)
{
cout << ii+1 << " ";
for(jj=0;jj<8;jj++)
{
if(!(feld[ii][jj]))
cout << "³ ±±± "; // Choose your favourite color : °±²غ
else
cout << "³ ";
}
if(ii<7)
cout << "³\n أؤؤؤؤؤإؤؤؤؤؤإؤؤؤؤؤإؤؤؤؤؤإ ؤؤؤؤؤإؤؤؤؤؤإؤؤؤؤؤإؤؤؤؤؤ´\n ";
}
cout << "³\n ہؤؤؤؤؤءؤؤؤؤؤءؤؤؤؤؤءؤؤؤؤؤء ؤؤؤؤؤءؤؤؤؤؤءؤؤؤؤؤءؤؤؤؤؤظ";
cout << "\n\n Press Any Key To Continue";
getch();
}[/PHP]
اینم حرکت اسب هست به صورت گرافیکی:::::::::::
[PHP]#include<iostream.h>
#include<math.h>
#include<stdlib.h>
#include<iomanip.h>
#include<stdio.h>
#include<conio.h>
#define Cbakg 1
#define Cbakgtxt 2
#define Cbakgshattxt 4
#define Cbakgshatsiah 0
#define Cbakgshatsefid 7
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);
}
}
void main()
{
int sh[12][12]={0};
int h[8][2]={{2,1},{1,2},{-1,2},{-2,1},{-2,-1},
{-1,-2},{1,-2},{2,-1}};
int k=0,x,y,step=1,xNew,yNew,num,minNum=9,minK;
int l,i,j;
char ch;
textbackground(Cbakg);
textcolor(Cbakgtxt);
clrscr();
/////////////
//initialize
for(i=0;i<12;i++){
sh[i][0]=sh[i][1]=sh[i][10]=sh[i][11]=-1;
sh[0][i]=sh[1][i]=sh[10][i]=sh[11][i]=-1;
}
cprintf("inter x,y ");
scanf("%d%d",&x,&y);
x=(x-1)%8+1;
y=(y-1)%8+1;
clrscr();
cprintf("inter x,y x=%d y=%d",x,y);
x++;
y++;
sh[x][y]=step;
/////////////////
//begin calculate
for(step=2;step<=64;step++){
minNum=9;
for(k=0;k<8;k++){
xNew= x + h[k][0];
yNew= y + h[k][1];
if( sh[xNew][yNew] == 0){
sh[xNew][yNew] = step;
num=0;
for(l=0;l<8;l++)
if(sh[ xNew + h[l][0] ][ yNew + h[l][1] ]==0) num++;
if(num<minNum){
minNum=num;
minK=k;
}
sh[xNew][yNew] = 0;
}
}
x= x + h[minK][0];
y= y + h[minK][1];
sh[x][y]=step;
}
//end calculate
///////////////
///////////////
//output
textcolor(Cbakgshattxt);
shat3(10,1,8,3,8,8,Cbakgshatsiah,Cbakgshatsefid);
for(i=0;i<8;i++)
for(j=0;j<8;j++){
if((i+j)%2==0)
textbackground(Cbakgshatsiah);
else
textbackground(Cbakgshatsefid);
gotoxy(j*8+13,i*3+2);
cprintf("%2d",sh[i+2][j+2]);
}
textcolor(Cbakgtxt);
textbackground(Cbakg);
cprintf("\n\n");
gotoxy(20,25);
cprintf("To run Step By Step,press y...");
cprintf("\n");
cprintf("To Quit Press q ");
ch=getch();
if(ch=='y'||ch=='Y'){
clrscr();
gotoxy(20,27);
cprintf("To Quit Press q ");
shat3(10,1,8,3,8,8,Cbakgshatsiah,Cbakgshatsefid);
textcolor(Cbakgshattxt);
for(i=1;i<65;i++){
for(j=0;j<8;j++)
for(l=0;l<8;l++)
if(sh[j+2][l+2]==i){
if((l+j)%2==0)
textbackground(Cbakgshatsiah);
else
textbackground(Cbakgshatsefid);
gotoxy(l*8+13,j*3+2);
cprintf("%2d",i);
gotoxy(80,25);
}
ch=getch();
if(ch=='q'||ch=='Q')break;
}
}
}[/PHP]
ماتریس اسپارس:::::::::::
[PHP]#include<iostream.h>
#include<conio.h>
const int n=3;
int main()
{
clrscr();
int s[n][n], s2[n][n] ;
int s_row[n];
int i,j ;
clrscr ;
cout << " ================ Enter Sparse Matrix =================\n";
for (i=0; i<n; i++)
{
cout << endl ;
for (j=0; j<n; j++)
{
cout << "s[" << i << "][" << j << "]=" ;
cin >> s[i][j] ;
}
}
getch();
// calculate transpose
for (int m=0; m<n; m++)
{
for (i=0; i<n; i++)
{
s_row[i]=s[i][m]; // copy mth column of matrix "s"
}
for (j=0; j<n; j++)
{
s2[m][j]=s_row[j]; // copy mth column of matrix "s" into mth row of matrix "s2"
}
}
cout << "Transpose of s matrix is: " << endl;
for (i=0; i<n; ++i)
for (j=0; j<n; ++j)
cout << "s2[" << i << "][" << j << "]=" << s2[i][j] << endl;
getch();
return 0;
}[/PHP]
برنامه ساخت منو و کار با آن از طریق کلاس ها::::::
[PHP]http://farshidshd.persiangig.com/menu(farshidshd).cpp[/PHP]
برنامه مشخصات دانشجویی به شیوه ی دیگر:::::::::::
[PHP]#include <fstream.h>
#include <iostream.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
void enter();
void report();
void trans();
int menu();
void closeAcc();
void maxBal();
struct customer {
int state;
char name[21];
int bal;
int account;
int kind;
} ;
//********************
int main()
{
int c;
for(;;) {
clrscr();
c = menu();
switch(c) {
case 1 : enter(); break;
case 2 : trans(); break;
case 3 : maxBal(); break;
case 4 : closeAcc(); break;
case 5 : report(); break;
case 6 : exit(0);
} //end of switch
} //end of for
}
//****************************
int menu()
{
int p;
cout << "1. Enter data" << endl;
cout << "2. Transaction" << endl;
cout << "3. Maximu balance" << endl;
cout << "4. Close customer account" << endl;
cout << "5. Report the file" << endl;
cout << "6. Terminate program" << endl;
cout << "Enter your select(1-6):";
cin >> p;
cin.get(); //clear the keyboard buffer
return p ;
}
//**************************
void enter()
{
customer cust;
clrscr();
ofstream fp("st.dat", ios::out | ios::in | ios::binary);
int r = 2;
cout << "Name "
<< "Balance Account# Kind(1,2)";
gotoxy(1, r);
cin.getline(cust.name, 20);
gotoxy(20, r);
cin >> cust.bal;
gotoxy(35, r);
cin >> cust.account;
gotoxy(45, r);
cin >> cust.kind;
cust.state = 1;
fp.seekp(sizeof(struct customer) * cust.account, ios::beg);
fp.write((char *) &cust, sizeof(struct customer));
fp.close();
}
//**********************
void report()
{
int r = 2;
clrscr();
cout << "Name "
<< "Balance Account# Kind(1,2)";
ifstream fp("st.dat", ios::in | ios::binary);
customer cust;
while(fp.read((char *) &cust, sizeof(struct customer))) {
if(cust.state == 1) {
gotoxy(1, r);
cout << cust.name;
gotoxy(20, r);
cout << cust.bal;
gotoxy(35, r);
cout << cust.account;
gotoxy(45, r);
cout << cust.kind;
r ++;
}
}
fp.close();
cout << "\nPress a key to continue...";
cin.get();
}
//*********************
void trans()
{
int acnum, amount;;
char tran;
customer cust;
clrscr();
cout << "Enter account number to change balance:";
cin >> acnum;
fstream fp("st.dat", ios::out | ios::in | ios::binary);
cout << "Do you want to decrement(d) or increment(i):";
cin >> tran;
cout << "Enter ammount to decrement or increment:";
cin >> amount;
fp.seekg(sizeof(struct customer) * acnum, ios::beg);
fp.read((char *) &cust, sizeof(struct customer));
switch(tran) {
case 'i':
cust.bal += amount; break;
case 'd':
if(cust.bal < amount) {
cout << "Balance is less, cannot change.";
getch();
}
else
cust.bal -= amount;
break;
} //end of switch
fp.seekp(sizeof(struct customer) * acnum, ios::beg);
fp.write((char *) &cust, sizeof(struct customer));
}
//***************************
void closeAcc()
{
int acnum;
customer cust;
cout << "Enter account number for close:";
cin >> acnum;
fstream fp("st.dat", ios::out | ios::in | ios::binary);
fp.seekg(sizeof(struct customer) * acnum, ios::beg);
fp.read((char *) &cust, sizeof(struct customer));
cust.state = 0;
fp.seekp(sizeof(struct customer) * acnum, ios::beg);
fp.write((char *) &cust, sizeof(struct customer));
}
//*********************
void maxBal()
{
int r = 2;
clrscr();
customer cust, cust1;
cust1.bal = 0;
fstream fp("st.dat", ios::out | ios::in | ios::binary);
while(fp.read((char *) &cust, sizeof(struct customer)))
if(cust.state == 1)
if(cust.bal > cust1.bal)
cust1 = cust;
cout << "Name "
<< "Balance Account# Kind(1,2)";
gotoxy(1, r);
cout << cust1.name;
gotoxy(20, r);
cout << cust1.bal;
gotoxy(35, r);
cout << cust1.account;
gotoxy(45, r);
cout << cust1.kind;
getch();
}[/PHP]
سلام
اگه اجازه هستش منم چند تا میزارم البته اونای که دم دست بودن
ترتیب بهینه ضرب ماتریسها
کد:http://files.myopera.com/HaW3D/files/main.cpp