Thread: need help with Tracking user login

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    18

    need help with Tracking user login

    Here is the topic
    [FONT=helvetica, arial, verdana, 'ms sans serif', sans-serif]Each user has a unique five-digit ID number.Whenever a user logs on, the users's ID,lab number,and the computer station number are transmitted to your system.For example,if the user 49193 logs onto station 2 in lab 3, then your sytem recieves(49193,2,3) as input data.Similarly,when a  user logs off a station,then your system receives the lab number and computer station number. write a computer program that could be used to track,by lab which user is logged onto which computer. Create a menu that allows the administrator to simulate the transmission of information by manually typing in the login or logoff data.Whenever someone logs in or out, the display should be update.Also write a search function so that the administrator can type in a use ID and the system will output the lab and station number that user is logged into, or NONE if the user is not logging to any computer.[/FONT]
    Code:
    #include <iostream>#include <cstdlib>
    
    
    using namespace std;
    
    
    int **dynArray(int row, int cols)
    {
        int **myPtr;
        myPtr = new int *[row];
        for(int i = 0; i < row; i++)
        myPtr[i] = new int[cols];
        for(int i = 0; i<row ; i++)
        if(myPtr[i] == 0)
        cout<<"empty";
        
        return myPtr;   
    }
    void getinput(int &ID,int &Station,int &labnumb)
    {
         cout<<" Enter your ID number: "<<endl;
         cin>>ID;
          cout<<" Enter your station number: "<<endl;
         cin>>Station;
          cout<<" Enter your lab number: "<<endl;
         cin>>labnumb;
         return;  
    }
    void getoutput(int &ID,int &Station,int &labnumb)
    {
         cout<< "You have been logged out."<<endl;
        return;
    }
    void login(int **dynArray,int &ID,int &Station,int &labnumb)
    {
         dynArray[labnumb][Station] = ID;
         return;
         
    }
    void search(int **dynArry)
    {
         
    }     
    
    
    void Menu(int **dynArray,int &ID,int &Station,int &labnumb)
    {
         int choice;
         cin>>choice;
         if(choice == 1)
             login(**dynArray,ID,Station,labnumb);
         if(choice == 2)
             search() //This is input later on
    }
    
    
    int main()
    {
        int **lab;
         lab = new int*[4];
        for(int i = 0; i <4 ; i++)
        {
                *(lab + i) = new int;
        }
        
        
        
    
    
            
        lab = dynArray(4,7);
       
          system("PAUSE");
          return 0;
    }
    ;
    I don't know how to declare and write the search function. Also, I need help with what do I need to add to complete the program.Because I kind of mess up everything up@@ If anyone can suggest me to do more thing or less Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Unless int** is specifically part of your assignment, I would suggest you replace it with
    std::vector< std::vector<int> >

    and just pass it (by reference) from one function to another.
    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.

  3. #3
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    I have consider about using vector but i'm not comfortable to use the vector, so that's why I do it this way and here is second version i get so far, the big problem here I don't know do I need to add the adminstration for another function or what because the topic say search function only for admin use. Therefore, am I thinking right or wrong?????
    Code:
    #include <iostream>#include <cstdlib>
    
    
    using namespace std;
    
    
    int **dynArray(int row, int cols)
    {
        int **myPtr;
        int lab[4];
        myPtr = new int *[row];
        for(int i = 0; i < row; i++)
        myPtr[i] = new int[lab[i]];
        for(int i = 0; i<row ; i++)
        if(myPtr[i] == 0)
        cout<<"empty";
        
        return myPtr;   
    }
    void getinput(int ID,int &Station,int &labnumb)
    {
         cout<<" Enter your ID number: "<<endl;
         cin>>ID;
          cout<<" Enter your station number: "<<endl;
         cin>>Station;
          cout<<" Enter your lab number: "<<endl;
         cin>>labnumb;
         return;  
    }
    void logout(int ID,int &Station,int &labnumb)
    {
         
         cout<< "You have been logged out."<<endl;
        return;
    }
    void login(int **dynArray,int ID,int &Station,int &labnumb)
    {
         dynArray[labnumb][Station] = ID;
         return;
         
    }
    bool search(int **dynArry,int ID,int &row,int &cols,int lab[])
    {
         cout<<"Enter user ID to check: "<<endl;
         cin>>ID;
         bool found = false;
         for(int i = 0; i < row;i++)
         for(int j = 0; j < lab[i];j++)
         if(ID == dynArry[i][j])
         {
          found = true;
          row = i;
          cols = j;
          
          }
         return found;
    }     
    
    
    void Menu(int **dynArray,int ID,int &Station,int &labnumb,int lab[])
    {
         int choice;
         cout<<"Enter 1 for login, 2 for search,3 for exit. "<<endl;
         cin>>choice;
         if(choice == 1)
             login(dynArray,ID,Station,labnumb);
         if(choice == 2)
             search(dynArray,ID,Station,labnumb,lab);
         if(choice == 3)
             exit(0);
    }
    
    
    int main()
    {
        int lab[4];
        lab[0] = 5;
        lab[1] = 6;
        lab[2] = 4;
        lab[3] = 3;
        int **labmain;
         labmain = new int*[4];
        for(int i = 0; i <4 ; i++)
        {
                *(labmain + i) = new int;
        }
        
        
        
    
    
            
        labmain = dynArray(4,7);
        int ID,Station,labnumb;
         Menu(dynArray,ID,Station,labnumb,lab);
          system("PAUSE");
          return 0;
    }

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So rather than "get comforable with vectors" by actually confronting the issue and doing some learning, you prefer endless frustration over continually screwing up on mis-managing do it yourself memory allocation.

    If you're not going to use all the tools in the C++ box, why bother with C++ at all?

    > 13 myPtr[i] = new int[lab[i]];
    What is lab[i] here?
    It isn't the carefully initialised array in main.

    > lines 82 to 86
    A complete waste and a memory leak, since line 93 just trashes the pointer with a newly allocated block of memory.

    > Menu(dynArray,ID,Station,labnumb,lab);
    What - dynArray is a FUNCTION, not an array.

    Does this even compile? If not, you should post your error messages as well.
    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.

  5. #5
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    > 13 myPtr[i] = new int[lab[i]];
    What is lab[i] here?
    The lab[i] is the column because the they have 4 row but it has different cols
    From the 82-86 is the labmain pointer point to other 4 small pointer. And each small pointers have one row array but different column.Also, i didn't complete it yet this is the so far i got.
    Moreover, the
    Menu(dynArray,ID,Station,labnumb,lab); is call function isn't it?
    Because I always confuse on the call function and I don't know how to make it right.
    =>It shows one error from the Menu call function in the int main.

  6. #6
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Vectors will make your life so much easier trust me I was anti vector a while back. Now they simplify code so much it makes your life a lot easier same thing with using char*'s and strings, once you get it strings are much nicer. Learn vectors you won't regret it. vector - C++ Reference

    With vectors, all you need to do is push_back when a user logs in; then delete when he logs out. To do a search use a for loop with always less than your vector.size(). It makes life simple. If you don't use vectors you better know how many computers are in the lab before you ever begin and when that number changes you need to recompile or reload from an ini file. Vectors will handle all your problems with memory and make the program more flexible.

  7. #7
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    I'm not sure my teacher let me using the vector because he said if you use vector you won't learn anything.?????

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by erictu
    I'm not sure my teacher let me using the vector because he said if you use vector you won't learn anything.?
    If your aim is to implement a dynamic array container like std::vector, then just using std::vector won't teach you anything concerning implementation, though it will teach you something about a possible interface for a dynamic array container.

    In this case, your aim is to implement something else. A dynamic array is just implementation detail, so using std::vector makes sense. If your teacher also wants you to learn how to implement as a dynamic array as part of the assignment, then the appropriate thing to do is to first design and implement a dynamic array container, and then use that container to implement what you want to implement.
    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

  9. #9
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    that's the way I'm doing now but I get stuckT_T

  10. #10
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Use a struct then with your information ID computer# etc. use your struct as the array type then

  11. #11
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    but the struct is the next chapter, it's not this chapter

  12. #12
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by erictu
    but the struct is the next chapter, it's not this chapter
    Right. Are you sure you are not over-complicating things? You just need one integer variable, not a dynamic array of them, to store "a unique five-digit ID number".
    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

  13. #13
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Use oversized arrays with full values of -1 to represent open spaces. Write a function that looks for a -1 in one array(doesn't matter which) then places your data in all 3 arrays you have to store data. You can loop and look for values != -1 to see who is logged in

  14. #14
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    I think they have multiple users that need their data stored hence the arrays

  15. #15
    Registered User
    Join Date
    Mar 2012
    Posts
    18
    can you give it in the example code because I'm kind of get it but kind of don't know where you mean point at@@

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. User login history - bash
    By garcy in forum Linux Programming
    Replies: 3
    Last Post: 05-17-2011, 10:23 AM
  2. Replies: 8
    Last Post: 12-08-2009, 12:55 PM
  3. Replies: 5
    Last Post: 05-06-2004, 09:14 AM
  4. Tracking Devices, GPS and etc.
    By Liger86 in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 05-14-2003, 05:12 AM
  5. creating a user login system for web pages
    By Nutshell in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 07-04-2002, 11:02 PM