Showing posts with label programming. Show all posts
Showing posts with label programming. Show all posts

Thursday, 25 July 2013

Difference between classes and structures in c++.

Simple but many(or few) people misunderstood or are a not aware ability of structure in cpp to hold both member functions and data members.
                In C++, structure can have both variables and functions as members.It can also declare some of its members as 'private' so that they cannot be accessed directly by the external functions.Since class is a specially introduced data type in C++, most of programmers use the structures for holding only data, and classes to hold both the data and the functions.The only difference between a structure and a class is that structure members have public access by default and class members have private access by default, you can use the keywords class or struct to define equivalent classes.

Example:


struct employee
{
private:      //c++ structures can have access labels
int emp_no;
protected:
float salary;
public:
void getdata()   //c++ sturctures can hold both member functions and data members
{
cin>>emp_no>>salary;
}
void putdata()
{
cout<<emp_no<<salary;
}
}object1;
void main()
{
object1.getdata();
object1.putdata();
}

External Links:

http://en.wikibooks.org/wiki/C%2B%2B_Programming/Structures

http://en.wikipedia.org/wiki/C%2B%2B_classes 

Monday, 3 June 2013

non graphical cricket game program code with c++

cricket game coded with c++:
  • user have choice to select team and opponent form three given teams - INDIAN team, AUSTRALIAN team, PAKISTAN team.
  • tossing available
  • 2 over game
  • 3 wickets
  • allows you to play game completely( ball- 2 overs, bat- 2 overs)
  •  based on numbers
coded by Noah Paul Jose .

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
int wkt=0,tm,op;
char *batsman;
void play(int);
void batsmann(int);
void bowler(int);
void main()
{
clrscr();
textbackground(WHITE);
textcolor(4);
clrscr();
int tos;
char toss;
cout<<"\n\n\n\n\n\n\n\n\n\n::::::==::==::==::==::==::==::::*****CRICKET*****::::==::==::==::==::==::==:::::\n ";
getch();
cout<<"\n                           noah @ my own creations";
getch();
cout<<" \n\n\n                         PLUS ONE - COMPUTER SCIENCE";
getch();
clrscr();
textbackground(YELLOW); 
textcolor(4);
clrscr();
cout<<"\n\n\n                        S=E=L=E=C=T   Y=O=U=R   T=E=A=M";
cout<<"\n\n\n\n                               ##:-FOR INDIA  1";
cout<<"\n\n\n\n\n                            ##:-FOR PAKSITAN  2";
cout<<"\n\n\n\n\n                           ##:-FOR AUSTRALIA  3";
cout<<"\n\n\n                         ENTER YOUR CHOICE::-  "; 
cin>>tm;
clrscr();
cout<<"\n\n\n                            ::::P=L=A=Y=E=R=S::::";
switch(tm)
  {
  case 1:
       {
       india: 
       cout<<" - Indian Team\n\n\n";
       cout<<"                         ##:- Sachin Tendulkar\n\n";
       cout<<"                         ##:- Yuvaraj Singh\n\n";    
       cout<<"                         ##:- Harbhajan Singh\n\n\n";
       break;
       }
  case 2:
        {
        cout<<" - Pakistan Team\n\n\n";
        cout<<"                        ##:- Taufeeq Umar\n\n";
        cout<<"                        ##:- Shahid Afridi\n\n";
        cout<<"                        ##:- Saeed Ajmal\n\n\n";
        break;
        }
  case 3:
        {
        cout<<" - Australian Team\n\n\n";
        cout<<"                        ##:- Michael Clarke\n\n";
        cout<<"                        ##:- Mitchell Johnson\n\n";
        cout<<"                        ##:- Nathan Lyon\n\n\n\n";
        break;
        }
 default:
        {
        tm=1;
        cout<<" - AUTO SELECTION(Team India)\n\n\n";
        cout<<"        YOU MADE AN INVALID CHOICE, SO YOUR TEAM IS AUTOMATICALLY SELECTED\n\n\n\n";
        goto india;
        }
  }
getch();
clrscr();
cout<<"\n\n\n                S=E=L=E=C=T   Y=O=U=R   O=P=P=O=N=E=N=T T=E=A=M                 ";
cout<<"\n\n\n\n                               ##:-FOR INDIA  1";
cout<<"\n\n\n\n\n                            ##:-FOR PAKSITAN  2";
cout<<"\n\n\n\n\n                           ##:-FOR AUSTRALIA  3";
cout<<"\n\n\n                         ENTER YOUR CHOICE::-  "; 
cin>>op;
clrscr();
cout<<"\n\n\n                            ::::P=L=A=Y=E=R=S::::";
switch(op)
  {
  case 1:
       {
       if(op!=tm)
       {
       cout<<" - Indian Team\n\n\n";
       cout<<"                         ##:- Sachin Tendulkar\n\n";
       cout<<"                         ##:- Yuvaraj Singh\n\n";    
       cout<<"                         ##:- Harbhajan Singh\n\n\n";
       break;
       }
       else
       {
       goto bottom;
       
       }
       }
  case 2:
        {
        if(op!=tm)
        {
        cout<<" - Pakistan Team\n\n\n";
        cout<<"                        ##:- Taufeeq Umar\n\n";
        cout<<"                        ##:- Shahid Afridi\n\n";
        cout<<"                        ##:- Saeed Ajmal\n\n\n";
        break;
        }
        else
        {
        goto bottom;
        
        }
        }
  case 3:
        {
        if(op!=tm)
        {
        cout<<" - Australian Team\n\n\n";
        cout<<"                        ##:- Michael Clarke\n\n";
        cout<<"                        ##:- Mitchell Johnson\n\n";
        cout<<"                        ##:- Nathan Lyon\n\n\n\n";
        break;
        }
        else
        {
        goto bottom;
        }
        }
  case 4:
        {
        english:
        {
        cout<<" - English Team\n\n\n";
        cout<<"                        ##:- Alastair Cook\n\n";
        cout<<"                        ##:- Ian Bell\n\n";
        cout<<"                        ##:- James Anderson\n\n\n\n";
        break;
        }
        }
 default:
        {
        bottom:
        {
        op=4;
        cout<<" -AUTO SELECTION\n\n\n";
        cout<<"        YOU MADE AN INVALID CHOICE, SO YOUR TEAM IS AUTOMATICALLY SELECTED\n\n\n\n";
        goto english;
        }
       }
     }
getch();
clrscr();
textbackground(WHITE);
clrscr();
cout<<" .............................YOUR GAME IS LOADING.............................";
cout<<"\n\n                       G::A::M::E    D::E::T::A::I::L::S";      
cout<<"\n\n      @ 12 Ball Game";
cout<<"\n\n      @ Each Team Have THREE Wickets";
cout<<"\n\n      @ Only Use Keys From 1 ,upto 6";
cout<<"\n\n      @ Using Of Any Other Key Is Considered As: \n";
cout<<"               While Batting: Loss Of 1 WICKET ";
cout<<"\n\n               While Bowling: Wide Ball";    
cout<<"\n\n\n\n\n                        TOSS(b= Batting,t= Bowling): ";
cin>>toss;
toss=tolower(toss);
if(toss=='b')
{
cout<<"\n\n                            You Choose To Bat First";
tos=1;
}
if(toss=='t')
{
cout<<"\n\n                            You Choose To Bowl First";
tos=2;
}
if(toss!='b' && toss!='t')
{
cout<<"\n\n            YOU MADE AN INVALID CHOICE, SO YOUR TOSS IS AUTOMATICALLY SELECTED";
cout<<"\n\n                               Auto Selected- Bat First";
tos=1;
}
play(tos);
 getch();
}

void play(int tes)
{
clrscr();
textbackground(YELLOW); 
textcolor(4);
clrscr();
int ovrbat,ovrbt,wkt=0,runs=0,i,b,runsop=0;
if(tes==1)
{
for(ovrbt=0;ovrbt<12 && wkt<3;ovrbt++)
{
                cout<<"\n\n\n\n       BALLS:: "<<ovrbt;
                cout<<"WICKET::-"<<wkt;
                
                
                cout<<"  BATSMAN: ";
                batsmann(wkt);
                
                cout<<"Enter Runs::- ";
                cin>>i;
                ovrbat=rand() % 6 + 1;
                cout<<"Bowler Shows::- "<<ovrbat;
                if(i!=ovrbat && i<7)
                {runs=runs+i;
                cout<<"Your Current Score::- "<<runs;}
                        else
{
                        cout<<batsman;
                        cout<<" Is Out";
wkt++;}
                }
        cout<<"Total Score::- "<<runs;
         
        cout<<"::INNINGS OVER:: ";
        cout<<"\n\n\n\n\nYOUR OPPONENT IS WAITING AHEAD FOR THE WAR";
        getch();
        clrscr();
for(ovrbt=0,wkt=0;ovrbt<12 && wkt<3 && runs>=runsop;ovrbt++)
{
                cout<<"\n\n\n\n       BALLS:: "<<ovrbt;
                cout<<"WICKET::-"<<wkt;
               
                
                 cout<<"  BATSMAN: ";
               bowler(wkt);
                cout<<"You Need To Ball::- ";
                cin>>i;
                ovrbat = rand() % 6 + 1;
cout<<"Batter Shows::- "<<ovrbat;
if(i!=ovrbat && i<7)
{runsop=runsop+ovrbat;
                cout<<"Opponents Current Score::- "<<runsop;}
                        else
{
if(i==ovrbat)
                        {cout<<batsman;
                        cout<<"Is Out";wkt++;}
                                else
                                {runsop=runsop+1;
cout<<"Opponents Current Score::- "<<runsop;ovrbt=ovrbt-1;}
                        }
}
        cout<<"::INNINGS OVER:: ";
  else
        {  
               for(ovrbt=0;ovrbt<12 && wkt<3;ovrbt++)
{
                cout<<"\n\n\n\n       BALLS:: "<<ovrbt;
                cout<<"WICKET::-"<<wkt;
               
                
                 cout<<"  BATSMAN: ";
                
                bowler(wkt);
                cout<<"You Need To Ball::- ";
                cin>>i;
                ovrbat = rand() % 6 + 1;
cout<<"Batter Shows::- "<<ovrbat;
if(i!=ovrbat && i<7)
{runsop=runsop+ovrbat;
                cout<<"Opponents Current Score::- "<<runsop;}
                        else
{
if(i==ovrbat)
                        {cout<<batsman;
                        cout<<"Is Out";wkt++;}
                                else
                                {runsop=runsop+1;
cout<<"Opponents Current Score::- "<<runsop;ovrbt=ovrbt-1;}
                        }
}
                
               cout<<"Opponent Scored::- "<<runsop;
                
               cout<<"::INNINGS OVER:: ";
               cout<<"\n\n\n\n\nGO AHEAD FOR THE WAR";
               getch();
               clrscr();
               for(ovrbt=0,wkt=0;ovrbt<12 && wkt<3 && runsop>=runs;ovrbt++)
{
                cout<<"\n\n\n\n       BALLS:: "<<ovrbt;
                cout<<"WICKET::-"<<wkt;
                
                
                cout<<"  BATSMAN: ";
                batsmann(wkt);
                
                cout<<"Enter Runs::- ";
                cin>>i;
                ovrbat=rand() % 6 + 1;
                cout<<"Bowler Shows::- "<<ovrbat;
                if(i!=ovrbat && i<7)
                {runs=runs+i;
                cout<<"Your Current Score::- "<<runs;}
                        else
{
                        cout<<batsman;
                        cout<<" Is Out";
wkt++;}
                }
       }




if(runs>runsop)
{
        cout<<"You Won";
        getch();
        clrscr();
        exit(0);
}
else
{
if(runsop>runs)
{
cout<<"You Lose";
                getch();
                clrscr();
                exit(0);
}
else
{
cout<<"DRAW game";
                getch();
                clrscr();
                exit(0);
}
}
return;
 }


void batsmann(int wkt)
{
if(tm==1)
{
if(wkt==0){
 cout<<"S.Tendulkar";
batsman= "Tendulkar";
 }
if(wkt==1){
 cout<<"Yuvaraj Singh";
batsman= "Yuvaraj";
}
if(wkt==2){
 cout<<"Harbhajan Singh";
batsman= "Bhaaji";
}
}
if(tm==2)
{
if(wkt==0){
 cout<<"Taufeeq Umar";
batsman= "TUmar";
}
if(wkt==1){
 cout<<"Shahid Afridi";
batsman= "Afridi";
}
if(wkt==2){
 cout<<"Saeed Ajmal";
batsman= "Ajmal";
}
}
if(tm==3)
{
if(wkt==0){
 cout<<"Michael Clarke";
batsman= "Clarke";
}
if(wkt==1){
 cout<<"Mitchell Johnson";
batsman= "Johnson";
}
if(wkt==2){
 cout<<"Nathan Lyon";
batsman= "Lyon";
}
}
return;
 }



void bowler(int wkt)
{


if(op==1)
{
if(wkt==0){
 cout<<"S.Tendulkar";
batsman= "Tendulkar";
 }
if(wkt==1){
 cout<<"Yuvaraj Singh";
batsman= "Yuvaraj";
}
if(wkt==2){
 cout<<"Harbhajan Singh";
batsman= "Bhaaji";
}
}
if(op==2)
{
if(wkt==0){
 cout<<"Taufeeq Umar";
batsman= "TUmar";
}
if(wkt==1){
 cout<<"Shahid Afridi";
batsman= "Afridi";
}
if(wkt==2){
 cout<<"Saeed Ajmal";
batsman= "Ajmal";
}
}
if(op==3)
{
if(wkt==0){
 cout<<"Michael Clarke";
batsman= "Clarke";
}
if(wkt==1){
 cout<<"Mitchell Johnson";
batsman= "Johnson";
}
if(wkt==2){
 cout<<"Nathan Lyon";
batsman= "Lyon";
}
}
if(op==4)
{
if(wkt==0){
 cout<<"Alastair Cook";
batsman= "Cook";
}
if(wkt==1){
 cout<<"Ian Bell";
batsman= "Bell";
}
if(wkt==2){
 cout<<"James Anderson";
batsman= "Anderson";
}
}
return;
}


compiled and tested with:
thank you - noah paul

Thursday, 30 May 2013

download turbo c++ 4.5 compiler for windows..

turbo c++ 4.5 compiler with exception handling

DOWNLOAD YOUR FILE HERE


windows executive .rar file uploaded in datafilehost.com.

how to install your downloaded file:

  • unzip downloaded .rar 
  • open the extracted folder 
  • double click on install.exe 
  • follow instructions ,complete installation and enjoy your coding

first usage:

  • open installed directory (C:\TCWIN45 by default)
  • open folder named "bin"
  • double click on "TCW" (executive file) 
  • enjoying coding
thank you 

Saturday, 20 April 2013

20+ simple cpp programs for beginners

Index:

1. my first cpp program
2. adding two numbers
3. find larger among two numbers - if..else
4. numbers entered are
5. prefix operator
6. find larger of three - nested if
7. print 1 to 5 - for loop
8. multiplication table
9. finding big number - conditional operator
10. finding day - switch
11. total passed or failed
12. print even numbers below 5o
13. sum of natural numbers below 100
14. array displaying entered number
15. search for an item in array
16. binary search
17. count characters of a string
18. love calculator version 1.1
19. insertion unsorted array
20. insertion sorted array
21. matrix addition
22. printing pattern
                           Download Here