Saturday, 5 July 2014

C++ Interview Questions and Answers

  1. What is the difference between new/delete and malloc(), free()?
  2. What if we allocate memory using new and release it with free()?
  3. Why do we need virtual destructors?
  4. C++ compiler provides a copy costructor and overloaded assignment operator by default, why do we need to write our own copy constructors?
  5. Have you ever used STL, why do we use STL, if yes then what containers?
  6. What are function pointers?
  7. What happens when a callback funtion is called?
  8. Differences between C and C++?
  9. Write a program in C language which prints "Hello World!" on screen, without using even a single semi colon ';'.
  10. Swap two integers without using a third one.
  11. Why do we need pure virtual functions?
  12. What are friend functions?



    For answers, Click here



    And now, some questions for practice, you will have to find the answers by yourself.
    Feel free to write the answers to these questions in the comments.
  13. What is the difference between a pointer and array?
  14. Is it possible to find out the size of an array?
  15. What is NULL?
  16. How can we find if a pointer contains a valid value or not?
  17. We have a circular linked list, and its tail -> next is not pointing to List -> Head. How can we diagnose such an error condition? 

For more questions to practice, click on the Questions??? tab and access the world of C++ questions and answers.

Saturday, 3 May 2014

Cruise Travel Management

//A Project On Cruise Travel Management
//A Project for Intermediate Programmers
//A Program By Karun Jaycee (karunjaycee987@gmail.com )



#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>
#include<ctype.h>
#include<stdlib.h>
#include<iomanip.h>
long int code;
class persdetails  //class for collecting the personal details
{
  int trvlcode;
  int  age[20];
  char name[20][20];
  char add[50];
  char phnum[15];
  char sex[20];
  char passnum[10][10];
  char familyname[30];
  int num;
  int numppl;
  public:
  void p_input(int);
  void p_output();
  void givefam();
  int givecode();
  int give();
}pob;
int persdetails::give()
{
  return num;
}
void persdetails::givefam()
{
  cout<<familyname;
}
int persdetails::givecode()
{
  return trvlcode;
}
void persdetails::p_input(int cd)  //input func() of class1
{
  trvlcode=cd;
  num=0;
  clrscr();
  cout<<"\n\n\t:::::::::::::::::::::: PERSONAL DETAILS ::::::::::::::::::::::\n";
  cout<<"\t\t\t\t~~~~~~~~~~~~~~\n";
  cout<<"\n\t\t* Please fill in the details:\n\n\n\t\t\t1.Family Name: ";
  gets(familyname);
  cout<<"\n\t\t\t2.Address: ";
  gets(add);
  cout<<"\n\t\t\t3.Contact Number(10 Digit Mobile Number) : ";
  gets(phnum);
  cout<<"\n\n\n\t\tEnter The No of People Travelling: ";
  cin>>numppl;
  clrscr();
  if(numppl>0)
  {
    cout<<"\n\t\tPlease Enter The Details of each Member/Members: "<<endl;
    cout<<"\t\t \n";
    for(int i=0;i<numppl;i++)
    {
      cout<<endl<<"\n\t\tMember "<<i+1;
      cout<<"\n\t\t~~~~~~~~";
      cout<<"\n\n\t\tFirst Name: ";
      gets(name[i]);
      cout<<"\n\t\tAge: ";
      cin>>age[i];
      cout<<"\n\t\tSex (M/F): ";
      cin>>sex[i];
      cout<<"\n\t\tPassport Number: ";
      gets(passnum[i]);
      if(age[i]>5)
      {
num++;    //to calculate no of travellers below 5 yrs
      }
    }
  }
}
void persdetails::p_output() //output func() of class1
{
  clrscr();
  cout<<"\n\n\t ******************** PERSONAL DETAILS ******************** "<<endl;
  cout<<"\n\n\t\t\tFamily Name:\t "<<familyname<<endl;
  cout<<"\t\t\tAddress:\t "<<add<<endl;
  cout<<"\t\t\tPhone Number:\t "<<phnum<<endl;
  cout<<"\n\n\tName\t\tAge\t\tSex\t\tPassport Number\n"<<endl;
  for(int i=0;i<numppl;i++)
  {
    cout<<"\t"<<name[i]<<"\t\t"<<age[i]<<"\t\t"<<sex[i]<<"\t\t"<<passnum[i]<<endl;
  }
  getch();
}
class travdetails   //class which holds the travel details
{
  int trvtcode;
  int day;
  int month;
  int year;
  int num1;
  int bdg_pt;
  int go_pt;
  int deck;
  int cabin;
  int pool;
  int gym;
  int sports;
  int salon;
  int spa;
  int theatre;
  public:
  void initial();
  void t_input(int);
  void t_output();
  void compute();
  int gtcode();
  void accept(int);
}tob;
void travdetails::initial()
{
  pool=gym=theatre=sports=salon=0;
}
void travdetails::accept(int c)
{
  num1=c;
}
int travdetails::gtcode()
{
  return trvtcode;
}
void travdetails::t_input(int cd) //input func()-class2
{
  tob.initial();
  trvtcode=cd;
  int i=1,opt;
  clrscr();
  do
  {
    clrscr();
    cout<<endl;
    cout<<"\n\n\t\t\t\t_||__TRAVEL DETAILS__";
    cout<<"\n\t\t\t\t\\___________________/";
    cout<<"\n\t\t\t\t~~~~~~~~~~~~~~~~~~~~~~";
    cout<<"\n\n\t\tPlease enter the following details for your journey:";
    cout<<"\n\n\t\t*Note:Options marked with '*' are compulsory.\n\t\t\tPlease do select them.";
    cout<<"\n\n\n\t\t\t\t*1.Boarding Point\n\t\t\t\t*2.Destination\n\t\t\t\t*3.Date of Departure\n\t\t\t\t*4.Deck\n\t\t\t\t 5.Cabin\n\t\t\t\t 6.Swimming Pool\n\t\t\t\t 7.Gymnasuim\n\t\t\t\t 8.Sports\n\t\t\t\t 9.Salon\n\t\t\t\t 10.Spa\n\t\t\t\t 11.Theatre\n\t\t\t\t 12.Back\n\n\t\t\t\t ";
    cin>>opt;
    switch(opt)
    {
      case 1:clrscr();
    cout<<"\n\n\n\t\t\tSelect Boarding point:\n\n\t\t\t1.Mumbai\n\n\t\t\t2.Cochin\n\n\t\t\t3.Chennai\n\n\t\t\t ";
    cin>>bdg_pt;
    break;
      case 2:clrscr();
    cout<<"\n\n\t\t\t****** Select Destination ******\n\n\n";
    cout<<"\t 1.New York\t\t6.Dubai\t\t\t11.Antananariv";
    cout<<"\n\n\t 2.Miami\t\t7.Lisbon\t\t12.Cairo\n\n";
    cout<<"\t 3.Rio De Janeiro\t8.London\t\t13.Perth";
    cout<<"\n\n\t 4.Colombo\t\t9.Copenhagen\t\t14.Sydney";
    cout<<"\n\n\t 5.Hong Kong\t\t10.Cape Town\t\t15.Wellington\n\n\n\n\n\t\t\t\t ";
    cin>>go_pt;
    break;
      case 3:clrscr();
    cout<<"\n\n\t Date of Departure ";
    cout<<"\n\n   * Note:Format for entering:Day(press enter)Month(press enter)Year *";
    cout<<"\n\n\t\tEnter your preferred date of departure: ";
    cin>>day;
    gotoxy(59,7);   //to create a paricular format for entry
    cout<<"/";
    cin>>month;
    gotoxy(62,7);
    cout<<"/";
    cin>>year;
    break;
      case 4:clrscr();
    cout<<"\n\n\t\t\tEnter The Choice OF Deck\n\n\t\t\t1.Top Deck\n\n\t\t\t2.Middle Decks\n\n\t\t\t3.Bottom Deck\n\n\t\t\t ";
    cin>>deck;
    break;
      case 5:clrscr();
    cout<<"\n\n\t\t\tEnter The Choice Of Cabin\n\n\t\t\t1.AC\n\n\t\t\t2.Non AC\n\n\t\t\t ";
    cin>>cabin;
    break;
      case 6:clrscr();
    cout<<"\n\n\t\tDo You Like To Avail The Facility Of A Swimming Pool\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t ";
    cin>>pool;
    pool--;
    break;
      case 7:clrscr();
    cout<<"\n\n\t\tDo You Like To Avail The Facility Of A Gymnasium\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t ";
    cin>>gym;
    gym--;
    break;
      case 8:clrscr();
    cout<<"\n\n\t\tDo You Like To Avail The Sports Facilities Offered\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t ";
    cin>>sports;
    sports--;
    break;
      case 9:clrscr();
    cout<<"\n\n\t\tDo You Like To Avail The Facility Of Beauty Salon\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t ";
    cin>>salon;
    salon--;
    break;
     case 10:clrscr();
    cout<<"\n\n\tDo You Like To Avail The Facility Of Spa and Ayurvedic Treatment\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t ";
    cin>>spa;
    spa--;
    break;
     case 11:clrscr();
    cout<<"\n\n\t\tDo You Like To Avail The Facility Of Amphitheatre\n\n\t\t\t1.No\n\n\t\t\t2.Yes\n\n\t\t\t ";
    cin>>theatre;
    theatre--;
    break;
     case 12:i=0;
    break;
    }
  }while(i==1);
}
void boardpt(int c)  //for easy o/p
{
  if(c==1)
  cout<<"Mumbai\t";
  if(c==2)
  cout<<"Cochin\t";
  if(c==3)
  cout<<"Chennai\t";
}
void dest(int d)  //for easy o/p
{
  switch(d)
  {
    case 1:cout<<"New York";
  break;
    case 2:cout<<"Miami";
  break;
    case 3:cout<<"Rio De Janero";
  break;
    case 4:cout<<"Colombo";
  break;
    case 5:cout<<"Hong Kong";
  break;
    case 6:cout<<"Dubai";
  break;
    case 7:cout<<"Lisbon";
  break;
    case 8:cout<<"London";
  break;
    case 9:cout<<"Copenhagen";
  break;
   case 10:cout<<"Cape Town";
  break;
   case 11:cout<<"Antananriv";
  break;
   case 12:cout<<"Cairo";
  break;
   case 13:cout<<"Perth";
  break;
   case 14:cout<<"Sydney";
 break;
   case 15:cout<<"Willington";
break;
  }
}
void travdetails::t_output()  //output func()-class2
{
  clrscr();
  cout<<"\n\n\t ******************* TRAVEL DETAILS ********************* ";
  cout<<"\n\n\t\tBoarding Point: ";
  boardpt(bdg_pt);
  cout<<"\n\n\t\tDestination: ";
  dest(go_pt);
  cout<<"\n\n\t\tDate of departure: ";
  cout<<day<<"/"<<month<<"/"<<year;
  cout<<"\n\n\t\tDeck: ";
  switch(deck)
  {
    case 1:cout<<"Top Deck";
  break;
    case 2:cout<<"Middle Deck";
  break;
    case 3:cout<<"Bottom Deck";
  break;
  }
  cout<<"\n\n\t\tCabin: ";
  switch(cabin)
  {
    case 1:cout<<"AC cabin";
  break;
    case 2:cout<<"Non-AC cabin";
  break;
  }
  cout<<"\n\n\n\tFacilities availed for are:";
  if(pool==1)
  cout<<"\n\t\t\t\t    Swimming Pool";
  if(gym==1)
  cout<<"\n\t\t\t\t    Gymnasuim";
  if(sports==1)
  cout<<"\n\t\t\t\t    Sports Facilities";
  if(spa==1)
  cout<<"\n\t\t\t\t    Spa and Ayurvedic Treatment";
  if(salon==1)
  cout<<"\n\t\t\t\t    Beauty Salon";
  if(theatre==1)
  cout<<"\n\t\t\t\t    Theatre";
  getch();
}
void family(int c,int&flag)  //to display familyname+to check for record
{
  flag=0;
  clrscr();
  ifstream ifl("PersonalDetails.txt",ios::binary);
  if(!ifl)
  cout<<"\nError";
  ifl.read((char*)&pob,sizeof(pob));
  while(!ifl.eof())
  {
    if(pob.givecode()==c)
    {
      flag=1;
      break;
    }
    ifl.read((char*)&pob,sizeof(pob));
  }
  if(flag==1)
  {
    cout<<"\n\n\t\t ****** ";
    pob.givefam();
    cout<<"'s FAMILY DATABASE ******";
  }
  else
  {
    cout<<"\nError in locating record!!";
  }
  ifl.close();
}
void editp(int c)  //to edit persdetails
{
  ofstream ofl2("temp1.txt",ios::binary);
  if(!ofl2)
  cout<<"Error While Opening File";
  ifstream ifl4("PersonalDetails.txt",ios::binary);
  if(!ifl4)
  cout<<"Error While Opening File";
  ifl4.read((char*)&pob,sizeof(pob));
  while(!ifl4.eof())
  {
    if(pob.givecode()==c)
    {
      clrscr();
      cout<<"Please Enter the New details of the record"<<endl;
      pob.p_input(c);
      ofl2.write((char*)&pob,sizeof(pob));
      cout<<"\n\t\t\tModification Succesful!!!";
      ifl4.read((char*)&pob,sizeof(pob));
    }
    else
    {
      ofl2.write((char*)&pob,sizeof(pob));
      ifl4.read((char*)&pob,sizeof(pob));
    }
  }
  remove("PersonalDetails.txt");
  rename("temp1.txt","PersonalDetails.txt");
  ifl4.close();
  ofl2.close();
  getch();
}
void editt(int c)  //to edit travdetails
{
  ofstream ofl2("temp1.txt",ios::binary);
  if(!ofl2)
  cout<<"Error While Opening File";
  ifstream ifl4("TravelDetails.txt",ios::binary);
  if(!ifl4)
  cout<<"Error While Opening File";
  ifl4.read((char*)&tob,sizeof(tob));
  while(!ifl4.eof())
  {
    if(tob.gtcode()==c)
    {
      clrscr();
      cout<<"Please Enter the New details of the record"<<endl;
      tob.t_input(c);
      ofl2.write((char*)&tob,sizeof(tob));
      cout<<"\n\t\t\tModification Succesful!!!";
      ifl4.read((char*)&tob,sizeof(tob));
    }
    else
    {
      ofl2.write((char*)&tob,sizeof(tob));
      ifl4.read((char*)&tob,sizeof(tob));
    }
  }
  remove("TravelDetails.txt");
  rename("temp1.txt","TravelDetails.txt");
  ifl4.close();
  ofl2.close();
  getch();
}
void deletion(int c)  //common delete func()
{
  ofstream ofl2("temp1.txt",ios::binary);
  if(!ofl2)
  cout<<"Error While Opening File";
  ifstream ifl4("PersonalDetails.txt",ios::binary);
  if(!ifl4)
  cout<<"Error While Opening File";
  ifl4.read((char*)&pob,sizeof(pob));
  while(!ifl4.eof())
  {
    if(pob.givecode()!=c)
    {
      ofl2.write((char*)&pob,sizeof(pob));
    }
    ifl4.read((char*)&pob,sizeof(pob));
  }
  remove("PersonalDetails.txt");
  rename("temp1.txt","PersonalDetails.txt");
  ofl2.close();
  ifl4.close();
  ofstream ofl3("temp2.txt",ios::binary);
  if(!ofl3)
  cout<<"\nError While Opening File";
  ifstream ifl5("TravelDetails.txt",ios::binary);
  if(!ifl5)
  cout<<"\nError While Opening File";
  ifl5.read((char*)&tob,sizeof(tob));
  while(!ifl5.eof())
  {
    if(tob.gtcode()!=c)
    {
      ofl3.write((char*)&tob,sizeof(tob));
    }
    ifl5.read((char*)&tob,sizeof(tob));
  }
  ofl3.close();
  ifl5.close();
  remove("TravelDetails.txt");
  rename("temp1.txt","TravelDetails.txt");
  cout<<"\n\n\t\tDeletion Completed!";
  getch();
}
void travdetails::compute()   //compution+bill generation
{
  long int gttl=0,hr,dcst,dck,cabn,swpool=5000,gm=2000,spfts=7500,slon=6000,sp=20000,ttr=500;
  switch(go_pt)
  {
    case 1:;
    case 2:;
    case 3:hr=30*24;
  dcst=250000;
  break;
    case 4:;
    case 5:;
    case 6:hr=7*24;
  dcst=75000;
  break;
    case 7:;
    case 8:;
    case 9:hr=24*24;
  dcst=130000;
  break;
   case 10:;
   case 11:;
   case 12:hr=15*24;
  dcst=100000;
  break;
   case 13:;
   case 14:;
   case 15:hr=12*24;
  dcst=120000;
  break;
  }
  switch(deck)
  {
    case 1:dck=7500;
  break;
    case 2:dck=5000;
  break;
    case 3:dck=1000;
  }
  switch(cabin)
  {
    case 1:cabn=5000;
  break;
    case 2:cabn=2000;
  break;
  }
  clrscr();
  cout<<"\n\n\t\t:::::::::::::::::::::: BILL ::::::::::::::::::::::::::";
  cout<<"\n\n\t\tBoarding point:\t\t ";
  boardpt(bdg_pt);
  cout<<"\n\n\t\tDestination:\t\t ";
  dest(go_pt);
  cout<<"\n\n\t\tDate of Departure: ";
  cout<<day<<"/"<<month<<"/"<<year;
   hr=hr/24;         //to calculate date of arrival
  day=day+hr;
  if(month==1||month==3||month==5||month==7||month==8||month==10||month==12)
  {
    if(day>31)
    {
      month=month+1;
      day=day%31;
    }
  }
  if(month==4||month==6||month==9||month==11)
  {
    if(day>30)
    {
      month=month+1;
      day=day%30;
    }
  }
  if(month==2)
  {
    if(day>28)
    {
      month=month+1;
      day=day%28;
    }
  }
  if(month==13)
  {
    month=1;
    year++;
  }
  cout<<"\n\n\t\tDate of Arrival: ";
  cout<<day<<"/"<<month<<"/"<<year;
  cout<<"\n\n\t\tSubject\t\tCost(for 1)\tNo of ppl\tTotal";
  cout<<"\n\n\t\tTravel\t\t"<<dcst<<"\t\t   "<<num1<<"\t\t"<<num1*dcst;
  gttl+=num1*dcst;
  cout<<"\n\t\tDeck\t\t"<<dck<<"\t\t   "<<num1<<"\t\t"<<dck*num1;
  gttl+=dck*num1;
  cout<<"\n\t\tCabin\t\t"<<cabn<<"\t\t   "<<num1<<"\t\t"<<cabn*num1;
  gttl+=cabn*num1;
  if(pool==1)
  {
    cout<<"\n\t\tSwimming Pool\t"<<swpool<<"\t\t   "<<num1<<"\t\t"<<swpool*num1;
    gttl+=swpool*num1;
  }
  if(gym==1)
  {
    cout<<"\n\t\tGym\t\t"<<gm<<"\t\t   "<<num1<<"\t\t"<<gm*num1;
    gttl+=gm*num1;
  }
  if(sports==1)
  {
    cout<<"\n\t\tSports\t\t"<<spfts<<"\t\t   "<<num1<<"\t\t"<<spfts*num1;
    gttl+=spfts*num1;
  }
  if(salon==1)
  {
    cout<<"\n\t\tSalon\t\t"<<slon<<"\t\t   "<<num1<<"\t\t"<<slon*num1;
    gttl+=slon*num1;
  }
  if(spa==1)
  {
    cout<<"\n\t\tSpa\t\t"<<sp<<"\t\t   "<<num1<<"\t\t"<<sp*num1;
    gttl+=dcst*num1;
  }
  if(theatre==1)
  {
    cout<<"\n\t\tTheatre\t\t"<<ttr<<"\t\t   "<<num1<<"\t\t"<<ttr*num1;
    gttl+=ttr*num1;
  }
  cout<<"\n\n\n\t\t\t Grand Total:Rs ";
  if(gttl>100000)     //to provide comma's for grandtotal
  {
    cout<<gttl/100000<<",";
    gttl=gttl%100000;
  }
  if(gttl>1000)
  {
    cout<<gttl/1000<<",";
    gttl=gttl%1000;
  }
  cout<<gttl;
  if(gttl<10)
  cout<<"00";
  cout<<" ";
  cout<<"\n\n\t ! All Travellers below the age of 5 have not been charged ! ";
  getch();
}
void main()
{
  clrscr();
  cout<<"\n\n\n\n\n";   //welcome screen
  cout<<"            **      :::::::  !!!!!!!!          \n";
  cout<<"         _____  **      ::       !!    !!       _____  \n";
  cout<<"             **      ::       !!    !!               \n";
  cout<<"            ******  :::::::  !!!!!!!!          \n";
  cout<<"\n\n\n\n\n";
  cout<<"      ~ __  ~ __  ~ __                  \n";
  cout<<"       |==|  |==|  |==|                 \n";
  cout<<"     __|__|__|__|__|__|_                \n";
  cout<<"  __|___________________|___            \n";
  cout<<"       __|__[]__[]__[]__[]__[]__[]__|___         CRUISE DATABASE MANAGEMENT\n";
  cout<<"      |............................o.../ \n";
  cout<<"      \\.............................../ \n";
  cout<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n";
  cout<<" ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ \n";
  cout<<"  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~  ~\n";
  cout<<"    ~    ~     ~    ~    ~    ~    ~    ~    ~  \n";
  cout<<"     ~    ~      ~    ~     ~    ~    ~      ~\n";
  ifstream fl("INITIALL.txt",ios::binary); //initialisation of code
  if(!fl)
  cout<<"\nError";
  fl.read((char*)&code,sizeof(code));
  fl.close();
  int opt,opt1,opt2,opt3,opt4;
  int acceptcode,flag;
  getch();
  clrscr();
  do
  {
    clrscr();
    cout<<"\n\n\t\t \n";
    cout<<"\t\t ....WELCOME TO THE CRUISE DATABASE SYSTEM.... \n";
    cout<<"\t\t \n\n\n";
    cout<<"\t\t         \n";
    cout<<"\t\t MAIN MENU \n";
    cout<<"\t\t         \n\n";
    cout<<"\n\t\t\tPlease select a kind of user:";
    cout<<"\n\n\t\t\t\t1.New User\n\n\t\t\t\t2.Existing User\n\n\t\t\t\t3.Exit";
    cout<<"\n\n\t\t\t\t ";
    cin>>opt;
    switch(opt)
    {
      case 1:do
    {
      clrscr();
      cout<<"\n\n\n\t\t\t\t    NEW USER\n";
      cout<<"\t\t\t\t    ********\n\n";
      cout<<"\n\n\t\t\tChoose the type of details you want to enter:";
      cout<<"\n\n\t\t\t\t1.Personal Details\n\n\t\t\t\t2.Travel Details\n\n\t\t\t\t3.Back\n\n\t\t\t\t ";
      cin>>opt1;
      switch(opt1)
      {
case 1:code++;
pob.p_input(code);
ofstream ofl("PersonalDetails.txt",ios::binary|ios::app);
if(!ofl)
cout<<"\n\n\t\tSorry.The File Cannot Be Opened For Writing"<<endl;
ofl.write((char*)&pob,sizeof(pob));
ofl.close();
break;
case 2:tob.t_input(code);
ofstream ofl1("TravelDetails.txt",ios::binary|ios::app);
if(!ofl1)
cout<<"\n\n\t\tSorry.The File Cannot Be Opened For Writing"<<endl;
ofl1.write((char*)&tob,sizeof(tob));
ofl1.close();
clrscr();
cout<<"\n\n\n\n!!!!!Your Details Have Been Registered.Please Make A Note Of This Code: "<<code;
cout<<"\n\n* For modifications,Please visit 'existing user' section in the main screen";
getch();
break;
      }
    }while(opt1!=3);
    break;
      case 2:clrscr();
    cout<<"\n\n\t\t\t ***** EXISTING USER ***** \n\n\t\tPlease Enter The Travel Code That Was Given To You\n\n\t\t\t ";
    cin>>acceptcode;
    if(acceptcode>code)
    {
      cout<<"\nNo such record has been created!";
      break;
    }
    family(acceptcode,flag);
    cout<<endl<<endl<<"\t\t\t\tCode no:"<<acceptcode;
    getch();
    if(flag==1)
    {
    do
    {
      clrscr();
      cout<<"\n\n\t\t\t@@@@@@@@@ Information Centre @@@@@@@@@";
      cout<<"\n\t\t\t\t  ~~~~~~~~~~~~~~~~~";
      cout<<"\n\n\tPlease select the type of operation that you would like to perform:";
      cout<<"\n\n\t\t\t1.View Personal Details\n\n\t\t\t2.View Travel Details\n\n\t\t\t3.Edit Details\n\n\t\t\t4.Compute Bill\n\n\t\t\t5.Back\n\n\t\t\t ";
      cin>>opt2;
      switch(opt2)
      {
case 1:ifstream ifl("PersonalDetails.txt",ios::binary);
if(!ifl)
cout<<"\nError";
ifl.read((char*)&pob,sizeof(pob));
while(!ifl.eof())
{
 if(pob.givecode()==acceptcode)
 {
   break;
 }
 ifl.read((char*)&pob,sizeof(pob));
}
pob.p_output();
ifl.close();
break;
case 2:ifstream ifl1("TravelDetails.txt",ios::binary);
if(!ifl1)
cout<<"\nError";
ifl1.read((char*)&tob,sizeof(tob));
while(!ifl1.eof())
{
 if(tob.gtcode()==acceptcode)
 {
   break;
 }
 ifl1.read((char*)&tob,sizeof(tob));
}
tob.t_output();
ifl1.close();
break;
case 3:do
{
 clrscr();
 cout<<"\n\n\n\t Edit Details ";
 cout<<"\n\n\t\tPlease select from among the editing options:\n\n";
 cout<<"\t\t\t\t1.Modify\n\n\t\t\t\t2.Delete\n\n\t\t\t\t3.Back\n\n\t\t\t\t ";
 cin>>opt3;
 switch(opt3)
 {
   case 1:do
  {
    clrscr();
    cout<<"\n\n\t\t Modificaton \n";
    cout<<"\t\t               ~~~~~~~~~~~";
    cout<<"\n\n\tChoose The Type Of Details You Want To Modify:\n\n\t\t\t1.Personal Details\n\n\t\t\t2.Travel Details\n\n\t\t\t3.Back\n\n\t\t\t ";
    cin>>opt4;
    switch(opt4)
    {
      case 1:editp(acceptcode);
     break;
      case 2:editt(acceptcode);
     break;
      case 3:break;
    }
  }while(opt4!=3);
  break;
   case 2:deletion(acceptcode);
  opt3=3;
  opt2=5;
  break;
   case 3:break;
 }
}while(opt3!=3);
break;
case 4:ifstream ifl3("PersonalDetails.txt",ios::binary);
if(!ifl3)
cout<<"\nError";
ifl3.read((char*)&pob,sizeof(pob));
while(!ifl3.eof())
{
 if(pob.givecode()==acceptcode)
 {
   break;
 }
 ifl3.read((char*)&pob,sizeof(pob));
}
ifstream ifl2("TravelDetails.txt",ios::binary);
if(!ifl2)
cout<<"\nError";
ifl2.read((char*)&tob,sizeof(tob));
while(!ifl2.eof())
{
 if(tob.gtcode()==acceptcode)
 {
   break;
 }
 ifl2.read((char*)&tob,sizeof(tob));
}
tob.accept(pob.give());
tob.compute();
ifl2.close();
break;
case 5:break;
      }
    }while(opt2!=5);
    }
    break;
      case 3:ofstream fil("INITIALL.txt",ios::binary); //storing code value
    if(!fil)
    cout<<"\nError";
    fil.write((char*)&code,sizeof(code));
    fil.close();
    clrscr();
    cout<<"\n\n";
    cout<<"         _/_/_/_/_/  _/                            _/            \n";
    cout<<"            _/      _/_/_/      _/_/_/  _/_/_/    _/  _/         \n";
    cout<<"           _/      _/    _/  _/    _/  _/    _/  _/_/            \n";
    cout<<"          _/      _/    _/  _/    _/  _/    _/  _/  _/           \n";
    cout<<"         _/      _/    _/    _/_/_/  _/    _/  _/    _/          \n";
    cout<<"                                                                  \n";
    cout<<"                                                                  \n";
    cout<<"                                                                  \n";
    cout<<"         _/     _/                                       \n";
    cout<<"          _/  _/    _/_/    _/    _/                     \n";
    cout<<"            _/    _/    _/  _/    _/                     \n";
    cout<<"            _/    _/    _/  _/    _/                     \n";
    cout<<"           _/      _/_/      _/_/_/                     \n\n";
             cout<<"\t    |===| ~~\n";
             cout<<"     _|   |____________________________________________|| ||___ ";
    cout<<"\t\t    |_|_|_|_\__()____()____()______()______()_____()__||_||__/"<<endl;
    cout<<"\t    `.==---------|_|----|_|-----|_|----|_|-----------------/"<<endl;
    cout<<"\t      `.__________________________________________________/"<<endl;
    cout<<"..........oOoOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
    cout<<".........oOoOo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
    cout<<".........oooo~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"<<endl;
    getch();
    exit(0);
    }
    getch();
  }while(1); //infinite loop till exit selected
}


                               // OUTPUT SCREENS















Thursday, 1 May 2014

SUPER MARKET BILLING

// A Project on Super Market Purchases and their Billing
// A Project to use as a customer or as an administrator


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

#include<conio.h>
#include<stdio.h>
#include<process.h>
#include<fstream.h>

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

class product
{
 int pno;
 char name[50];
 float price,qty,tax,dis;
 public:
void create_product()
{
cout<<"\nPlease Enter The Product No. of The Product ";
cin>>pno;
cout<<"\n\nPlease Enter The Name of The Product ";
gets(name);
cout<<"\nPlease Enter The Price of The Product ";
cin>>price;
cout<<"\nPlease Enter The Discount (%) ";
cin>>dis;
}

void show_product()
{
cout<<"\nThe Product No. of The Product : "<<pno;
cout<<"\nThe Name of The Product : ";
puts(name);
cout<<"\nThe Price of The Product : "<<price;
cout<<"\nDiscount : "<<dis;
}

  int  retpno()
  {return pno;}

  float retprice()
  {return price;}

  char* retname()
  {return name;}

  int retdis()
  {return dis;}

};         //class ends here



//***************************************************************
//     global declaration for stream object, object
//****************************************************************

 fstream fp;
 product pr;


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

void write_product()
   {
    fp.open("Shop.dat",ios::out|ios::app);
    pr.create_product();
    fp.write((char*)&pr,sizeof(product));
    fp.close();
    cout<<"\n\nThe Product Has Been Created ";
    getch();
   }


//***************************************************************
//     function to read all records from file
//****************************************************************


void display_all()
{
    clrscr();
    cout<<"\n\n\n\t\tDISPLAY ALL RECORD !!!\n\n";
    fp.open("Shop.dat",ios::in);
    while(fp.read((char*)&pr,sizeof(product)))
{
pr.show_product();
cout<<"\n\n====================================\n";
getch();
}
    fp.close();
    getch();
}


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


void display_sp(int n)
{
    int flag=0;
    fp.open("Shop.dat",ios::in);
    while(fp.read((char*)&pr,sizeof(product)))
{
if(pr.retpno()==n)
{
clrscr();
pr.show_product();
flag=1;
}
}
    fp.close();
if(flag==0)
 cout<<"\n\nrecord not exist";
    getch();
}


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


void modify_product()
{
    int no,found=0;
    clrscr();
    cout<<"\n\n\tTo Modify ";
    cout<<"\n\n\tPlease Enter The Product No. of The Product";
    cin>>no;
    fp.open("Shop.dat",ios::in|ios::out);
    while(fp.read((char*)&pr,sizeof(product)) && found==0)
  {
   if(pr.retpno()==no)
  {
   pr.show_product();
   cout<<"\nPlease Enter The New Details of Product"<<endl;
   pr.create_product();
   int pos=-1*sizeof(pr);
   fp.seekp(pos,ios::cur);
   fp.write((char*)&pr,sizeof(product));
   cout<<"\n\n\t Record Updated";
   found=1;
  }
    }
    fp.close();
    if(found==0)
    cout<<"\n\n Record Not Found ";
    getch();
}


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


void delete_product()
   {
    int no;
    clrscr();
    cout<<"\n\n\n\tDelete Record";
    cout<<"\n\nPlease Enter The product no. of The Product You Want To Delete";
    cin>>no;
    fp.open("Shop.dat",ios::in|ios::out);
    fstream fp2;
    fp2.open("Temp.dat",ios::out);
    fp.seekg(0,ios::beg);
    while(fp.read((char*)&pr,sizeof(product)))
{
if(pr.retpno()!=no)
{
fp2.write((char*)&pr,sizeof(product));
}
}
    fp2.close();
    fp.close();
    remove("Shop.dat");
    rename("Temp.dat","Shop.dat");
    cout<<"\n\n\tRecord Deleted ..";
    getch();
    }


//***************************************************************
//     function to display all products price list
//****************************************************************

    void menu()
    {
     clrscr();
     fp.open("Shop.dat",ios::in);
     if(!fp)
     {
       cout<<"ERROR!!! FILE COULD NOT BE OPEN\n\n\n Go To Admin Menu to create File";
       cout<<"\n\n\n Program is closing ....";
       getch();
       exit(0);
     }

     cout<<"\n\n\t\tProduct MENU\n\n";
 cout<<"====================================================\n";
 cout<<"P.NO.\t\tNAME\t\tPRICE\n";
 cout<<"====================================================\n";

      while(fp.read((char*)&pr,sizeof(product)))
{
  cout<<pr.retpno()<<"\t\t"<<pr.retname()<<"\t\t"<<pr.retprice()<<endl;
}
     fp.close();
}




//***************************************************************
//     function to place order and generating bill for Products
//****************************************************************

   void place_order()
   {
    int  order_arr[50],quan[50],c=0;
    float amt,damt,total=0;
    char ch='Y';
    menu();
    cout<<"\n============================";
    cout<<"\n    PLACE YOUR ORDER";
    cout<<"\n============================\n";
    do{
cout<<"\n\nEnter The Product No. Of The Product : ";
cin>>order_arr[c];
cout<<"\nQuantity in number : ";
cin>>quan[c];
c++;
cout<<"\nDo You Want To Order Another Product ? (y/n)";
cin>>ch;
    }while(ch=='y' ||ch=='Y');
    cout<<"\n\nThank You For Placing The Order";getch();clrscr();
      cout<<"\n\n********************************INVOICE************************\n";
      cout<<"\nPr No.\tPr Name\tQuantity \tPrice \tAmount \tAmount after discount\n";
      for(int x=0;x<=c;x++)
{
fp.open("Shop.dat",ios::in);
fp.read((char*)&pr,sizeof(product));
 while(!fp.eof())
{
if(pr.retpno()==order_arr[x])
{
amt=pr.retprice()*quan[x];
damt=amt-(amt*pr.retdis()/100);
cout<<"\n"<<order_arr[x]<<"\t"<<pr.retname()<<"\t"<<quan[x]<<"\t\t"<<pr.retprice()<<"\t"<<amt<<"\t\t"<<damt;
total+=damt;
}
fp.read((char*)&pr,sizeof(product));
}

fp.close();
}
       cout<<"\n\n\t\t\t\t\tTOTAL = "<<total;
    getch();
    }

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

void intro()
{
 clrscr();
 gotoxy(31,11);
 cout<<"SUPER MARKET";
 gotoxy(35,14);
 cout<<"BILLING";
 gotoxy(35,17);
 cout<<"PROJECT";
 getch();

}




//***************************************************************
//     ADMINSTRATOR MENU FUNCTION
//****************************************************************
void admin_menu()
{
  clrscr();
  char ch2;
  cout<<"\n\n\n\tADMIN MENU";
  cout<<"\n\n\t1.CREATE PRODUCT";
  cout<<"\n\n\t2.DISPLAY ALL PRODUCTS";
  cout<<"\n\n\t3.QUERY ";
  cout<<"\n\n\t4.MODIFY PRODUCT";
  cout<<"\n\n\t5.DELETE PRODUCT";
  cout<<"\n\n\t6.VIEW PRODUCT MENU";
  cout<<"\n\n\t7.BACK TO MAIN MENU";
  cout<<"\n\n\tPlease Enter Your Choice (1-7) ";
  ch2=getche();
  switch(ch2)
  {
    case '1': clrscr();
     write_product();
     break;
    case '2': display_all();break;
    case '3':
      int num;
      clrscr();
      cout<<"\n\n\tPlease Enter The Product No. ";
      cin>>num;
      display_sp(num);
      break;
      case '4': modify_product();break;
      case '5': delete_product();break;
      case '6': menu();
getch();
      case '7': break;
      default:cout<<"\a";admin_menu();
   }
}


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


void main()
{
  char ch;
  intro();
  do
    {
 clrscr();
 cout<<"\n\n\n\tMAIN MENU";
 cout<<"\n\n\t01. CUSTOMER";
 cout<<"\n\n\t02. ADMINISTRATOR";
 cout<<"\n\n\t03. EXIT";
 cout<<"\n\n\tPlease Select Your Option (1-3) ";
 ch=getche();
 switch(ch)
 {
case '1': clrscr();
  place_order();
  getch();
  break;
 case '2': admin_menu();
   break;
 case '3':exit(0);
 default :cout<<"\a";
}
    }while(ch!='3');
}

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

                 //OUTPUT SCREENS










Monday, 21 April 2014

SOCCER

// A Program On Soccer and score of the players
// A Program to understand OOPS and File Handling


#include<conio.h>
#include<fstream.h>
#include<string.h>

class footballer{

protected:

char id[10],name[30];
int per;

public:

footballer(){per =100;}
void getid()
{
 cout<<"\n\n\ninput footballer id\t ";
 cin>>id;
 cout<<"\n\n\ninput fottballer name\t";
 cin>>name;
};


};

class fileinfoot:public footballer{

    public:
    void fil()
    {
     fstream x("FOOTBALL.txt",ios::out|ios::app);
     x.width(30);
     x<<endl;
     x<<name;
     x.width(20);
     x<<id;
     x.close();

    }

} ;
class goalkeeper: public fileinfoot{
   int save;
   int loss;
   public:
  void performance()
  {
   getid();
   cout<<"\n\n\nHow many goal he saved?\t";
   cin>>save;
   save=save*25;
   cout<<"\n\n\nHow many goal he got\t";
   cin>>loss;
   loss=loss*75;
   per=per+save-loss;
   if(per<0)
   per=0;
   file();
}
void file();


};

      void  goalkeeper::file()
{
 char fil[20];
 strcpy(fil,id);
 strcat(fil,".txt");
 ofstream x(fil);
 x<<"NAME:-"<<name<<endl;
 x<<"ID:-"<<id<<endl;
 x<<"POSITION- GOALKEEPER\n";
 x<<"Performance point:-"<<per<<endl;
 x.close();
      fstream y("GOALKEEP.txt",ios::out|ios::app);
     y<<endl;
     y.width(30);
     y<<name;
     y.width(20);
     y<<id;
     y.close();


}

class defender: public fileinfoot{
   int defend;
   int loss;
   public:
  void performance()
  {
   getid();
   cout<<"\n\n\nHow many defend?\t";
   cin>>defend;
   defend=defend*25;
   cout<<"\n\n\nHow many missdefence\t";
   cin>>loss;
   loss=loss*5;
   per=per+defend-loss;
   if(per<0)
   per=0;

   file();
  }
  void file();

};
 void defender::file()
{
 char fil[20];
 strcpy(fil,id);
 strcat(fil,".txt");
 ofstream x(fil);
 x<<"NAME:-"<<name<<endl;
 x<<"ID:-"<<id<<endl;
 x<<"POSITION- DEFENDER\n";
 x<<"Performance point:-"<<per<<endl;
 x.close();
      fstream y("DEFENDER.txt",ios::out|ios::app);
     y<<endl;
     y.width(30);
     y<<name;
     y.width(20);
     y<<id;
     y.close();
}

class midfielder:public fileinfoot{
    int passing;
   int mispass;
   public:
  void performance()
  {getid();
   cout<<"\n\n\nHow many pass?\t";
   cin>>passing;
   passing=passing*25;
   cout<<"\n\n\nHow many miss pass\t";
   cin>>mispass;
   mispass=mispass*75;
   per=per+passing-mispass;
   if(per<0)
   per=0;
   file();
  }
   void file();

};
 void midfielder:: file()
{
 char fil[20];
 strcpy(fil,id);
 strcat(fil,".txt");
 ofstream x(fil);
 x<<"NAME:-"<<name<<endl;
 x<<"ID:-"<<id<<endl;
 x<<"POSITION- MIDFIELDER\n";
 x<<"Performance point:-"<<per<<endl;
 x.close();
  fstream y("MIDFIELD.txt",ios::out|ios::app);
     y<<endl;
     y.width(30);
     y<<name;
     y.width(20);
     y<<id;
     y.close();



}

class striker: public fileinfoot{
   int goal;
   int loss;
public:
  void performance()
  {getid();
   cout<<"\n\n\nHow many goal?\t";
   cin>>goal;
   goal=goal*25;
   cout<<"\n\n\nHow many goal he miss\t";
   cin>>loss;
   loss=loss*75;
   per=per+goal-loss;
   if(per<0)
   per=0;
   file();
  }
   void file();

};
 void striker:: file()
{
 char fil[20];
 strcpy(fil,id);
 strcat(fil,".txt");
 ofstream x(fil);
 x<<"NAME:-"<<name<<endl;
 x<<"ID:-"<<id<<endl;
 x<<"POSITION- STRIKER\n";
 x<<"Performance point:-"<<per<<endl;
 x.close();
 fstream y("STRIKER.txt",ios::out|ios::app);
     y<<endl;
     y.width(30);
     y<<name;
     y.width(20);
     y<<id;
     y.close();
}



class add{
public:
add();
};
     add::add(){
 goalkeeper g;
 defender d;
 striker s;
 midfielder m;
 int co;
 while(1)
 {clrscr();
 cout<<"\n\n\n1\tgoalkeeper\n\n\n2\tdefender\n\n\n"
     <<"3\tstriker\n\n\n4\tmidfielder\n\n\n5\texit\n\n";
 cin>>co;
 if(co==5)
 break;
 if(co==1)
 {
g.performance();
g.fil();
 }
  if(co==2)
 { d.performance();
  d.fil();
  }
  if(co==3)
  {
  s.performance();
  s.fil();
  }
  if(co==4)
  {
  m.performance();
  m.fil();
 }
 }
}




class search{

public:
void find();
} ;
void search::find(){
   int i;
   char id[20],c;
   while(1)
   {
    clrscr();
   cout<<"\n\n\n1\tALL FOOTBALLER\n\n\n2\tALL GOALKEEPER\n\n\n3\tALL DEFENDER";
   cout<<"\n\n\n4\tALL MIDFIELDER\n\n\n5\tALL STRIKER\n\n\n6\tSEARCH BY ID\n\n\n7\tExit\n\n";
   cin>>i;
   if(i==7)
     break;            
   if(i==1)
   {
   ifstream x("FOOTBALL.txt");
   cout<<"FOOTBALLERS NAME AND ID \n\n";
   while(x)
    { x.get(c);
      cout<<c;
     }
     getch();
     x.close();
 }
 if(i==2)
 {ifstream x("GOALKEEP.txt");
  cout<<"FOOTBALLERS NAME AND ID \n\n";
  while(x)
  { x.get(c);
    cout<<c;
  }
  getch();
  x.close();
 }
 if(i==3)
 {ifstream x("DEFENDER.txt");
  cout<<"DEFENERS NAME AND ID \n\n";
  while(x)
  { x.get(c);
    cout<<c;
  }
  getch();
  x.close();
 }
 if(i==4)
 {ifstream x("MIDFIELD.txt");
  cout<<"MIDFIELDERS NAME AND ID \n\n";
  while(x)
  { x.get(c);
    cout<<c;
  }
  getch();
  x.close();
 }
 if(i==5)
 {ifstream x("STRIKER.txt");
  cout<<"STRIKER NAME AND ID \n\n";
  while(x)
  { x.get(c);
    cout<<c;
  }
  getch();
  x.close();
 }
 if(i==6)
 {clrscr();
  cout<<"input the id";
  cin>>id;
  char fil[20];
 strcpy(fil,id);
  strcat(fil,".txt");
  ifstream x(fil);
   while(x)
  { x.get(c);
    cout<<c;
  }
  getch();
  x.close();
 }
 }

}


int main()
{
  int c;
 clrscr();

 while(1)
 {
  clrscr();
  cout<<"\n\n\n1\tadd\n\n"<<"\n\n\n2\tsearch\n\n"<<"\n\n\n3\texit\n\n";
  cin>>c;
  if(c==3)
     break;
  else if(c==1)
     {
      add a;
     }
  else if(c==2)
     {
     search f;
     f.find();
     }
  else
 { cout<<"wrong choice";
   getch();
   }
 }


 return 0;
}

             // OUTPUT SCREENS