Thread: A mini data-base handler. Very primitive but it works.

  1. #1
    Registered User
    Join Date
    Feb 2010
    Location
    Budapest
    Posts
    26

    Cool A mini data-base handler. Very primitive but it works.

    When you put data in double enter is needed. Pass that mistake.

    Code:
    #include<iostream>
    using namespace std;
    
      struct book {
               string author;
               string title;
               string publisher;
               int pubyear;
               float price;
               };
                          
      char op = 'a';   bool idcall=0;  int i=0;
      book *B;
      
      bool choice(char, bool);
      int main();
               
    void datainput(){     
                      int n=0;       
                      book *A; A = new book[i]; B = new book[i]; 
        do{        
            delete[] B;           
            B = new book[i+1];
                       
            cout<<"\n Author: "; getline(cin, B[i].author); cin.ignore();
            cout<<" Title: "; getline(cin, B[i].title); cin.ignore();
            cout<<" Publisher: ";getline(cin, B[i].publisher); cin.ignore();
            cout<<" Publication year: ";cin>> B[i].pubyear; cin.ignore();
            cout<<"\n Price: "; cin>>B[i].price; cin.ignore();
            
                         n=i;
                         if(i!=0)for(i-=1;i>=0;i--)B[i]=A[i];
                         i=n;  delete[] A;                 
                               if(n==0){A = new book[i+1];A[i]=B[i];}
                               else {A = new book[n+1]; for(;n>=0;n--) A[n]=B[n];}                          
                                         i++;
           cout<<"\n\n Would you like to register futher more? (y for Yes, n for No): "; cin>>op; cin.ignore(); idcall=1;
           choice(op, idcall);       
          }while(idcall==0); main();
         
                    } 
                    
    bool choice(char op, bool idcall){
         entry:
         switch(op){
                       case 'y': if(idcall==0) datainput();
                                 else {::idcall=0; return(idcall);}
                       case 'n': if(idcall==0) exit(0);
                                 else return(idcall);
                       default: cout<<"\n Read more careful, please."; 
                                if(idcall==0) cout<<" Would you like to put data in? (y for Yes, n for No): "; cin>>op; cin.ignore(); break;
                                if(idcall==1) cout<<" Would you like to register futher more? (y for Yes, n for No): "; cin>>op; break;
                                 }
                       goto entry;
                                                 
                       }     
              
    int main(){ 
        
                 if(idcall==1) goto lastpart;
                 
                 cout<<" The database editor is ready.\n Are you sure that you would like to put data in? (y for Yes, n for No): ";
                 cin>>op; cin.ignore(); choice(op, 0);
    
    lastpart:             
            for(i-=1;i>=0;i--){cout<<endl<<"\n Author: "<<B[i].author;cout<<endl<<"\n Title: "<<B[i].title; cout<<endl<<"\n Publisher: "<<B[i].publisher;
                               cout<<endl<<"\n Publication year: "<<B[i].pubyear;cout<<endl<<"\n Price: "<<B[i].price;cout<<"\n\n";}   
                 
        cin.get();
     
        }

  2. #2
    Registered User
    Join Date
    Feb 2010
    Location
    Budapest
    Posts
    26
    The prototypes would be first and after main the function definitions. I know.

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Your indentation still needs work.
    SourceForge.net: Indentation - cpwiki

    Tip - if you're using some kind of IDE, then set it to use "spaces for tabs" in the indentation.
    If you mix spaces and real tabs in source code, it may look OK in your editor, but it will be a mess when posted online.

    Oh, and don't use goto's to generate a while loop, and don't call main() recursively.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  2. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  3. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 10:33 AM
  4. C diamonds and perls :°)
    By Carlos in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 05-16-2003, 10:19 PM
  5. can't insert data into my B-Tree class structure
    By daluu in forum C++ Programming
    Replies: 0
    Last Post: 12-05-2002, 06:03 PM