Thread: i need help with Tel. Directory

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    5

    i need help with Tel. Directory

    I need help with this program,actually i want to do Telephone directory,that will search an existing user by either name,surname ,tel.number so on so forth .I have already started it and have some skeletons of intended methods that i'd like to include in it .problem being how to write their implementations

    Code:
    #include <iostream>
    #include <fstream>
    #include <string>
    using namespace std;
    
    struct Personal_info
    {
    string name;
    string Last_name;
    int Mobil_Num;
    string email;
    };
    
    struct Address
    {
    string city;
    string street;
    };
    
    class Telephone_Dir
    {
    // I have used arrays of the structs Personal_info and Address to hold the information in the directory
    // We want on directory to hold a large number of entries, so each Telephone_Dir class has a large array of
    //   Personal_info and Address structs.
    public:
    Telephone_Dir();
    Telephone_Dir(int);
    void AddEntry(Personal_info,Address);
    void AddEntry();
    void Display();
    void SearchForEntry();
    void ShowHelp();
    
    private:
    int size_of_directory;
    int num_of_entries;
    Personal_info *pers;
    Address *addr;
    };
                            
    Telephone_Dir::Telephone_Dir() // Constructor for Telephone class
                                   // Initialize all private values.
    {
    size_of_directory = 400;
    num_of_entries = 0;
    pers = new Personal_info[size_of_directory];
    addr = new Address[size_of_directory];
    }
    
                                        // Constructor that takes in specified size of directory
    Telephone_Dir::Telephone_Dir(int size) 
    {
    size_of_directory = size;
    num_of_entries = 0;
    pers = new Personal_info[size_of_directory];
    addr = new Address[size_of_directory];
    }
    
    
    void Telephone_Dir::AddEntry(Personal_info P_info,Address Addr_orig)
    {
    pers[num_of_entries] = P_info;
    addr[num_of_entries] = Addr_orig;
    num_of_entries++;
    }
    
    void Telephone_Dir::AddEntry()
    {
    string surname = "";
    
    cout << "User entry module" << endl;
    
    char quit_char = 'Y';
    while(quit_char == 'Y' || quit_char == 'y')
    {
    cout << endl << "Add Entry #" << num_of_entries << endl;
    cout << "\n*************\n" << endl;
    cout << "Name: ";
    cin >> pers[num_of_entries].name;
    cout << "Surname: ";
    cin >> pers[num_of_entries].Last_name;
    cout << "Email: ";
    cin >> pers[num_of_entries].email;
    cout << "Mobile: ";
    cin >> pers[num_of_entries].Mobil_Num;
    cout << "City: ";
    cin >> addr[num_of_entries].city;
    cout << "Street: ";
    cin >> addr[num_of_entries].street;
    // Add in rest of input
    
    cout << "Successfully added Entry #" << num_of_entries << endl;
    cout << "Do you want to add another? [Y/N] ";
    cin >> quit_char;
    num_of_entries++;
    }
    
    }
    
    void Telephone_Dir::Display()
    {
    // Display entire Directory?
    for (int i=0; i<num_of_entries; i++) {
         cout << "Entry #" << i << endl;
         cout << "---------" << endl;
         cout << "Name: " << pers[i].name << endl;
         cout << "Surname: " << pers[i].Last_name << endl;
         cout << "Email: " << pers[i].email << endl;
         cout << "Mobile: " << pers[i].Mobil_Num << endl;
         //Add in prints for rest of fields
         cout << "City: " << addr[i].city << endl;
         cout << "Street: " << addr[i].street << endl << endl;
         }
    }
    
    void Telephone_Dir::SearchForEntry()
    
    {
    	char option;
    cout<<"\nAre u searching according to Personal information or Address ?\n ";
    cout<<"\nThen type in either keyword (P) for the first choice or (A) for the latter\n ";
          cin>>option;
    	  if (option='P'||'p')
    	  
    	  {
    		  char str;
    		  cout<<"\nEnter an entry u r looking for\n";
    		  cin>>str;
              
    		
    
    
    
    }

  2. #2
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    You have the itchiest trigger finger I've ever seen - I'm refering
    to this duplication

    One of these should be closed and the remaining one moved to
    C++ board.

    Now we don't like multiple threads on the same topic, especially
    when you have a 3rd one here with same title but a different
    problem

    Which also happens to have been asked by you here
    Without appearing too interested in working.

    If you are a real person and not a bot - collect your thoughts
    before you post a new thread, and it's the internet - a single
    click will suffice!
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,656
    Other post deleted
    This moved to C++ forum
    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.

  4. #4
    The superhaterodyne twomers's Avatar
    Join Date
    Dec 2005
    Location
    Ireland
    Posts
    2,273
    Code:
    Telephone_Dir::Telephone_Dir(int size) 
    {
    size_of_directory = size;
    num_of_entries = 0;
    pers = new Personal_info[size_of_directory];
    addr = new Address[size_of_directory];
    }
    You don't need to declare a new variable 'size_of_directory' here. You could just have used the 'size' one which was passed into the function.

    Code:
    		  char str;// should that be 'string str'?
    
    		  cout<<"\nEnter an entry u r looking for\n";
    		  cin>>str;
    After this you could possibly do something very similar to what was done in the adding loop ...
    Code:
    for ( int i=0; i<size_of_directory; i++ )
    {
    	if ( str == FirstName || str == LastName )
    	{// I know FirstName and LastName weren't your variables.
    		cout<< "MATCH!";
    		// etc.
    	}
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to tell if a file or directory
    By swappo in forum C++ Programming
    Replies: 4
    Last Post: 07-07-2009, 10:57 AM
  2. Profiler Valgrind
    By afflictedd2 in forum C++ Programming
    Replies: 4
    Last Post: 07-18-2008, 09:38 AM
  3. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  4. Replies: 6
    Last Post: 07-30-2003, 03:08 AM
  5. Directory reading trouble
    By samGwilliam in forum Linux Programming
    Replies: 0
    Last Post: 03-10-2002, 09:43 AM