Pages

💡 Now You Can Get your Assignments Sollution here... .💡 100% plagiarism Free Service...💡 Responsibility, punctuality and on-time delivery... 💡 Furnishing you with experts... 💡 experienced in your subject 100% privacy... 💡 helping you with the highest efficiency , professionalism Affordable and budget-friendly costs that do not make a hole in your wallet

Showing posts with label Assignments. Show all posts
Showing posts with label Assignments. Show all posts

C++ code for Tic Tak Toe

#include<iostream>
#include<windows.h>
using namespace std;
void main()
{
int rep=0;
do
{
system("color f0");
int c=1;
char game[3][3]={'7','8','9','4','5','6','1','2','3'};
int num;
char player1='\0',player2='\0';
int check;
cout<<"Please press caps on to Start game\n";
int y=rand()%100;
if(y%2==0)
{
cout<<"Player 1 select your option \'X\' or \'O\'\n";
cin>>player1;
check=1;
if(player1=='O')
player2='X';
if(player1=='X')
player2='O';
cout<<"Player 1:"<<player1<<" Player 2:"<<player2<<"\n";
}
if(y%2!=0)
{
cout<<"Player 2 select your option \'X\' or \'O\'\n";
cin>>player2;
check=2;
if(player2=='O')
player1='X';
if(player2=='X')
player1='O';
cout<<"Player 1:"<<player1<<" Player 2:"<<player2<<"\n";
}
system("pause");
system("cls");
cout<<"Game started\n\n";
int k=1;
do
{
if(check==1)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<game[i][j]<<"\t";
}
cout<<"\n\n";
}
system("color f8");
cout<<"\nPlayer 1:"<<player1<<"\nPress number 1-9 as on standerd keyboard:";
cin>>num;
if(num==1 && game[2][0]!='X' && game[2][0]!='O')
{
game[2][0]=player1;
check=2;
k++;
}
if(num==2 && game[2][1]!='X' && game[2][1]!='O')
{
game[2][1]=player1;
check=2;
k++;
}
if(num==3 && game[2][2]!='X' && game[2][2]!='O')
{
game[2][2]=player1;
check=2;
k++;
}
if(num==4 && game[1][0]!='X' && game[1][0]!='O')
{
game[1][0]=player1;
check=2;
k++;
}
if(num==5 && game[1][1]!='X' && game[1][1]!='O')
{
game[1][1]=player1;
check=2;
k++;
}
if(num==6 && game[1][2]!='X' && game[1][2]!='O')
{
game[1][2]=player1;
check=2;
k++;
}
if(num==7 && game[0][0]!='X' && game[0][0]!='O')
{
game[0][0]=player1;
check=2;
k++;
}
if(num==8 && game[0][1]!='X' && game[0][1]!='O')
{
game[0][1]=player1;
check=2;
k++;
}
if(num==9 && game[0][2]!='X' && game[0][2]!='O')
{
game[0][2]=player1;
check=2;
k++;
}
if((game[0][0]==player1)&&(game[0][1]==player1)&&(game[0][2]==player1))
{
num=0;
k=9;
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins \a"<<(char)1<<"\n";
check=0;
system("pause");
}
else if((game[1][0]==player1)&&(game[1][1]==player1)&&(game[1][2]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins\a "<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
else if((game[2][0]==player1)&&(game[2][1]==player1)&&(game[2][2]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
else if((game[0][0]==player1)&&(game[1][0]==player1)&&(game[2][0]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
else if((game[0][1]==player1)&&(game[1][1]==player1)&&(game[2][1]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
else if((game[0][2]==player1)&&(game[1][2]==player1)&&(game[2][2]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins\a "<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
else if((game[0][0]==player1)&&(game[1][1]==player1)&&(game[2][2]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins\a "<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
else if((game[0][2]==player1)&&(game[1][1]==player1)&&(game[2][0]==player1))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player1 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
}
system("cls");
if(check==2)
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
cout<<game[i][j]<<"\t";
}
cout<<"\n\n";
}
system("color f4");
cout<<"\nPlayer 2:"<<player2<<"\nPress number 1-9 as on standerd keyboard:";
cin>>num;
if(num==1 && game[2][0]!='X' && game[2][0]!='O')
{
game[2][0]=player2;
check=1;
k++;
}
if(num==2 && game[2][1]!='X' && game[2][1]!='O')
{
game[2][1]=player2;
check=1;
k++;
}
if(num==3 && game[2][2]!='X' && game[2][2]!='O')
{
game[2][2]=player2;
check=1;
k++;
}
if(num==4 && game[1][0]!='X' && game[1][0]!='O')
{
game[1][0]=player2;
check=1;
k++;
}
if(num==5 && game[1][1]!='X' && game[1][1]!='O')
{
game[1][1]=player2;
check=1;
k++;
}
if(num==6 && game[1][2]!='X' && game[1][2]!='O')
{
game[1][2]=player2;
check=1;
k++;
}
if(num==7 && game[0][0]!='X' && game[0][0]!='O')
{
game[0][0]=player2;
check=1;
k++;
}
if(num==8 && game[0][1]!='X' && game[0][1]!='O')
{
game[0][1]=player2;
check=1;
k++;
}
if(num==9 && game[0][2]!='X' && game[0][2]!='O')
{
game[0][2]=player2;
check=1;
k++;
}
if((game[0][0]==player2)&&(game[0][1]==player2)&&(game[0][2]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[1][0]==player2)&&(game[1][1]==player2)&&(game[1][2]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[2][0]==player2)&&(game[2][1]==player2)&&(game[2][2]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins\a "<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[0][0]==player2)&&(game[1][0]==player2)&&(game[2][0]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[0][1]==player2)&&(game[1][1]==player2)&&(game[2][1]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[0][2]==player2)&&(game[1][2]==player2)&&(game[2][2]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins\a "<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[0][0]==player2)&&(game[1][1]==player2)&&(game[2][2]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins \a"<<(char)1<<"\n";
check=0;
k=9;
num=0;
system("pause");
}
if((game[0][2]==player2)&&(game[1][1]==player2)&&(game[2][0]==player2))
{
cout<<"\n\n\t\t\t"<<(char)1<<" Player2 Wins \a"<<(char)1<<"\n";
check=0;
      k=9;
num=0;
system("pause");
}
}

system("cls");
 }while(k<9);
            cout<<"Press 1 to Rematch\nPress 2 to Terminate:";
       cin>>rep;
     }while(rep==1);
}

C++ Code for Sorting 2D Array odd rows asscending and Even Rows Decending

#include<iostream>
using namespace std;
void sortass(int [][4],int);
void sortdes(int [][4],int);
void main()
{
int arr[6][4];
for(int i=0;i<6;i++)
for(int j=0;j<4;j++)
arr[i][j]=rand()%40+10;
for(int i=0;i<6;i++)
{
for(int j=0;j<4;j++)
cout<<arr[i][j]<<" ";
cout<<"\n";
}
cout<<"\n";
for(int i=0;i<6;i++)
{
if(i%2==0)
{
sortass(arr,i);
}
if(i%2!=0)
{
sortdes(arr,i);
}
}
for(int i=0;i<6;i++)
{
for(int j=0;j<4;j++)
cout<<arr[i][j]<<" ";
cout<<"\n";
}
}
void sortdes(int arr[][4],int i)
{
int temp;
for(int k=0;k<4;k++)
{
for(int j=k;j<4;j++)
{
if(arr[i][k]<arr[i][j])
{
temp=arr[i][j];
arr[i][j]=arr[i][k];
arr[i][k]=temp;
}
}
}

}
void sortass(int arr[][4],int i)
{
int temp;
for(int k=0;k<4;k++)
{
for(int j=k;j<4;j++)
{
if(arr[i][k]>arr[i][j])
{
temp=arr[i][j];
arr[i][j]=arr[i][k];
arr[i][k]=temp;
}
}
}
}

C++ program to work as ATM counter

#include<iostream>
using namespace std;
void calculation(int&,int&,int&,int&);
void output(int,int,int,int);
void main()
{
int amount,five=0,thau=0,fthau=0;

do
{
cout<<"Enter Amount in limit of 25000 and *ple of 500:";
cin>>amount;
}while(amount>25000);
int temp=amount;
calculation(amount,five,thau,fthau);
output(temp,five,thau,fthau);
}
void calculation(int &amount,int &five,int &thau,int &fthau)
{
do
{
if(amount>=5000 && amount<=25000)
{
fthau=amount/5000;
amount=amount-(fthau*5000);
}
else
if(amount>=2000 && amount<5000)
{
thau=amount/1000;
amount-=(thau*1000);
}
else
if(amount>=500 && amount<2000)
{
five=amount/500;
amount-=(five*500);
}
}while(amount>=500);
if(amount<500 && amount!=0)
{
cout<<"Less then 500\\ is neglected and not deducted from your account\n";
system("pause");
}
}
void output(int amount,int five,int thau,int fthau)
{
system("cls");
cout<<"\nYour amount:"<<amount;
cout<<"\n=================================================\n";
cout<<"5000\\ Rupees notes:"<<fthau;
cout<<"\n1000\\ Rupees notes:"<<thau;
cout<<"\n500\\ Rupees notes:"<<five;
cout<<"\n=================================================\n";
}

C++ Code to find Factorial using Recurtion

#include<iostream>
using namespace std;

void Fac(int n, int &ans) //& use to get address
{
ans*=n; // is ans=ans*n;
if(n>1)
Fac(n-1, ans); // 'ans' passed by reference
}
int main()
{
int numb = 0;
int ans = 1;
cout<<"Enter number: ";
cin>>numb; //Getting number
Fac(numb, ans);
cout<<ans<<"\n";
cout<<endl;
return 0;
}

// For any query type it in comment or chat with any online Admin

Write a C++ program for the following problem. Initialize an integer array A [] of size 5 in declaration.{ Assign the address of first element of array A[] to pointer variable ptr. Using pointer variable find and display the maximum and the minimum element of the array.



#include<iostream>
using namespace std;
int main()
{
int a[5];
for(int i=0; i<5; i++)
{
cin>>a[i];
}
  int *p,minimum=a[0],maximum=a[0];
  for(int i=0;i<5;i++)
  {
  p=&a[i];
  if(*p<minimum)
minimum=*p;
else if (*p>maximum)
maximum=*p;
}
cout<<"minimum : "<<minimum<<"  maximum : "<<maximum<<endl;
return 0;
}