Thread: simple database program error

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    38

    simple database program error

    hi im getting a starnge error in my search functions

    heres the function
    Code:
    void store::findE(void)
    {
    	int i = 0;
    	bool sCompare = false;
    	char fName[20];
    	
    	cout << "please enter the name of the person you wish to find their email address :  ";
    	gets(fName);
    
    	for(i = 0; i < Voters; i++)
    	{
    		if(!strcmp(np[i].name, fName))
    		  {
    		 	 cout << "Eurkia \n" << np[i].name <<"\n" << np[i].email  ;
    		 	 sCompare = true;
    		  }
    	}
     
    	if(sCompare == false)
    	  {
    	 	 cout << "Sorry record not found.";
    	  }
    }
    the error sayes " no 'void store::findE()' member function decleared in class store"

    the programs "main" section also cant find this function

    any help would be very mush appreciated

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Perhaps you left it out of your class declaration? Incidentally, you might want to read about Why gets() is bad.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Nov 2006
    Posts
    38
    yes i have stupid me also i realise gets is evil but i was told to use it and i have resurched other ways of doing the same thing but ill stick to what my tutor wants for now

    thanks alot

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Its not evil, its just unkind to those who aren't aware of its behavior

  5. #5
    Registered User
    Join Date
    Nov 2006
    Posts
    38

    Question new problem

    k i have those errors fixed and my program compiles but now for some reason i cant get past the first call function here's the full code (its quite big)
    Code:
    #include <iostream.h>
    #include <string.h>
    #include <fstream.h>
    #include <stdio.h>
    #include <conio.h>
    
    
    //-----------------------------------
    #define Voters 10
    
      class people 
    	{
     	 public:
    	 struct details 
    	  {
           char name[20];
           char phone[20];
    	   char address[100];
    	   char email[30];
    	   char party[20];
          }np[Voters]; 
    	    
         void clearary(void);
         void enter(int);
         void list(void);
        
         
    	 };
    
    
     
        class store: public people 
    	 {
    	  public:
    	  void save(void);
    	  void load(void);
    	
    	  void findF(void);
    	 void findA(void);
    	 void findT(void);
    	 void findE(void);
    	 void findP(void);
         };
    
        char name[12]="terry young";
    	
    //------------------------------------
    
    int main (void)
    {
      people datab;
      store tdata;
      char any;
      
      char choice;
      char choice2;
      float count = 0;
      float count2 = 0;
      int c; 
      
      tdata.clearary();
      
      cout<<"\nThis program will allow the user to create and then control a database. \n";
      
       
      cout<<"what would you like to do? \n To enter a new record press n \n"
    "To delete a record press d \nTo view a full list of the users with details press f \n"
    "To view serch options press s\n to quit press q :- ";
      cin>>choice;
       
    
     while(count == 0) 
     {
          choice = getchar ();
    	  switch(choice)
    	   {
    	    case 'n':
    		 {    tdata.enter(1);
    			  tdata.save();
    		  count = 1;
    		  break;
    		 } 
    		 
        	case 'd':
    		 {
    		  //delete a record ??
    		  count = 1;
    		  break;
    		 }
    		 
    		 case 'f':
    		 {
    		  tdata.list();
    		  count = 1;
    		  break;
    		 }
    		 
    		case 's':
    		 {
    		    	cout<<"search options \n";
    				cout<<"what would you like to do? \nTo search for full contact details press F \n"
    "To search for addresses  press A \n"
    "To search for telephone numbers press T \n"
    To search for email address press E\n"
    To search for the members of a politial party press P\n"
    To quit press Q :- ";
      				cin>>choice2;
    			
    			
    				while(count2 = 0) 
     					{
         				 choice2 = getchar ();
    	 				 switch(choice2)
    	   					{
    	   					 case 'F':
    		 	 	 	 	  {
    						   tdata.findF();
    		 	 	 	 	    count2 = 1;
    		     	 	 	    break;
    		    			  } 
    		 	
        					 case 'A':
    		 				  {
    						   tdata.findA();
    		                    count2 = 1;
    		                    break;
    		                  }
    		 
    						 case 'T':
    		                  {
    						  tdata.findT();
    		          	  	    count2 = 1;
    		                    break;
    		                  } 
    		 
    		                 case 'E':
    		 				  {
    						  tdata.findE();
    		          	  	    count2 = 1;
    		                    break;
    		                  }
             
    						 case 'P':
                     	 	  {
    						  tdata.findP();
    		                    count2 = 1;
    		                    break;
    		                  }
    						 case 'Q':
    						  {
    						   count2 = 1;
    						   break;
    						  }
    					} //end of switch
    		    
    		  count = 1;
    		  break;
    		 } 
    		 
    		         
    		 case 'q':
    		 {
    		   count = 1;
    		   break;
    		 }
    		 
    	      
    	
    	  } //end of switch
    	}
    	
      any = getch();
      return(0);
    	
    
    }// end of main
    
    }
     void people::clearary(void)
      {
    	int i;
    	cout << "  Clearing array..";
    	for(i=0;i<Voters;i++)
    	 {
    	  *np[i].name='\0';
    	  *np[i].phone='\0';
    	  *np[i].address='\0';
    	  *np[i].email='\0';
    	  *np[i].party='\0';
    	 }
     }
    
    //..........................................
     void people::enter(int i) 
       {
        char k = 'y'; 
    	 while (k == 'y'); 
    	   { 
    	    cout << "Enter the name of the person ";
    	     gets(np[i].name);
            cout << "Enter the phone number of the person ";
    	     gets(np[i].phone);
    		cout << "Enter the full address of the person ";
    		 gets(np[i].address); 
    		cout << "Enter the Email address of the person";
    		 gets(np[i].email);
    		cout << "enter the name of the party that the person belongs to ( conservative, labour, liberal, other)";
    		 gets(np[i].party);
    		cout << "Do you wish to enter another member ? (y/n)";
    		cin  >> k;
    		}
    	}
    	// end of enter member function
    
    //******************************************************************************* 
     void store::save(void) {
    	fstream outfile;
    	int i;
    	cout << "Saving.." << endl;
    	outfile.open("c:\\quincy2002\\tel.dat",ios::out);
    	for(i=0;i<Voters;i++) {
    	  outfile.write((char *) &np[i],sizeof(class people));
    	}
    	outfile.close();
    
     }//end of save member function.
    //*******************************************************************************
    
    void store::load(void) {
     	fstream infile;
    	int i;
    	cout << "Loading.." << endl;
    	infile.open("c:\\quincy2002\\tel.dat",ios::in);
    	for(i=0;i<Voters;i++) {
    	  infile.read((char *) &np[i],sizeof(class people));
    	}
    
    	infile.close();
    
     }//end of load member function. 
    //********************************************************************************
    
     void people::list(void) 
     {
    	int i;
    	cout << "Listing.." << endl;
    	for (i=0;i<13;i++) 
    	{
    	  cout << "\nName " << np[i].name << endl;
    	  cout << "\nPhone No " << np[i].phone << endl;
    	  cout << "\nAddress " << np[i].address <<endl;
    	  cout << "\nEmail " << np[i].email <<endl;
    	  cout << "\nPolitical Party " << np[i].party <<endl; 
    	}//end of for loop
    }// end of list member fuction. 
    
    //********************************************************************************
    
    void store::findF(void)
    {
    	int i = 0;
    	bool serch = false;
    	char person[20];
    	
    	cout << "please enter the name of the person you wish to find their details :  ";
    	gets(person);
    
    	for(i = 0; i < Voters; i++)
    	{
    		if(!strcmp(np[i].name, person))
    		  {
    		 	 cout << "Eurkia \n" << np[i].name <<  "\n" << np[i].phone << "\n" 
    		 	      << np[i].address << "\n" << np[i].email << "\n" << np[i].party ;
    		 	 serch = true;
    		  }
    	}
     
    	if(serch == false)
    	  {
    	 	 cout << "Sorry record not found.";
    	  }
    }
    
    //*****************************************************************************************
    void store::findA(void)
    {
    	int i = 0;
    	bool serch = false;
    	char person[20];
    	
    	cout << "please enter the name of the person you wish to find their address :  ";
    	gets(person);
    
    	for(i = 0; i < Voters; i++)
    	{
    		if(!strcmp(np[i].name, person))
    		  {
    		 	 cout << "Eurkia \n" << np[i].name <<  "\n" << np[i].address; 
    			 serch = true;
    		  }
    	}
     
    	if(serch == false)
    	  {
    	 	 cout << "Sorry record not found.";
    	  }
    }
    
    //***************************************************************************************************
    
    void store::findT(void)
    {
    	int i = 0;
    	bool serch = false;
    	char person[20];
    	
    	cout << "please enter the name of the person you wish to find their phone number :  ";
    	gets(person);
    
    	for(i = 0; i < Voters; i++)
    	{
    		if(!strcmp(np[i].name, person))
    		  {
    		 	 cout << "Eurkia \n" << np[i].name <<  "\n" << np[i].phone ;
    		 	 serch = true;
    		  }
    	}
     
    	if(serch == false)
    	  {
    	 	 cout << "Sorry record not found.";
    	  }
    }
    //*********************************************************************************************************
    
    void store::findE(void)
    {
    	int i = 0;
    	bool serch = false;
    	char person[20];
    	
    	cout << "please enter the name of the person you wish to find their email address :  ";
    	gets(person);
    
    	for(i = 0; i < Voters; i++)
    	{
    		if(!strcmp(np[i].name, person))
    		  {
    		 	 cout << "Eurkia \n" << np[i].name <<"\n" << np[i].email  ;
    		 	 serch = true;
    		  }
    	}
     
    	if(serch == false)
    	  {
    	 	 cout << "Sorry record not found.";
    	  }
    }
    //********************************************************************************************
    
    void store::findP(void)
    {
    	int i = 0;
    	bool serch = false;
    	char fParty[20];
    	
    	cout << "please enter the name of the party you wish to find (conservitive, labour, libral or other) :  ";
    	gets(fParty);
    
    	for(i = 0; i < Voters; i++)
    	{
    		if(!strcmp(np[i].party, fParty))
    		  {
    		 	 cout << "Eurkia \n" << np[i].name <<  "\n" << np[i].party ;
    		 	 serch = true;
    		  }
    	}
     
    	if(serch == false)
    	  {
    	 	 cout << "Sorry record not found.";
    	  }
    }
    
    //*************************END************************************************************************
    also i have to add the load function in here somewere (the functions writen just not sure were to call it)

    so can any one help

    (also im using Quincy to write and compile it)
    Last edited by Salem; 05-13-2007 at 06:11 AM. Reason: Folding long lines.

  6. #6
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    <iostream.h> and <fstream.h> should be <iostream> and <fstream> respectively.

    It looks like having a people class is not quite right, or at least does not really help you at all. You should have a person class, and then use a container such as a vector to store person objects. If such standard containers are not permitted, then you can have your people class keep an array of person objects. Remove store class as it is just acting like a namespace (a way to group things such as functions and classes). As it stands, you might as well just have a details struct and let all the functions be free functions that operate on an array of detail objects.

    Once you do have an array (or other container) of person objects, you can then have your other functions be free functions that operate on this container. You still might want to provide a clear() member function to reset a person object, though from the looks of your code a well written default constructor will do.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    38

    Question

    hi im not totaly sure what u mean my knollage of c++ is not great could you give me an exampel

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. how do you resolve this error?
    By -EquinoX- in forum C Programming
    Replies: 32
    Last Post: 11-05-2008, 04:35 PM
  3. using c++ in c code
    By hannibar in forum C Programming
    Replies: 17
    Last Post: 10-28-2005, 09:09 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  5. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM