13 Replies - 748 Views - Last Post: 23 July 2012 - 12:16 AM Rate Topic: ****- 1 Votes

#1 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Infinite loop

Posted 20 July 2012 - 02:02 AM

// spoets mgt……………………

#include<graphics.h>
#include<iostream.h>
#include<fstream.h>
#include<stdio.h>
#include<conio.h>
#include<string.h>
#include<iomanip.h>
#include<dos.h>
struct date_rec
{
     short int dd,mm;
     int yyyy;
}due_date,current_date;
int check=0;
class facility
{
     char fac_type[10];
     short int fac_code;
     public:
     void get_facility();
     void show_fac();
     void add_facility();
     void show_facility();
     void reports();
}fac;
void facility::get_facility()
{
     cout<<"\nENTER THE FACILITY TO BE ADDED -----> ";
     gets(fac_type);
     cout<<"\nENTER THE CODE FOR THIS FACILITY -----> ";
     cin>>fac_code;
}
void facility::show_fac()
{
     cout<<"\n";
     cout<<setiosflags(ios::left)
     <<setw(10)<<" "
     <<setw(25)<<fac_code<<setw(30)<<fac_type;
}
void facility::add_facility()
{
     fstream outfile;
     char ch='y';
     outfile.open("facility.dat",ios::app);
     while(ch=='y'||ch=='Y')
     {
          fac.get_facility();
          outfile.write((char *)&fac, sizeof(fac));
          cout<<"\nANY MORE FACILITY TO BE ADDED <<Y/N>> ? ----> ";
          ch=getch();
     }
}
void facility::show_facility()
{
     clrscr();
     fstream infile;
     infile.open("facility.dat",ios::in);
     infile.seekg(0,ios::beg);
     cout<<"\n FACILITY CODE -----------------> FACILITY TYPE ";
     cout<<"\n ------------------------------------------------";
     infile.read((char *)&fac,sizeof(fac));
     while(!infile.eof())
     {
          fac.show_fac();
          infile.read((char *)&fac,sizeof(fac));
     }
}
class fees_file
{
     private:
     unsigned long mem_code;
     date_rec date_of_deposit;
     float amount;
     short int payment_code;
     public:
     void add_fees_object(unsigned long code,date_rec date, int paycode);
     void del_fees_object(unsigned long code);
     void check_due_date(int& check);
     void get_fees();
     void show_fees();
     void update_fees_file();
     void show_fees_file();
     void fees_collection();
     void fees_due();
}fees,temp;
void fees_file::add_fees_object(unsigned long code,date_rec date, int paycode)
{
     fstream outfile;
     fees.mem_code=code;
     fees.date_of_deposit=date;
     fees.payment_code=paycode;
     if(fees.payment_code==1)
          fees.amount=7000.00;
     else
          fees.amount=3500.00;
     outfile.open("feesfile.dat",ios::app);
     outfile.write((char *)&fees,sizeof(fees));
     outfile.flush();
     outfile.close();
}
void fees_file::del_fees_object(unsigned long code)
{
     fstream outfile,infile;
     outfile.open("tempfile.dat",ios::app);
     infile.open("feesfile.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char *)&fees,sizeof(fees));
     while(!infile.eof())
     {
          if(fees.mem_code!=code)
               outfile.write((char *)&fees,sizeof(fees));
          infile.read((char *)&fees,sizeof(fees));
     }
     infile.close();
     outfile.close();
     remove("feesfile.dat");
     rename("tempfile.dat","feesfile.dat");
}
void fees_file::get_fees()
{
     cout<<"\n ENTER THE DATE OF SUBMISSION OF FEES--> ";
     cin>>date_of_deposit.dd;
     getch();
     cin>>date_of_deposit.mm;
     getch();
     cin>>date_of_deposit.yyyy;
     cout<<"\n ENTER THE AMOUNT OF FEES ----> ";
     cin>>amount;
}
void fees_file::show_fees()
{
     cout<<"\n DATE OF SUBMISSION OF FEES ---> "<<date_of_deposit.dd<<date_of_deposit.mm<<date_of_deposit.yyyy;
     cout<<"\n AMOUNT OF FEES ---------------> "<<amount;
}
void fees_file::check_due_date(int &check)
{
     if(due_date.yyyy<=current_date.yyyy)
     {
          if(due_date.mm<=current_date.mm)
          {
               if(due_date.dd<=current_date.dd)
                    check=1;
          }
     }
     else
          check=0;
}
void fees_file::update_fees_file(void)
{
     fstream infile,outfile;
     char ch;
     clrscr();
     cout<<"\n ENTER CURRENT DATE <<dd/mm/yyyy>> :";
     cin>>current_date.dd>>ch>>current_date.mm>>ch>>current_date.yyyy;
     outfile.open("tempfile.dat",ios::app);
     infile.open("feesfile.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char *)&fees,sizeof(fees));
     while(!infile.eof())
     {
          switch(fees.payment_code)
          {
               case 1 : due_date.yyyy=fees.date_of_deposit.yyyy+1;
                    due_date.mm=fees.date_of_deposit.mm;
                    due_date.dd=fees.date_of_deposit.dd;
                    fees.check_due_date(check);
                    switch(check)
                    {
                         case 0 : outfile.write((char *)&fees,sizeof(fees));
                              break;
                         case 1 : cout<<"\n MEMBERSHIP CODE ------> "<<fees.mem_code;
                              cout<<"FEE WAS DUE ON "<<due_date.dd<<"-"<<due_date.mm<<"-"<<due_date.yyyy;
                              cout<<"HAS THE FEES BEEN DEPOSITED [Y/N] ? ";
                              cin>>ch;
                              if(ch=='y'||ch=='Y')
                              {
                                   temp.mem_code=fees.mem_code;
                                   cout<<"\n ENTER THE DATE ON WHICH THE FEES WAS DEPOSITED ----> ";
                                   cin>>temp.date_of_deposit.dd>>ch>>temp.date_of_deposit.mm>>ch>>temp.date_of_deposit.yyyy;
                                   cout<<"\n ENTER THE AMOUNT DEPOSITED ---> ";
                                   cin>>temp.amount;
                                   temp.payment_code=fees.payment_code;
                                   outfile.write((char *)&temp, sizeof(temp));
                              }
                              else
                              outfile.write((char *)&fees, sizeof(fees));
                              break;
                    }
                    break;
                    case 0 : //p no. 58
                    due_date.mm=fees.date_of_deposit.mm+6;
                    due_date.yyyy=fees.date_of_deposit.yyyy;
                    switch(due_date.mm)
                    {
                         case 13 : due_date.mm=1;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 14 : due_date.mm=2;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 15 : due_date.mm=3;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 16 : due_date.mm=4;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 17 : due_date.mm=5;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 18 : due_date.mm=6;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                    }
                    fees.check_due_date(check);
                    switch(check)
                    {
                         case 0 : outfile.write((char *)&fees, sizeof(fees));
                         break;
                         case 1 : cout<<"\n MEMBERSHIP CODE -----> "<<fees.mem_code;
                         cout<<"\nFEES WAS DUE ON "<<due_date.dd<<"-"<<due_date.mm<<"-"<<due_date.yyyy;
                         cout<<"HAS THE FEES BEEN DEPOSITED [Y/N] ?";
                         cin>>ch;
                         if(ch=='y'||ch=='Y')
                         {
                              temp.mem_code=fees.mem_code;
                              cout<<"\n ENTER THE DATE ON WHICH THE FEES WAS DEPOSITED --->";
                              cin>>temp.date_of_deposit.dd>>ch>>temp.date_of_deposit.mm>>ch>>temp.date_of_deposit.yyyy;
                              cout<<"\n ENTER THE AMOUNT DEPOSITED ---->";
                              cin>>temp.amount;
                              temp.payment_code=fees.payment_code;
                              outfile.write((char *) &temp, sizeof(temp));
                         }
                         else outfile.write((char *)&fees, sizeof(fees));
                         break;
                    }
                    break;
               }
               infile.read((char *)&fees, sizeof(fees));
          }
          infile.close();
          outfile.close();
          remove("feesfile.dat");
          rename("tempfile.dat","feesfile.dat");
     }
void fees_file::show_fees_file()
{
     fstream infile;
     infile.open("feesfile.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char *)&fees, sizeof(fees));
     while(!infile.eof())
     {
          fees.show_fees();
          infile.read((char*)&fees,sizeof(fees));
     }
     infile.close();
}
void fees_file::fees_collection()
{
     fstream infile;
     cout<<"\n CHOOSE THE MONTH IN WHICH YOU WANT TO SEE DATEWISE FEES COLLECTION ---->";
     int month;
     cout<<"\n\n ENTER THE MONTH";
     cin>>month;
     cout<<"\n DATE -------------> MEMBERSHIP CODE";
     cout<<"\n -----------------------------------";
     for(int i=1; i<=31;i++)
     {
          infile.open("feesfile.dat",ios::in);
          infile.seekg(0,ios::beg);
          infile.read((char*)&fees, sizeof(fees));
          while(!infile.eof())
          {
               if(fees.date_of_deposit.dd==i&&fees.date_of_deposit.mm==month)
               {
                    cout<<"\n";
                    cout<<fees.date_of_deposit.dd<<"-"<<fees.date_of_deposit.mm<<"-"<<fees.date_of_deposit.yyyy<<"------------>"
                    <<fees.mem_code;
               }
               infile.read((char *)&fees, sizeof(fees));
          }
          infile.close();
          }
          gotoxy(22,25);
          cout<<"PRESS ANY KEY TO CONTINUE";
          getch();
     }
void fees_file::fees_due()
{
     fstream infile;
     char ch;
     cout<<"\n ENTER THE CURRENT DATE <<dd/mm/yyy/>>---------->";
     cin>>current_date.dd>>ch>>current_date.mm>>ch>>current_date.yyyy;
     clrscr();
     cout<<"\n MEMBER CODE --------------> DUE DATE ";
     infile.open("feesfile.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char *)&fees, sizeof(fees));
     while(!infile.eof())
     {
          switch(fees.payment_code)
          {
               case 1 : due_date.yyyy=fees.date_of_deposit.yyyy+1;
                    due_date.mm=fees.date_of_deposit.mm;
                    due_date.dd=fees.date_of_deposit.dd;
                    if(due_date.yyyy==current_date.yyyy)
                    {
                         if(due_date.mm<=current_date.mm)
                         cout<<"\n"<<fees.mem_code<<"----------->"<<due_date.dd<<"-"<<due_date.mm<<"-"<<due_date.yyyy;
                    }
                    break;
               case 0 :
                    due_date.mm=fees.date_of_deposit.mm+6;
                    due_date.yyyy=fees.date_of_deposit.yyyy;
                    switch(due_date.mm)
                    {
                         case 13 : due_date.mm=1;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 14 : due_date.mm=2;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 15 : due_date.mm=3;
                              due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 16 : due_date.mm=4;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 17 : due_date.mm=5;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                         case 18 : due_date.mm=6;
                         due_date.yyyy=fees.date_of_deposit.yyyy+1;
                         break;
                    }
                    if(due_date.yyyy==current_date.yyyy)
                    {
                         if(due_date.mm<=current_date.mm)
                         cout<<"\n"<<fees.mem_code<<"------>"<<due_date.dd<<"-"<<due_date.mm<<"-"<<due_date.yyyy;
                    }
                    break;
               }
               infile.read((char*)&fees,sizeof(fees)); //read next record
               }
          infile.close(); //close file
          gotoxy(20,24);
          cout<<"PRESS ANY KEY TO CONTINUE";
          getch();
           }
class club_mem:public fees_file,public facility //derived class
{
   private:
   unsigned long mem_code;
   char mem_name[20];
   date_rec date_of_joining;
   char address[40];
   long int phone_no;
   short int fac_code1;  //facility code
   short int fac_code2;
   short int fac_code3;
   short int no_of_child; //no. of children
   short int payment_code;  //payment_code=1 if member pays the fees yearly
   public:
   char ch;
   unsigned long get_rec_no();
  void get_data();
  void show_data();
  void add_object();
  void show_object();
  void del_object();
  void modify_object();
  void facility_availed();
  void search_object();
  void membership_card();
}member;
unsigned long club_mem::get_rec_no()
{
     int found=0;
     unsigned long recno,temp_recno;
     struct node
     {
          unsigned long rec_no;
          node*link;
     };
     node *start,*ptr,*ptr1,*ptr2 ;
     fstream infile;
     infile.open("clubfile.dat",ios::in);
     infile.seekg(0,ios::end);
     int n=infile.tellg();
     infile.close();
     if(n==0)
     recno=1;
     else
     {    infile.open("clubfile.dat",ios::in);
          start=ptr=new node;
          infile.seekg(0,ios::beg);
          infile.read((char*)&member,sizeof(member));
          while(!infile.eof())
          {
            ptr->rec_no=member.mem_code;
            ptr->link=new node;
            ptr=ptr->link;
            infile.read((char*)&member,sizeof(member));
         }
            ptr->link=NULL;
            ptr1=start;
            while(ptr1->link!=NULL)
            {
                 ptr2=ptr1->link;
                 while(ptr2!=NULL)
                 {
                 if(ptr2->rec_no<ptr1->rec_no)
                 {
                     temp_recno=ptr2->rec_no;
                     ptr2->rec_no=ptr1->rec_no;
                     ptr1->rec_no=temp_recno;
                 }
                 ptr2=ptr2->link;
                 }
                 ptr2=ptr1->link;
                 ptr1=ptr2;
          }
          ptr1=start;
          while(ptr1!=NULL&& found!=1)
          {
          ptr2=ptr1;
          ptr1=ptr1->link;
          if((ptr2->rec_no)+1!=ptr1->rec_no)
          {
               recno=(ptr2->rec_no)+1;
               found=1;
          }
         }
         if(found!=1)
         recno=(ptr2->rec_no)+1;
         ptr=start;
         while(start!=NULL)
         {
          start=start->link;
          delete ptr;
         }
     }
     return recno;
}
void club_mem::get_data()
{
     clrscr();
     mem_code=get_rec_no();
     cout<<"\n ENTER THE NAME ------------> ";
     gets(mem_name);
     cout<<"\n ENTER THE DATE OF JOINING<<dd/mm/yyyy>> ------> ";
     cin>>date_of_joining.dd>>ch>>date_of_joining.mm>>ch>>date_of_joining.yyyy;
     cout<<"\n ENTER THE ADDRESS ---------------->";
     gets(address);
     cout<<"\n ENTER THE PHONE NO. -------------->";
     cin>>phone_no;
     clrscr();
     cout<<"<<<<<<<<<<<<< IMPORTANT >>>>>>>>>>>>>";
     cout<<"\n NOW YOU WILL ENTER THE FACILITY CODES WHICH YOU WANT TO AVAIL";
     cout<<"\n IF YOU DID NOT SEE THE AVAILABLE FACILITIES WITH THEIR RESPECTIVE";
     cout<<"\n CODES AT THE BEGINING, YOU CAN SEE NOW";
     cout<<"\n ENTER y/n ----------->";
     char ch;
     cin>>ch;
     if(ch=='y'||ch=='Y')
     {
          fac.show_facility();
          gotoxy(20,24);
          cout<<"PRESS ANY KEY TO CONTINUE";
          getch();
     }
     clrscr();
     cout<<"\n ENTER THE FACILITY CODE NO. 1 ------------------> ";
     cin>>fac_code1;
     cout<<"\n ENTER THE FACILITY CODE NO. 2 ------------------> ";
     cin>>fac_code2;
     cout<<"\n ENTER THE FACILITY CODE NO. 3 ------------------> ";
     cin>>fac_code3;
     cout<<"\n ENTER THE NO. OF CHILDREN <<ABOVE 12>> ------------------> ";
     cin>>no_of_child;
     cout<<"\n ENTER CODE FOR MODE OF PAYMENT ";
     cout<<"\n 1 --- FOR YEARLY PAYMENT ";
     cout<<"\n 2 --- FOR HALF - YEARLY PAYMENT ---------------> ";
     cin>>payment_code;
}
void club_mem::show_data()
{
     clrscr();
     cout<<"\n MEMBER SHIP NO. ------------>  "<<mem_code;
     cout<<"\n NAME ------------>  "<<mem_name;
     cout<<"\n DATE OF JOINING ------------>  "<<date_of_joining.dd<<"-"<<date_of_joining.mm<<"-"<<date_of_joining.yyyy;
     cout<<"\n ADDRESS ------------>  "<<address;
     cout<<"\n PHONE NO. ------------>  "<<phone_no;
     cout<<"\n FACILITY CODE NO. 1 ------------>  "<<fac_code1;
     cout<<"\n FACILITY CODE NO. 2 ------------>  "<<fac_code2;
     cout<<"\n FACILITY CODE NO. 3 ------------>  "<<fac_code3;
     cout<<"\n NO. OF CHILDREN ------------>  "<<no_of_child;
     cout<<"\n\nPRESS ANY KEY TO CONTINUE ------------>  ";
     getch();
}
void club_mem::add_object()
{
   fstream outfile;
   char choice='y';
   while (choice=='y')
   {
      clrscr();
      cout<<"\n DO YOU WANT TO SEE THE LIST OF FACILITIES AVAILABLE IN THE CLUB ? ";
      cout<<"\n YOU ARE ADVISED TO ENTER 'y' BEFORE FILLING THE FORM ";
      cout<<"\n ENTER y/n ---------> ";
      char ch;
      cin>>ch;
      if(ch=='y'||ch=='Y')
      {
     fac.show_facility();
     gotoxy(20,24);
     cout<<"PRESS ANY KEY TO CONTINUE";
     getch();
      }
      outfile.open("clubfile.dat",ios::app);
      member.get_data();
      outfile.write((char *)&member, sizeof(member));
      outfile.flush();
      outfile.close();
      add_fees_object(member.mem_code, member.date_of_joining, member.payment_code);
      cout<<"\n ANY MORE RECORD TO BE ENTERED <<y/n>> -------> ";
      cin>>choice;
      }
}
void club_mem::show_object()
{
     fstream infile;
     infile.open("clubfile.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char*)&member,sizeof(member));
     while(!infile.eof())
     {
          member.show_data();
          infile.read((char*)&member,sizeof(member));
     }
}
void club_mem::del_object()
{
     unsigned long code;
     fstream infile, outfile;
     cout<<"\n ENTER THE MEMBERSHIP NO. TO BE DELETED ------->";
     cin>>code;
     outfile.open("tempclub.dat",ios::app);
     infile.open("club.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char*)&member,sizeof(member));
     while(!infile.eof())
     {
          if(member.mem_code!=code)
          outfile.write((char*)&member,sizeof(member));
          infile.read((char*)&member,sizeof(member));
     }
     infile.close();
     outfile.close();
     remove("clubfile.dat");
     rename("tempclub.dat","clubfile.dat");
     del_fees_object(code);
     remove("feesfile.dat");
     rename("tempfile.dat","feesfile.dat");
}
void club_mem::modify_object()
{
     fstream file;
     int mod_choice;
     unsigned long code;
     do
     {
          clrscr();
          cout<<"\n     MODIFY MENU   ";
          cout<<"\n--------------------";
          cout<<"\nCHANGE ADDRESS           ..1";
          cout<<"\nCHANGE PHONE NO.         ..2";
          cout<<"\nCHANGE FACILITY CODES    ..3";
          cout<<"\nCHANGE NO. OF CHILDREN   ..4";
          cout<<"\nEXIT MODIFY MENT         ..5";
          cout<<"\n\nENTER YOUR CHOICE NO.  ";
          cin>>mod_choice;
          if(mod_choice!=5)
          {
               cout<<"\n ENTER THE MEMBERSHIP CODE ----------->";
               cin>>code;
               file.open("clubfile.dat",ios::in|ios::out);
               file.seekg(0,ios::beg);
               file.read((char*)&member, sizeof(member));
               int n=file.tellg();
               while(!file.eof())
               {
                    if(code==member.mem_code)
                    {
                         switch(mod_choice)
                         {
                              case 1 : clrscr();
                              cout<<"\n ENTER THE NEW ADDRESS --->";
                              gets(member.address);
                              file.seekg(n-sizeof(member));
                              file.write((char *)&member,sizeof(member));
                              file.flush();
                              break;
                              case 2 : clrscr();
                              cout<<"\n ENTER THE NEW PHONE NO. --->";
                              cin>>member.phone_no;
                              file.seekg(n-sizeof(member));
                              file.write((char *)&member,sizeof(member));
                              file.flush();
                              break;
                              case 3 : clrscr();
                              cout<<"\n ENTER THE NEW FACILITY CODE NO. 1--->";
                              cin>>member.fac_code1;
                              cout<<"\n ENTER THE NEW FACILITY CODE NO. 2--->";
                              cin>>member.fac_code2;
                              cout<<"\n ENTER THE NEW FACILITY CODE NO. 3--->";
                              cin>>member.fac_code3;
                              file.seekg(n-sizeof(member));
                              file.write((char *)&member,sizeof(member));
                              file.flush();
                              break;
                              case 4 : clrscr();
                              cout<<"\n ENTER NO. OF CHILDREN ABOVE 12 --->";
                              cin>>member.no_of_child;
                              file.seekg(n-sizeof(member));
                              file.write((char *)&member,sizeof(member));
                              file.flush();
                              break;
                         }
                    }
                    file.read((char*)&member,sizeof(member));
                    n=file.tellg();
               }
               file.close();
          }
     }while(mod_choice!=5);
     clrscr();
     cout<<"\n YOU ENDED THE MODIFY SESSION ";
     cout<<" \n THANK YOU !";
     delay(700);
}
void club_mem::search_object()
 {
     fstream infile;
     int search_choice;
     long int phno;
     unsigned long code;
     char name[20];
     do
     {
          int counter=0;
          clrscr();
          cout<<"\n       SEARCH MENU      ";
          cout<<"\n-------------------------";
          cout<<"\nMEMBER CODE    ..1";
          cout<<"\nMEMBER NAME    ..2";
          cout<<"\nPHONE NUMBER   ..3";
          cout<<"\nEXIT           ..4";
          cout<<"\n\n ENTER YOUR CHOICE NO. ----->";
          cin>>search_choice;
          switch(search_choice)
          {
               case 1 : clrscr();
               cout<<"\n ENTER THE MEMBER CODE TO BE SEARCHED ----->";
               cin>>code;
               infile.open("clubfile.dat",ios::in);
               infile.seekg(0,ios::beg);
               infile.read((char*)&member, sizeof(member));
               while(!infile.eof())
               {
                    if(member.mem_code==code)
                    {
                         counter++;
                         member.show_data();
                    }
                    infile.read((char*)&member, sizeof(member));
               }
               infile.close();
               gotoxy(22,24);
               cout<<"RECORDS FOUND = "<<counter;
               getch();
               break;
               case 2 : clrscr();
               cout<<"\n ENTER THE MEMBER NAME TO BE SEARCHED --->";
               gets(name);
               infile.open("clubfile.dat",ios::in);
               infile.seekg(0,ios::beg);
               infile.read((char *)&member, sizeof(member));
               while(!infile.eof())
               {
                    if(strcmp(member.mem_name,name)==0)
                    {
                         counter++;
                         member.show_data();
                    }
                    infile.read((char*)&member, sizeof(member));
               }
               gotoxy(22,24);
               cout<<"RECORDS FOUND = "<<counter;
               getch();
               break;
                case 3 : clrscr();
               cout<<"\n ENTER THE PHONE NO. TO BE SEARCHED --->";
               cin>>phno;
               infile.open("clubfile.dat",ios::in);
               infile.seekg(0,ios::beg);
               infile.read((char *)&member, sizeof(member));
               while(!infile.eof())
               {
                    if(member.phone_no==phno)
                    {
                         counter++;
                         member.show_data();
                    }
                    infile.read((char*)&member, sizeof(member));
                 }
               gotoxy(22,24);
               cout<<"RECORDS FOUND = "<<counter;
               getch();
               break;
               case 4 : clrscr();
               gotoxy(22,15);
               cout<<"YOU ENDED THE SEARCH SESSION ";
               gotoxy(27,18);
               cout<<"THANK YOU !";
               delay (700);
               break;
          }
     }while(search_choice!=4);
}
void club_mem::facility_availed()
{
     fstream infile;
     cout<<"\n ENTER THE FACILITY CODE FOR SEARCHING ";
     int code;
     cin>>code;
     cout<<"\n FOLLOWING MEMBERS ARE REGISTERED WITH FACILITY CODE NO. "<<code;
     cout<<"\n -------------------------------------------";
     cout<<" \n      MEMBER CODE      NAME       ";
     cout<<"\n -------------------------------------------";
     infile.open("clubfile.dat",ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char *)&member, sizeof (member));
     while(!infile.eof())
     {
          if(code==member.fac_code1||code==member.fac_code2||code==member.fac_code3)
          {
               cout<<"\n"<<setiosflags(ios::left)<<setw(25)<<member.mem_code<<setw(25)<<member.mem_name;
          }
          infile.read((char*)&member, sizeof(member));
     }
     infile.close();
     cout<<"\n --------------------------------------------";
     gotoxy(20,24);
     cout<<"PRESS ANY KEY TO CONTINUE";
     getch();
}
void club_mem::membership_card()
{
     fstream infile;
     infile.open("clubfile.dat", ios::in);
     infile.seekg(0,ios::beg);
     infile.read((char *)&member, sizeof(member));
     while(!infile.eof())
     {
          clrscr();
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n                 BAL BHARTI SCHOOL SPORTS CLUB            ";
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n\n           MEMBERSHIP CARD                            ";
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n\n      NAME :"<<setiosflags(ios::left)<<setw(20)<<member.mem_name<<"CODE : "<<mem_code;
          cout<<"\n      ADDRESS :"<<setiosflags(ios::left)<<setw(20)<<member.address;
          cout<<"PHONE NO. :"<<member.phone_no;
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n\n FACILITY CODE 1 FACILITY CODE 2 FACILITY CODE 3  ";
          cout<<"\n    "<<setiosflags(ios::left)<<setw(18)<<member.fac_code1<<setw(18)<<member.fac_code2<<setw(15)<<member.fac_code3;
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n\n"<<setiosflags(ios::right)<<setw(60)<<"MANAGER";
          cout<<"\n --------------------------------------------------------------------------------";
          cout<<"\n --------------------------------------------------------------------------------";
          gotoxy(20,24);
          cout<<"PRESS ANY KEY TO CONTINUE";
          getch();
          infile.read((char *)& member,sizeof(member));
     }
     infile.close();
}
void facility:: reports()
{
     fstream infile;
     int report_choice;
     do
     {
          clrscr();
          cout<<"\n        REPORT MENU     ";
          cout<<"\n ------------------------";
          cout<<"\n LIST OF ALL MEMBERS WITH ALL FIELDS                         ..1";
          cout<<"\n LIST OF FACILITIES AVAILABLE IN THE CLUB                    ..2";
          cout<<"\n ACTIVITYWISE MEMBER CODE AND MEMBER's NAME                  ..3";
          cout<<"\n DATEWISE FEES COLLECTED FROM MEMBERS IN A PARTICULAR MONTH  ..4";
          cout<<"\n LIST OF MEMBERS WHOSE FEES IS DUE IN THE CURRENT MONTH      ..5";
          cout<<"\n MEMBERSHIP CARD FOR EACH MEMBER                             ..6";
          cout<<"\n EXIT REPORTS SESSION                                        ..7";
          cout<<"\n\n REPORT ON WHAT ? < ENTER CHOICE NO. > ------------> ";
          cin>>report_choice;
          switch(report_choice)
          {
               case 1 : clrscr();
               member.show_object();
               break;
               case 2 : fac.show_facility();
               getch();
               break;
               case 3 : clrscr();
               member.facility_availed();
               break;
               case 4 : clrscr();
               fees.fees_collection();
               break;
               case 5 : clrscr();
               fees.fees_due();
               break;
               case 6 : clrscr();
               member.membership_card();
               break;
               case 7 : clrscr();
               gotoxy(22,15);
               cout<<"YOU ENDED THE REPOT SESSION";
               gotoxy(27,18);
               cout<<"THANK YOU !";
               delay(700);
               break;
          }
     }while(report_choice!=7);
}
void graphic_screen()
{
     int driver, mode;
     driver=DETECT;
     initgraph(&driver, &mode,"");
     setbkcolor(10);
     setcolor(1);
     settextstyle(4,0,8);
     outtextxy(150,50," B B S");
     outtextxy(20,250," SPORTS CLUB");
     delay(5000);
     closegraph();
     initgraph(&driver, &mode,"");
     setbkcolor(10);
     setcolor(1);
     settextstyle(0,0,9);
     outtextxy(100,100,"CREATED");
     settextstyle(0,0,6);
     outtextxy(250,250,"BY");
     delay(5000);
     closegraph();
     initgraph(&driver, &mode,"");
     setbkcolor(10);
     setcolor(1);
     settextstyle(0,0,5);
     outtextxy(60,100,"abc");
     outtextxy(250,200,"AND");
     outtextxy(95,300,"pqr");
     delay(5000);
     closegraph();
     initgraph(&driver, &mode,"");
     setbkcolor(10);
     setcolor(1);
     settextstyle(0,0,5);
     outtextxy(60,100,"GUIDED BY");
     outtextxy(50,250,"xyz");
     //outtextxy(250,350,"klm");
     delay(5000);
     closegraph();
}
void main()
{
     int main_choice;
     graphic_screen();
     do
     {
          clrscr();
          gotoxy(22,7);
          cout<<"   MAIN MENU   ";
          gotoxy(22,8);
          cout<<"----------------";
          gotoxy(22,10);
          cout<<"REGISTER A NEW MEMBER                 ..1";
          gotoxy(22,11);
          cout<<"REMOVE A MEMBER                       ..2";
          gotoxy(22,12);
          cout<<"MODIFY INFORMATION ABOUT A MEMBER     ..3";
          gotoxy(22,13);
          cout<<"SEARCH FOR INFORMATION ABOUT A MEMBER ..4";
          gotoxy(22,14);
          cout<<"ENTRY OF FEES IN FEES FILE            ..5";
          gotoxy(22,15);
          cout<<"ADD NEW FACILITY IN FACILITY FILE     ..6";
          gotoxy(22,16);
          cout<<"REPORTS                               ..7";
          gotoxy(22,17);
          cout<<"EXIT                                  ..8";
          gotoxy(25,20);
          cout<<"ENTER YOUR CHOICE NO. -----------> ";
          cin>>main_choice;
          switch(main_choice)
          {
               case 1 : clrscr();
               member.add_object();
               break;
               case 2 : clrscr();
               member.del_object();
               break;
               case 3 : clrscr();
               member.modify_object();
               break;
               case 4 : clrscr();
               member.search_object();
               break;
               case 5 : clrscr();
               fees.update_fees_file();
               break;
               case 6 : clrscr();
               fac.add_facility();
               break;
               case 7 : clrscr();
               member.reports();
               break;
               case 8 : clrscr();
               gotoxy(25,10);
               cout<<"YOU ENDED THE SESSION";
               gotoxy(27,12);
               cout<<"THANK YOU !";
               delay(1000);
               break;
          }
     }while(main_choice!=8);
}



The problem is that when the project executes, it goes through an infinite loop after it is asked to register a new member. I am not able to correct that loop

Is This A Good Question/Topic? 0
  • +

Replies To: Infinite loop

#2 nuclearfroggy  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 82
  • View blog
  • Posts: 167
  • Joined: 04-August 08

Re: Infinite loop

Posted 20 July 2012 - 03:56 AM

The infinite loop is occurring in the while loop at line 64, for me when the file fails to open. You need to make a test for the file facility.dat actually opening successfully. You also shouldn't test the while loop waiting for eof(), because you'll get a repeating character read at the end. Put the read as the conditional of the while loop.

If you want us to be able to help you please don't use Borland specific headers / functions, like the headers "graphics" and "conio". It makes it unportable so we can't compile it and start working through the code. Also, the Borland compiler is out of date so it would really be better to start using an IDE like Code::Blocks or Visual Studio (express) which are both free and up to date.

I want to help more but I'm in a bit of a rush and there is loads of code to sift through. I'd recommend splitting up the project into several files and header files, for example the class definitions and implementation could go into their own header / cpp files.
Was This Post Helpful? 3
  • +
  • -

#3 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Re: Infinite loop

Posted 22 July 2012 - 11:08 PM

View Postnuclearfroggy, on 20 July 2012 - 03:56 AM, said:

The infinite loop is occurring in the while loop at line 64, for me when the file fails to open. You need to make a test for the file facility.dat actually opening successfully. You also shouldn't test the while loop waiting for eof(), because you'll get a repeating character read at the end. Put the read as the conditional of the while loop.

If you want us to be able to help you please don't use Borland specific headers / functions, like the headers "graphics" and "conio". It makes it unportable so we can't compile it and start working through the code. Also, the Borland compiler is out of date so it would really be better to start using an IDE like Code::Blocks or Visual Studio (express) which are both free and up to date.

I want to help more but I'm in a bit of a rush and there is loads of code to sift through. I'd recommend splitting up the project into several files and header files, for example the class definitions and implementation could go into their own header / cpp files.


Now what can i do?? i have no idea.. you may mention the code to be written instead of the statement at line 64, so that my program runs.
Was This Post Helpful? 0
  • +
  • -

#4 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8031
  • View blog
  • Posts: 13,743
  • Joined: 19-March 11

Re: Infinite loop

Posted 22 July 2012 - 11:13 PM

Rather than asking for a magic bit of code to make it work, think about how to solve the problem.

You know you have a loop - now you have at least one indication of where the loop is. Can you test that hypothesis? Is it correct?

Under what circumstances does the loop become infinite? Can you detect that the loop is going infinite and manually break out of it?

DIC is a great resource, but please, you should be able to at least make some progress on this on your own.
Was This Post Helpful? 1
  • +
  • -

#5 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Re: Infinite loop

Posted 22 July 2012 - 11:24 PM

View Postjon.kiparsky, on 22 July 2012 - 11:13 PM, said:

Rather than asking for a magic bit of code to make it work, think about how to solve the problem.

You know you have a loop - now you have at least one indication of where the loop is. Can you test that hypothesis? Is it correct?

Under what circumstances does the loop become infinite? Can you detect that the loop is going infinite and manually break out of it?

DIC is a great resource, but please, you should be able to at least make some progress on this on your own.


View Postsrajat, on 22 July 2012 - 11:23 PM, said:

View Postjon.kiparsky, on 22 July 2012 - 11:13 PM, said:

Rather than asking for a magic bit of code to make it work, think about how to solve the problem.

You know you have a loop - now you have at least one indication of where the loop is. Can you test that hypothesis? Is it correct?

Under what circumstances does the loop become infinite? Can you detect that the loop is going infinite and manually break out of it?

DIC is a great resource, but please, you should be able to at least make some progress on this on your own.


i want the project to run ASAP! assist me in this
Was This Post Helpful? -2
  • +
  • -

#6 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8031
  • View blog
  • Posts: 13,743
  • Joined: 19-March 11

Re: Infinite loop

Posted 22 July 2012 - 11:32 PM

I'd love to drop my work to debug your 1000 lines of C, but I also have stuff that needs to be finished. If you really want to get help fast, you might try to refine your question. Can you at least verify that the problem is in one particular area of the code?
How would you go about that?
Was This Post Helpful? 1
  • +
  • -

#7 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Re: Infinite loop

Posted 22 July 2012 - 11:40 PM

View Postjon.kiparsky, on 22 July 2012 - 11:32 PM, said:

I'd love to drop my work to debug your 1000 lines of C, but I also have stuff that needs to be finished. If you really want to get help fast, you might try to refine your question. Can you at least verify that the problem is in one particular area of the code?
How would you go about that?


The issue in the code is that when the program runs, in the menu when we enter the choice no.1 i.e to register an new member, and after that we are asked to answer a question whether yes or no. after pressing yes the program goes to an infinite loop.
This is the major issue
Was This Post Helpful? 0
  • +
  • -

#8 Skydiver  Icon User is online

  • Code herder
  • member icon

Reputation: 3663
  • View blog
  • Posts: 11,486
  • Joined: 05-May 12

Re: Infinite loop

Posted 22 July 2012 - 11:47 PM

I would imagine an infinite loop would be an issue. I'd be concerned, too.

What have you done to verify the problem is in one particular area of code? Have you stepped through it with a debugger? Have you tried putting in the file that it seems to want to have present? Have you simply tried disabling the code to see if that fixes the infinite loop? Have you tried implementing the fixes suggested in post #2?

Before post #2, it seemed like you yourself didn't know what was causing the infinite loop. We are not seeing any evidence in this thread of you trying to help yourself other than asking somebody else to fix the problem for you.
Was This Post Helpful? 0
  • +
  • -

#9 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Re: Infinite loop

Posted 22 July 2012 - 11:53 PM

View PostSkydiver, on 22 July 2012 - 11:47 PM, said:

I would imagine an infinite loop would be an issue. I'd be concerned, too.

What have you done to verify the problem is in one particular area of code? Have you stepped through it with a debugger? Have you tried putting in the file that it seems to want to have present? Have you simply tried disabling the code to see if that fixes the infinite loop? Have you tried implementing the fixes suggested in post #2?

Before post #2, it seemed like you yourself didn't know what was causing the infinite loop. We are not seeing any evidence in this thread of you trying to help yourself other than asking somebody else to fix the problem for you.


Thanks for your help.
Was This Post Helpful? 0
  • +
  • -

#10 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8031
  • View blog
  • Posts: 13,743
  • Joined: 19-March 11

Re: Infinite loop

Posted 22 July 2012 - 11:56 PM

So in here, eh?


void club_mem::add_object()
504	{
505	   fstream outfile;
506	   char choice='y';
507	   while (choice=='y')
508	   {
509	      clrscr();
510	      cout<<"\n DO YOU WANT TO SEE THE LIST OF FACILITIES AVAILABLE IN THE CLUB ? ";
511	      cout<<"\n YOU ARE ADVISED TO ENTER 'y' BEFORE FILLING THE FORM ";
512	      cout<<"\n ENTER y/n ---------> ";
513	      char ch;
514	      cin>>ch;
515	      if(ch=='y'||ch=='Y')
516	      {
517	     fac.show_facility();
518	     gotoxy(20,24);
519	     cout<<"PRESS ANY KEY TO CONTINUE";
520	     getch();
521	      }
522	      outfile.open("clubfile.dat",ios::app);
523	      member.get_data();
524	      outfile.write((char *)&member, sizeof(member));
525	      outfile.flush();
526	      outfile.close();
527	      add_fees_object(member.mem_code, member.date_of_joining, member.payment_code);
528	      cout<<"\n ANY MORE RECORD TO BE ENTERED <<y/n>> -------> ";
529	      cin>>choice;
530	      }
531	}



The question you refer to is the one at 512?
Now, help us narrow it down a little. When you see these lines:
 
510	      cout<<"\n DO YOU WANT TO SEE THE LIST OF FACILITIES AVAILABLE IN THE CLUB ? ";
511	      cout<<"\n YOU ARE ADVISED TO ENTER 'y' BEFORE FILLING THE FORM ";
512	      cout<<"\n ENTER y/n ---------> ";


and you hit 'y', what happens then? Do you enter the show_facility function? You can use a debugger or simply insert a print statement to find out. If you enter that function, how far do you get in it? Where is it that you get hung up?
If you get through that function, you'll get to the "PRESS ANY KEY TO CONTINUE" statement - does this happen?

You can find all of this out by either probing with prints or by using a step-through debugger. Please give it a try.
Was This Post Helpful? 1
  • +
  • -

#11 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Re: Infinite loop

Posted 23 July 2012 - 12:01 AM

View Postjon.kiparsky, on 22 July 2012 - 11:56 PM, said:

So in here, eh?


void club_mem::add_object()
504	{
505	   fstream outfile;
506	   char choice='y';
507	   while (choice=='y')
508	   {
509	      clrscr();
510	      cout<<"\n DO YOU WANT TO SEE THE LIST OF FACILITIES AVAILABLE IN THE CLUB ? ";
511	      cout<<"\n YOU ARE ADVISED TO ENTER 'y' BEFORE FILLING THE FORM ";
512	      cout<<"\n ENTER y/n ---------> ";
513	      char ch;
514	      cin>>ch;
515	      if(ch=='y'||ch=='Y')
516	      {
517	     fac.show_facility();
518	     gotoxy(20,24);
519	     cout<<"PRESS ANY KEY TO CONTINUE";
520	     getch();
521	      }
522	      outfile.open("clubfile.dat",ios::app);
523	      member.get_data();
524	      outfile.write((char *)&member, sizeof(member));
525	      outfile.flush();
526	      outfile.close();
527	      add_fees_object(member.mem_code, member.date_of_joining, member.payment_code);
528	      cout<<"\n ANY MORE RECORD TO BE ENTERED <<y/n>> -------> ";
529	      cin>>choice;
530	      }
531	}



The question you refer to is the one at 512?
Now, help us narrow it down a little. When you see these lines:
 
510	      cout<<"\n DO YOU WANT TO SEE THE LIST OF FACILITIES AVAILABLE IN THE CLUB ? ";
511	      cout<<"\n YOU ARE ADVISED TO ENTER 'y' BEFORE FILLING THE FORM ";
512	      cout<<"\n ENTER y/n ---------> ";


and you hit 'y', what happens then? Do you enter the show_facility function? You can use a debugger or simply insert a print statement to find out. If you enter that function, how far do you get in it? Where is it that you get hung up?
If you get through that function, you'll get to the "PRESS ANY KEY TO CONTINUE" statement - does this happen?

You can find all of this out by either probing with prints or by using a step-through debugger. Please give it a try.

After pressing the "y" the code goes into an infinite loop. it doesn't enter the show_facility function. That is the major concern
Was This Post Helpful? 0
  • +
  • -

#12 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8031
  • View blog
  • Posts: 13,743
  • Joined: 19-March 11

Re: Infinite loop

Posted 23 July 2012 - 12:04 AM

Quote

After pressing the "y" the code goes into an infinite loop. it doesn't enter the show_facility function. That is the major concern


Do you know this to be true? What have you done to test it?

I frankly see no way for it to fail to enter that method, so you'd better have a good answer for this. If you're not sure, test the bastard.
Was This Post Helpful? 1
  • +
  • -

#13 srajat  Icon User is offline

  • New D.I.C Head

Reputation: -2
  • View blog
  • Posts: 8
  • Joined: 19-July 12

Re: Infinite loop

Posted 23 July 2012 - 12:14 AM

View Postjon.kiparsky, on 23 July 2012 - 12:04 AM, said:

Quote

After pressing the "y" the code goes into an infinite loop. it doesn't enter the show_facility function. That is the major concern


Do you know this to be true? What have you done to test it?

I frankly see no way for it to fail to enter that method, so you'd better have a good answer for this. If you're not sure, test the bastard.


what should i do to test it. I am working on turbo compiler.
Was This Post Helpful? 0
  • +
  • -

#14 jon.kiparsky  Icon User is online

  • Pancakes!
  • member icon


Reputation: 8031
  • View blog
  • Posts: 13,743
  • Joined: 19-March 11

Re: Infinite loop

Posted 23 July 2012 - 12:16 AM

Look for a necessary consequence of the code entering that function. Something obvious and unmistakeable. If there isn't one (there isn't) then make one. For example, put a print statement in it that executes if the function is entered. If you see that print statement, you got to there.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1