CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Apr 2011
    Posts
    2

    Newbie Question, help please!

    Hello,
    i'm working on an assignment for school.
    i'm doing in visual c++ using borland.
    i have a requirement to do the following:
    1. Load Given a txt file which has a number of records (not specified) of student IDs and their date of enrollment.
    2. Ability to filter Students by their ID
    3. Ability to filter Students by Date of enrollment
    4. Show the filtered result.
    Below is an example of one line of the mentioned text file:
    //Student ID, Date Enrolled,Name Abreviation
    01368,2010-11-29,Ru88

    What i've done so far:

    1. Created visually the needed setup as such:

    i. ComboBox (contains Student IDs, which i've added manually)
    ii. DateTimePicker (added two with name: From and To)
    iii. RadioButton (Labeled as ALL records, DATEdResult( which will set the DATETimePIcker to enabled and visible to show a specific date)
    iV. StringGrid.
    v. main menu with open dialog.

    What i need advice with:

    1. how can i load the text file in a way that i can take the comma as a delimiter. in other words, how can i sort by date (given that date is the second field.

    3. am i correct to use stringgrid? would a memo be better suited for just showing the output?

    Thank you for you advice in advance.

  2. #2
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Newbie Question, help please!

    Quote Originally Posted by rollyah View Post
    What i've done so far:

    1. Created visually the needed setup as such:

    i. ComboBox (contains Student IDs, which i've added manually)
    ii. DateTimePicker (added two with name: From and To)
    iii. RadioButton (Labeled as ALL records, DATEdResult( which will set the DATETimePIcker to enabled and visible to show a specific date)
    iV. StringGrid.
    v. main menu with open dialog.
    You spent time developing the least important parts first.

    Instead of doing this, you should have developed the business logic first. For example, what structure are you storing this information in? How are you filtering -- where is this code? Are you going to use an array, linked list, etc.?

    The very first thing is to write code to read the data into your data structure. Once you have that working, then you work on the filtering, etc. None of these steps require a GUI.

    This is the first thing you spend time on -- fancy GUI's doesn't mean anything if the code underneath that do the actual business rules is either incomplete or not done at all. Once you figure out how to do the business rules of the app, then and only then do you put a GUI wrapper around it. Too many students make the mistake of wasting 80% of the time writing fancy I/O, and when it comes time to actually write the code that is most important, they have only a small amount of time left.

    What's going to happen with your approach is that you are now going to try and fit the these rules into your GUI code -- once you go down that road, you've made the job much more difficult.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Apr 2011
    Posts
    2

    Re: Newbie Question, help please!

    thank you for yoru reply.
    i thought bout starting to code first but i got a bit confused with the fstream part.
    since i'll b using a dialogbox, i'll b doing the work twice?

    anyhow, to answer your questions:

    1. Structure (not sure, can you shed some light on ur qustion? )
    2. sorting // well im thinking of setting them in vector or dynamic array though i'm not entirely familiar with that as the notes ive taken doesnt even mention arrays.
    3. where is this code // is it wrong for me to set the code to execute on date selection click?

    i'm looking around and found getline(a_file_stream, a_string, ',')
    though i'm a bit lost at how to reference each string in order to sort...

  4. #4
    Join Date
    Apr 2008
    Posts
    118

    Re: Newbie Question, help please!

    Is making a GUI a requirement? This would be much easier if you didn't make a GUI, and ran it from console.

  5. #5
    Join Date
    Apr 1999
    Posts
    27,449

    Re: Newbie Question, help please!

    Quote Originally Posted by rollyah View Post
    thank you for yoru reply.
    i thought bout starting to code first but i got a bit confused with the fstream part.
    since i'll b using a dialogbox, i'll b doing the work twice?
    Don't even mention "dialog box" or "combo box" or "buttons" or anything like that. Wasting time writing GUI code that does nothing except lower your chances of getting the important work done.

    Again, a student who doesn't know better always waste their time making the I/O look fancy, while internally, the real important parts of the program are broken, don't work, incomplete, or not even started at all. A program that has the basic business logic coded, but doesn't have all the fancy looking GUI or I/O done is more valuable and gets higher scores than a program with fancy GUI covering up a bunch of crap underneath.

    For example, if I wanted you to build a program that evaluated a mathematical expression, I want to see the correct answers at the end -- what good is it if I can press a neat looking button that says "Evaluate" within a bonzo looking dialog box, but the answer is wrong? Would you go to the teacher and say "but my dialog boxes and buttons look fancy, so that must be worth at least a 'B', right?" So the important part is the collection of data and internal computations. The GUI can be anything, but only after the important parts of the program are sound and working.

    The first thing you should be thinking about and learning is the data structure that you will use to organize the data internally. Then when you decide how to internally represent the data, then you decide how you will populate these internal structures, i.e. reading from a file, user input, etc.
    1. Structure (not sure, can you shed some light on ur qustion? )
    2. sorting // well im thinking of setting them in vector or dynamic array though i'm not entirely familiar with that as the notes ive taken doesnt even mention arrays.
    Your questions prove my point. These questions should have been answered by yourself before writing a single line of code.
    3. where is this code // is it wrong for me to set the code to execute on date selection click?
    This is not important. Answer questions 1 and 2) first and get these coded.

    If you're serious about programming, this is how you organize building a program. You start out with coding the business rules first, and then when that's done, then you code your GUI or whatever interface you want to use to access the various data.
    /Student ID, Date Enrolled,Name Abreviation
    01368,2010-11-29,Ru88
    This would have been a much better starting point.
    Code:
    #include <string>
    #include <fstream>
    #include <vector>
    
    struct StudentInfo
    {
        std::string student_id;
        std::string date_enrolled;
        std::string name_abbreviation;
    };
    
    typedef std::vector<StudentInfo> AllStudentInfo;
    
    using namespace std;
    
    void ReadStudentData( AllStudentInfo& stInfo)
    {
        std::ifstream studData("data.txt");
        if ( studData )
        {
               // read data into stInfo
        }
    }
    
    int main()
    {
        AllStudentInfo theStudentInfo;
        ReadStudentData( theStudentInfo );
    }
    This is a basic skeleton on how you read the data. If you don't know or can't complete this step at the time you read this post, then you concentrate on getting this to work. Once you get that to work, you've read in the data into your internal structures (in this case, a vector of student information), and you can go forward from there.

    Regards,

    Paul McKenzie
    Last edited by Paul McKenzie; April 26th, 2011 at 09:23 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured