Monday, August 15, 2011

A project on Bird Survey

A project on Bird Survey by using object oriented programming

/* declaring header files */

#include<iostream.h>
#include<conio.h>
#include<stdio.h>

class bird{
   
    private:
    char name[50],colour[50],nature[50],origin[50];
    float life;
       
    public:
    int code;
    void getdata(){
        cout<<"\nEnter bird's name: "; gets(name);
        cout<<"Colour: "; gets(colour);
        cout<<"Nature: "; gets(nature);
        cout<<"Origin: "; gets(origin);
        cout<<"Life time: "; cin>>life;
        cout<<"Bird's code: "; cin>>code;
        }
    void display(){
        cout<<"\nBird's name: "<<name;
        cout<<"\nColour     : "<<colour;
        cout<<"\nNature     : "<<nature;
        cout<<"\nOrigin     : "<<origin;
        cout<<"\nLife time  : "<<life<<" year";
        cout<<"\nCode       : "<<code;
        }
    }b[100];

void main(){
    clrscr();
    int i,j,k,index;
    do
         {
           cout<<"\n\nWhat do you want to do\n1.Input bird's information"
           <<"\n2.Display\n3.Search\n4.Exit."
           <<"\n\nChoose appropriate number: ";
           cin>>index;

           switch(index)
             {
              case 1:
                 cout<<"Enter the number of bird how many to input: ";
                 cin>>j;
                 for(i=1;i<=j;i++)
                 {
                 cout<<"\nInformation of Bird "<<i<<".\n";
                 b[i].getdata();
                 }
                 break;

               case 2:
                  for(i=1;i<=j;i++)
                 {
                  cout<<"\nBird no "<<i<<".\n";
                  b[i].display();
                 cout<<"\n";
                 }
                 break;

               case 3:
                 cout<<"\nEnter the bird code: ";
                 cin>>k;

                 for(i=1;i<=j;i++)
                  {
                 if(k==b[i].code)
                    {
                     cout<<"\nBird no "<<i<<".\n";
                     b[i].display();
                     break;
                    }
                   }
                 if(k!=b[i].code)
                   cout<<"Wrong code input...\n";
                  break;

               case 4:
                  break;

               default:
                  cout<<"Wrong choice\nPlease enter correct number.";
                  break;
             }

         }while(index!=4);
  }

No comments:

Post a Comment

Vision