Friday, 10 June 2016

C++ Tic Tac Toe Game Project - source code

#include <iostream>
using namespace std;

char square[10] = {'o','1','2','3','4','5','6','7','8','9'};

int checkwin();
void board();

int main()
{
 int player = 1,i,choice;

 char mark;
 do
 {
  board();
  player=(player%2)?1:2;

  cout << "Player " << player << ", enter a number:  ";
  cin >> choice;

  mark=(player == 1) ? 'X' : 'O';

  if (choice == 1 && square[1] == '1')

   square[1] = mark;
  else if (choice == 2 && square[2] == '2')

   square[2] = mark;
  else if (choice == 3 && square[3] == '3')

   square[3] = mark;
  else if (choice == 4 && square[4] == '4')

   square[4] = mark;
  else if (choice == 5 && square[5] == '5')

   square[5] = mark;
  else if (choice == 6 && square[6] == '6')

   square[6] = mark;
  else if (choice == 7 && square[7] == '7')

   square[7] = mark;
  else if (choice == 8 && square[8] == '8')

   square[8] = mark;
  else if (choice == 9 && square[9] == '9')

   square[9] = mark;
  else
  {
   cout<<"Invalid move ";

   player--;
   cin.ignore();
   cin.get();
  }
  i=checkwin();

  player++;
 }while(i==-1);
 board();
 if(i==1)

  cout<<"==>\aPlayer "<<--player<<" win ";
 else
  cout<<"==>\aGame draw";

 cin.ignore();
 cin.get();
 return 0;
}

/*********************************************

 FUNCTION TO RETURN GAME STATUS
 1 FOR GAME IS OVER WITH RESULT
 -1 FOR GAME IS IN PROGRESS
 O GAME IS OVER AND NO RESULT
**********************************************/

int checkwin()
{
 if (square[1] == square[2] && square[2] == square[3])

  return 1;
 else if (square[4] == square[5] && square[5] == square[6])

  return 1;
 else if (square[7] == square[8] && square[8] == square[9])

  return 1;
 else if (square[1] == square[4] && square[4] == square[7])

  return 1;
 else if (square[2] == square[5] && square[5] == square[8])

  return 1;
 else if (square[3] == square[6] && square[6] == square[9])

  return 1;
 else if (square[1] == square[5] && square[5] == square[9])

  return 1;
 else if (square[3] == square[5] && square[5] == square[7])

  return 1;
 else if (square[1] != '1' && square[2] != '2' && square[3] != '3' 
                    && square[4] != '4' && square[5] != '5' && square[6] != '6' 
                  && square[7] != '7' && square[8] != '8' && square[9] != '9')

  return 0;
 else
  return -1;
}


/*******************************************************************
     FUNCTION TO DRAW BOARD OF TIC TAC TOE WITH PLAYERS MARK
********************************************************************/


void board()
{
 system("cls");
 cout << "\n\n\tTic Tac Toe\n\n";

 cout << "Player 1 (X)  -  Player 2 (O)" << endl << endl;
 cout << endl;

 cout << "     |     |     " << endl;
 cout << "  " << square[1] << "  |  " << square[2] << "  |  " << square[3] << endl;

 cout << "_____|_____|_____" << endl;
 cout << "     |     |     " << endl;

 cout << "  " << square[4] << "  |  " << square[5] << "  |  " << square[6] << endl;

 cout << "_____|_____|_____" << endl;
 cout << "     |     |     " << endl;

 cout << "  " << square[7] << "  |  " << square[8] << "  |  " << square[9] << endl;

 cout << "     |     |     " << endl << endl;
}

/*******************************************************************
    END OF PROJECT
********************************************************************/

Programmers Thought




Monday, 6 June 2016

Orange Line Train Project on C++ Language

//--------------------------------Project On Orange Line Train In Lahore -----------------------------------
#include <iostream>
#include <fstream>
using namespace std ;
int sales ();
int main ()
{
float c;
int n,a,b,d,cash,recieved,f,l,p;
double phone,acc,time ;
string pwd,line;
string arrayst[27]={"","Ali Town","Thokar Niaz Beg","Awan Town","Shah Noor","Band Road","Gulshan e Ravi","Leak Road","Lakshami","Sultan Pura","Bag Ban Pura","Pakistan Minute","Salam Pura","Canal Road","Wahdat Road","Sabza Zar","Salu hu Din","Samna Abad ","Chubragi","GPO","Railway Station","UET","Shalamar Bag","Mahood Booti ","Islam Park","Dera Gujran","Dera Gujran"};
float arraykm[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};

do
{
cout<<"                                                  "<<endl;
cout<<"                                                  "<<endl;
cout<<"                                                  "<<endl;
cout<<"                                                  "<<endl;
cout<<"      01 Routes \n      02 Timmings Of Trains \n      03 Rent & Tickets \n      04 Online Reservation \n      05 Services And Managment\n      06 Information About Project "<<endl;
cout<<"                                                  "<<endl;
cout<<"Enter Number That You Want TO Select (01--08)"<<endl;
cout<<"                                                  "<<endl;
cin>>n;
system("cls");
if (n==1)
{
cout<<"The Routes Of Train Are "<<endl;

cout<<"       1-Ali Town           "<<"2-Thokar Niaz Beg\t"<<endl;
cout<<"       3-Awan Town          "<<"4-Shah Noor\t"<<endl;
cout<<"       5-Band Road          "<<"6-Gulshan e Ravi\t"<<endl;
cout<<"       7-Leak Road          "<<"8-Lakshami\t"<<endl;
cout<<"       9-Sultan Pura        "<<"10-Bag Ban Pura\t"<<endl;
cout<<"       11-Pakistan Minute   "<<"12-Salam Pura\t"<<endl;
cout<<"       13-Canal Road        "<<"14-Wahdat Road\t"<<endl;
cout<<"       15-Sabza Zar         "<<"16-Salu hu Din\t"<<endl;
cout<<"       17-Samna Abad        "<<"18-Chubragi\t"<<endl;
cout<<"       19-GPO               "<<"20-Railway Station\t"<<endl;
cout<<"       21-UET               "<<"22-Shalamar Bag\t"<<endl;
cout<<"       23-Mahood Booti      "<<"24- Islam Park\t"<<endl;
cout<<"       25- Dera Gujran      "<<"26- Dera Gujran\t"<<endl;
}
if(n==2)
{
cout<<"Timmings Of Train Are "<<endl;
cout<<"Train Start in Morning 6:00 Am "<<endl<<"Train Close at 11:00 Pm in Night "<<endl;
}
if (n==3)
{
cout<<"               Rent And Tickets Are "<<endl<<endl;
cout<<"               Per KM is 10 Rs "<<endl<<endl;

cout<<"SELECT YOUR ROUTE "<<endl;

cout<<"       1-Ali Town           "<<"2-Thokar Niaz Beg\t"<<endl;
cout<<"       3-Awan Town          "<<"4-Shah Noor\t"<<endl;
cout<<"       5-Band Road          "<<"6-Gulshan e Ravi\t"<<endl;
cout<<"       7-Leak Road          "<<"8-Lakshami\t"<<endl;
cout<<"       9-Sultan Pura        "<<"10-Bag Ban Pura\t"<<endl;
cout<<"       11-Pakistan Minute   "<<"12-Salam Pura\t"<<endl;
cout<<"       13-Canal Road        "<<"14-Wahdat Road\t"<<endl;
cout<<"       15-Sabza Zar         "<<"16-Salu hu Din\t"<<endl;
cout<<"       17-Samna Abad        "<<"18-Chubragi\t"<<endl;
cout<<"       19-GPO               "<<"20-Railway Station\t"<<endl;
cout<<"       21-UET               "<<"22-Shalamar Bag\t"<<endl;
cout<<"       23-Mahood Booti      "<<"24- Islam Park\t"<<endl;
cout<<"       25-Cup Store         "<<"26- Dera Gujran\t"<<endl;
       
 d=sales();

   
}
if (n==4)
{
cout<<"Timmings Of Train Are "<<endl;
cout<<"Train Start in Morning 6:00 Am "<<endl<<"Train Close at 11:00 Pm in Night "<<endl;
cout<<"If u Want Reserve Your seat";
cout<<"Enter Timing \t Only Enter 6am+pm ,9am+pm ,12pm,3pm"<<endl;
cin>>time;
if (time==6 || time==9 || time==12 || time==3 )
{
cout<<"Valid Timmings"<<endl;
cout<<"        "<<endl;
cout<<"If u Want Reserve Your seat Please Enter The Number 410 else write wrong number "<<endl;
cin>>phone;
if(phone==410)
{
cout<<"Enter Station Number From Where You Want to Go"<<endl;
cout<<"       1-Ali Town           "<<"2-Thokar Niaz Beg\t"<<endl;
cout<<"       3-Awan Town          "<<"4-Shah Noor\t"<<endl;
cout<<"       5-Band Road          "<<"6-Gulshan e Ravi\t"<<endl;
cout<<"       7-Leak Road          "<<"8-Lakshami\t"<<endl;
cout<<"       9-Sultan Pura        "<<"10-Bag Ban Pura\t"<<endl;
cout<<"       11-Pakistan Minute   "<<"12-Salam Pura\t"<<endl;
cout<<"       13-Canal Road        "<<"14-Wahdat Road\t"<<endl;
cout<<"       15-Sabza Zar         "<<"16-Salu hu Din\t"<<endl;
cout<<"       17-Samna Abad        "<<"18-Chubragi\t"<<endl;
cout<<"       19-GPO               "<<"20-Railway Station\t"<<endl;
cout<<"       21-UET               "<<"22-Shalamar Bag\t"<<endl;
cout<<"       23-Mahood Booti      "<<"24- Islam Park\t"<<endl;
cout<<"       25-Cup Store         "<<"26- Dera Gujran\t"<<endl;
cout<<"From(Station no):"<<endl;
cin>>a;
cout<<"  "<<arrayst[a]<<endl;
cout<<"To(Station no):"<<endl;
cin>>b;
cout<<"  "<<arrayst[b]<<endl;
system("cls");
cout<<"From:"<<endl;
cout<<a<<"-"<<arrayst[a]<<endl;
cout<<"To:"<<endl;
cout<<b<<"-"<<arrayst[b]<<endl;
if(arraykm[a]>arraykm[b])
{
c=arraykm[a]-arraykm[b];
//cout<<arraykm[a]<<"-"<<arraykm[b]<<endl;
}
if(arraykm[a]<arraykm[b])
{
c=arraykm[b]-arraykm[a];
//cout<<arraykm[b]<<"-"<<arraykm[a]<<endl;
}
cout<<"                       Total km are  "<<c<<endl;
d=c*10;
cout<<"                     Total Bill is  "<<d<<" Rs"<<endl;
}

cout<<"Enter Your Account Number"<<endl;
cin>>acc;
cout<<"Thank You "<<d<<" Rs Charge From Your Account"<<endl;

}}


if(n==5)
{
cout<<"Enter the Pasword"<<endl;
cin>>pwd;
ifstream pasword("d:/password.txt");
if(pasword.is_open())
{
while(getline(pasword,line))
{

if(pwd==line)
{
cout<<"Welcome sir"<<endl;
//f=total sales
f=d+f;
cout<<"Total amaount of Today is "<<f<<endl;
d=1;
p=d+p;
l=p;
//l=total passengers
cout<<"Total paseengers of Today are "<<l<<endl;

}
else {cout<<"wrong pasword"<<endl;
}
}}}
if (n==6)
{
cout<<"This Project Is Started in 2015 and Should be Completed in 2018. This Is a Very Huge Project with Respect to their Properties and Charchteristics.";
cout<<" This is Very Long About to 27.1 kiloMeters. Having 26 Stations, 2 Undergrounded and 24 Elevated Stations.Minimum 2.5lacs People can Travel Each Day.";
cout<<" ";
}
cout<<"c to continue X to exit"<<endl;
cin>>pwd;
system("cls");
ofstream sales("d:/totals.txt");
if(sales.is_open())
{
sales<<"Total amount of today is"<<endl;
sales<<f<<endl;
sales<<"Total passengres of today is"<<endl;
sales<<l<<endl;
}
}
while (pwd!="x");

}
int sales ()
{

int a,b,d,
c,cash,recieved;
string arrayst[27]={"","Ali Town","Thokar Niaz Beg","Awan Town","Shah Noor","Band Road","Gulshan e Ravi","Leak Road","Lakshami","Sultan Pura","Bag Ban Pura","Pakistan Minute","Salam Pura","Canal Road","Wahdat Road","Sabza Zar","Salu hu Din","Samna Abad ","Chubragi","GPO","Railway Station","UET","Shalamar Bag","Mahood Booti ","Islam Park","Dera Gujran","Dera Gujran"};
float arraykm[27]={0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26};

cout<<"From(Station no):"<<endl;
cin>>a;
cout<<"  "<<arrayst[a]<<endl;
cout<<"To(Station no):"<<endl;
cin>>b;
cout<<"  "<<arrayst[b]<<endl;
system("cls");
cout<<"From:"<<endl;
cout<<a<<"-"<<arrayst[a]<<endl;
cout<<"To:"<<endl;
cout<<b<<"-"<<arrayst[b]<<endl;
if(arraykm[a]>arraykm[b])
{
c=arraykm[a]-arraykm[b];
//cout<<arraykm[a]<<"-"<<arraykm[b]<<endl;
}
if(arraykm[a]<arraykm[b])
{
c=arraykm[b]-arraykm[a];
//cout<<arraykm[b]<<"-"<<arraykm[a]<<endl;
}
cout<<"                       Total km are "<<c<<endl;
d=c*10;
cout<<"                     Total Bill is "<<d<<" Rs"<<endl;
cout<<"cash  ";
cin>>cash;
if(cash>=d)
{
recieved=cash-d;
cout<<"Recieved "<<recieved<<" Rs-------"<<endl;
}
else if(cash<d){
cout<<"insufficien money-----------"<<endl;

}
return d;
}

C++ Project Banking Management System

//***************************************************************
//                   HEADER FILE USED IN PROJECT
//****************************************************************

#include<iostream>
#include<fstream>
#include<cctype>
#include<iomanip>
using namespace std;

//***************************************************************
//                   CLASS USED IN PROJECT
//****************************************************************


class account
{
int acno;
char name[50];
int deposit;
char type;
public:
void create_account(); //function to get data from user
void show_account() const; //function to show data on screen
void modify(); //function to add new data
void dep(int); //function to accept amount and add to balance amount
void draw(int); //function to accept amount and subtract from balance amount
void report() const; //function to show data in tabular format
int retacno() const; //function to return account number
int retdeposit() const; //function to return balance amount
char rettype() const; //function to return type of account
};         //class ends here

void account::create_account()
{
cout<<"\nEnter The account No. :";
cin>>acno;
cout<<"\n\nEnter The Name of The account Holder : ";
cin.ignore();
cin.getline(name,50);
cout<<"\nEnter Type of The account (C/S) : ";
cin>>type;
type=toupper(type);
cout<<"\nEnter The Initial amount(>=500 for Saving and >=1000 for current ) : ";
cin>>deposit;
cout<<"\n\n\nAccount Created..";
}

void account::show_account() const
{
cout<<"\nAccount No. : "<<acno;
cout<<"\nAccount Holder Name : ";
cout<<name;
cout<<"\nType of Account : "<<type;
cout<<"\nBalance amount : "<<deposit;
}


void account::modify()
{
cout<<"\nAccount No. : "<<acno;
cout<<"\nModify Account Holder Name : ";
cin.ignore();
cin.getline(name,50);
cout<<"\nModify Type of Account : ";
cin>>type;
type=toupper(type);
cout<<"\nModify Balance amount : ";
cin>>deposit;
}


void account::dep(int x)
{
deposit+=x;
}

void account::draw(int x)
{
deposit-=x;
}

void account::report() const
{
cout<<acno<<setw(10)<<" "<<name<<setw(10)<<" "<<type<<setw(6)<<deposit<<endl;
}


int account::retacno() const
{
return acno;
}

int account::retdeposit() const
{
return deposit;
}

char account::rettype() const
{
return type;
}


//***************************************************************
//     function declaration
//****************************************************************
void write_account(); //function to write record in binary file
void display_sp(int); //function to display account details given by user
void modify_account(int); //function to modify record of file
void delete_account(int); //function to delete record of file
void display_all(); //function to display all account details
void deposit_withdraw(int, int); // function to desposit/withdraw amount for given account
void intro(); //introductory screen function

//***************************************************************
//     THE MAIN FUNCTION OF PROGRAM
//****************************************************************


int main()
{
char ch;
int num;
intro();
do
{
system("cls");
cout<<"\n\n\n\tMAIN MENU";
cout<<"\n\n\t01. NEW ACCOUNT";
cout<<"\n\n\t02. DEPOSIT AMOUNT";
cout<<"\n\n\t03. WITHDRAW AMOUNT";
cout<<"\n\n\t04. BALANCE ENQUIRY";
cout<<"\n\n\t05. ALL ACCOUNT HOLDER LIST";
cout<<"\n\n\t06. CLOSE AN ACCOUNT";
cout<<"\n\n\t07. MODIFY AN ACCOUNT";
cout<<"\n\n\t08. EXIT";
cout<<"\n\n\tSelect Your Option (1-8) ";
cin>>ch;
system("cls");
switch(ch)
{
case '1':
write_account();
break;
case '2':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
deposit_withdraw(num, 1);
break;
case '3':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
deposit_withdraw(num, 2);
break;
case '4':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
display_sp(num);
break;
case '5':
display_all();
break;
case '6':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
delete_account(num);
break;
case '7':
cout<<"\n\n\tEnter The account No. : "; cin>>num;
modify_account(num);
break;
case '8':
cout<<"\n\n\tThanks for using bank managemnt system";
break;
default :cout<<"\a";
}
cin.ignore();
cin.get();
}while(ch!='8');
return 0;
}


//***************************************************************
//     function to write in file
//****************************************************************

void write_account()
{
account ac;
ofstream outFile;
outFile.open("account.dat",ios::binary|ios::app);
ac.create_account();
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
outFile.close();
}

//***************************************************************
//     function to read specific record from file
//****************************************************************

void display_sp(int n)
{
account ac;
bool flag=false;
ifstream inFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<"\nBALANCE DETAILS\n";

    while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
if(ac.retacno()==n)
{
ac.show_account();
flag=true;
}
}
inFile.close();
if(flag==false)
cout<<"\n\nAccount number does not exist";
}


//***************************************************************
//     function to modify record of file
//****************************************************************

void modify_account(int n)
{
bool found=false;
account ac;
fstream File;
File.open("account.dat",ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&ac), sizeof(account));
if(ac.retacno()==n)
{
ac.show_account();
cout<<"\n\nEnter The New Details of account"<<endl;
ac.modify();
int pos=(-1)*static_cast<int>(sizeof(account));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&ac), sizeof(account));
cout<<"\n\n\t Record Updated";
found=true;
 }
}
File.close();
if(found==false)
cout<<"\n\n Record Not Found ";
}

//***************************************************************
//     function to delete record of file
//****************************************************************


void delete_account(int n)
{
account ac;
ifstream inFile;
ofstream outFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
outFile.open("Temp.dat",ios::binary);
inFile.seekg(0,ios::beg);
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
if(ac.retacno()!=n)
{
outFile.write(reinterpret_cast<char *> (&ac), sizeof(account));
}
}
inFile.close();
outFile.close();
remove("account.dat");
rename("Temp.dat","account.dat");
cout<<"\n\n\tRecord Deleted ..";
}

//***************************************************************
//     function to display all accounts deposit list
//****************************************************************

void display_all()
{
account ac;
ifstream inFile;
inFile.open("account.dat",ios::binary);
if(!inFile)
{
cout<<"File could not be open !! Press any Key...";
return;
}
cout<<"\n\n\t\tACCOUNT HOLDER LIST\n\n";
cout<<"====================================================\n";
cout<<"A/c no.      NAME           Type  Balance\n";
cout<<"====================================================\n";
while(inFile.read(reinterpret_cast<char *> (&ac), sizeof(account)))
{
ac.report();
}
inFile.close();
}

//***************************************************************
//     function to deposit and withdraw amounts
//****************************************************************

void deposit_withdraw(int n, int option)
{
int amt;
bool found=false;
account ac;
fstream File;
File.open("account.dat", ios::binary|ios::in|ios::out);
if(!File)
{
cout<<"File could not be open !! Press any Key...";
return;
}
while(!File.eof() && found==false)
{
File.read(reinterpret_cast<char *> (&ac), sizeof(account));
if(ac.retacno()==n)
{
ac.show_account();
if(option==1)
{
cout<<"\n\n\tTO DEPOSITE AMOUNT ";
cout<<"\n\nEnter The amount to be deposited";
cin>>amt;
ac.dep(amt);
}
if(option==2)
{
cout<<"\n\n\tTO WITHDRAW AMOUNT ";
cout<<"\n\nEnter The amount to be withdraw";
cin>>amt;
int bal=ac.retdeposit()-amt;
if((bal<500 && ac.rettype()=='S') || (bal<1000 && ac.rettype()=='C'))
cout<<"Insufficience balance";
else
ac.draw(amt);
}
int pos=(-1)*static_cast<int>(sizeof(ac));
File.seekp(pos,ios::cur);
File.write(reinterpret_cast<char *> (&ac), sizeof(account));
cout<<"\n\n\t Record Updated";
found=true;
      }
         }
File.close();
if(found==false)
cout<<"\n\n Record Not Found ";
}


//***************************************************************
//     INTRODUCTION FUNCTION
//****************************************************************


void intro()
{
cout<<"\n\n\n\t  BANK";
cout<<"\n\n\tMANAGEMENT";
cout<<"\n\n\t  SYSTEM";
cout<<"\n\n\n\nMADE BY : your name";
cout<<"\n\nSCHOOL : your school name";
cin.get();
}

//***************************************************************
//     END OF PROJECT
//***************************************************************

Notepad++