Thread: Need help with a big project

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    3

    Need help with a big project

    Im doing a database in c++ for my A-S level coursework and need help trying to do some classes in it. Any help or suggestions at all would be helpful.

    1) I need to create a class that inputs 2 numbers and 2 letters then returns them as an ID for example AR01. If anyone can suggest how i can create a function that can return this or knows a better way, it would be great thanks.

    2) Also i need help trying to work out how to sort the data inputted to then be able to make a binary search algorithm for it. I dont expect anyone to write it for me but to givew me a shove in the right direction.

    Thanks!

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Quote Originally Posted by reado
    Im doing a database in c++ for my A-S level coursework and need help trying to do some classes in it. Any help or suggestions at all would be helpful.

    1) I need to create a class that inputs 2 numbers and 2 letters then returns them as an ID for example AR01. If anyone can suggest how i can create a function that can return this or knows a better way, it would be great thanks.
    That depends on how that should look. Should the user input the ID in one piece? If so, then ask for a string, check if it is in (four i? words - impressive) the correct format, if not ask again, until you get what you want.

    2) Also i need help trying to work out how to sort the data inputted to then be able to make a binary search algorithm for it. I dont expect anyone to write it for me but to givew me a shove in the right direction.

    Thanks!
    Well, you first need to figure out how to compare two entries. Once you've got the code for that, you can make a binary search predicate out of it (ask again) and pass it to the standard sort algorithm.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    3
    Well for the ID class i want the Id to be inputted in the constructor if it was suitable. I was then thinking that it could be stored in one of the following ways.
    1) Two chars two integers
    2) A char array and an int
    3) 4 character variables

    The only problem is creating a GETID function that would return the value stored in the seperate characters... in order.. how could i do this with one function....

  4. #4
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    Why not use a null-terminated character array? It's easy to pass to functions and work with.
    Code:
    class IDClass
    {
    public:
    	IDClass(); // {m_ID[4] = 0;}
    	const char* GetID(); // {memcpy(m_outputID,m_ID,strlen(m_ID)+1);return m_outputID;}
    	void SetID(char* param); // {memcpy(m_ID,param,strlen(m_ID));}
    private:
    	char m_ID[5];
    	char m_outputID[5];
    };
    My quick and dirty implementation is in the comments. If you wanted, you could validate your data in the SetID (if you did, you'd probably want to change the return type to a bool), or you could validate outside of the class before you called SetID. You want a seperate buffer for the GetID so that a user can't use the pointer from GetID to change the real data inside your class.

    This probably isn't the best way, but it could work.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    3
    Excellent thanks for the help.

    I've come accross another probem though..

    For this database i also need to make the tables relational so that say a customer is linked
    to his car (its a garage database) which is linked to anytime its had a fitting.
    My teacher suggested that i link the customer, car and product table all to a fitting table but im wondering how each table can access each other and what to do if the customer hasnt had any fittings... how would i link him to his car?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Project Help please!
    By black_hole??? in forum C++ Programming
    Replies: 4
    Last Post: 04-28-2009, 12:55 AM
  2. Big and little endian
    By Cactus_Hugger in forum C Programming
    Replies: 4
    Last Post: 10-12-2005, 07:07 PM
  3. Game Independent Anti-cheat Project Needs Programmers
    By GIA Project Lea in forum Projects and Job Recruitment
    Replies: 3
    Last Post: 09-15-2005, 07:41 PM
  4. How to add a file to a project in bloodshed.
    By Smeep in forum C++ Programming
    Replies: 4
    Last Post: 04-22-2005, 09:29 PM