CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Nov 2010
    Posts
    146

    Help with assignment

    ...
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by gulHK; April 14th, 2011 at 10:47 AM.

  2. #2
    Join Date
    Apr 2008
    Posts
    725

    Re: Help with assignment

    lol. Really? If it is too difficult, then the job probably isn't suitable. They want to judge your competency level, not the level of a mish mash of people from some internet forum. Do it yourself.

  3. #3
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Help with assignment

    Break it down into manageable parts:

    Load the flat file
    Parse the flat file
    Convert to libxml's writing structure
    Write xml

  4. #4
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Help with assignment

    Quote Originally Posted by Amleto View Post
    lol. Really? If it is too difficult, then the job probably isn't suitable. They want to judge your competency level, not the level of a mish mash of people from some internet forum. Do it yourself.
    From my experience companies do not much care for original solutions but for the fact that you have found a solution at all. However, they don't like to be lied to and of course they would check if you fully understand the solution and were able to adopt it to different environments.

    So, I think the best is to make an own attempt to solve the task and only if there are major difficulties you should ask for those special issues. If you have no plan at all how to solve the task you also may ask for a general design. But please, explain the task with your own words and don't expect people to open unknown pdf documents.

  5. #5
    Join Date
    Nov 2010
    Posts
    146

    Re: Help with assignment

    Thanks itsmeandnobodyelse for your helpful suggestions . You are right. I will read the task carefully and will try to explain it in my own words

    Have you read the pdf file? would you suggest any design?

  6. #6
    Join Date
    Jun 2009
    Location
    France
    Posts
    2,513

    Re: Help with assignment

    Quote Originally Posted by gulHK View Post
    Thanks itsmeandnobodyelse for your helpful suggestions . You are right. I will read the task carefully and will try to explain it in my own words

    Have you read the pdf file? would you suggest any design?
    This is a simple exercise of reading a file (fileA) of format A, and rewriting it into fileB of format B.

    The standard method is to un-serialize your fileA into generic objects that make sense from a business point of view.
    From there, simply simply re-serialize your objects into fileB.

    a sensible "business object" would be a "partner_accounting_record". A partner file would have fields
    - "partner_id", which is the identity of the current partner: name, address, etc...
    - "partner_sales", which would hold a date range, and a variable amount of sales.

    Remember to break down your task in smaller parts.
    Start by reading in from the file, and just being able to identify the text.

    Second, try to desing your objects so they can easily be filled with text.

    Third, write the serializing code that transforms objects into xml.

    Finally, put all 3 steps together.
    Is your question related to IO?
    Read this C++ FAQ article at parashift by Marshall Cline. In particular points 1-6.
    It will explain how to correctly deal with IO, how to validate input, and why you shouldn't count on "while(!in.eof())". And it always makes for excellent reading.

  7. #7
    Join Date
    Nov 2010
    Posts
    146

    Re: Help with assignment

    Thanks a LOT monarch_dodra once again for helping me

    I will try all your design suggestions.

    Thanks once again

  8. #8
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Help with assignment

    Quote Originally Posted by gulHK View Post
    Thanks itsmeandnobodyelse for your helpful suggestions . You are right. I will read the task carefully and will try to explain it in my own words

    Have you read the pdf file? would you suggest any design?
    First, it is more than a three-hours-job especially if you should write portable code and work your way into a new library. I would assume the short time frame is a test on your honesty and whether you would be able to reason higher efforts you made.

    I would suggest you define two structs, one for master, one for detail. The master struct could hold a vector of detail structs. All text attributes should be std::string. For the address you probably should use a std::vector<std::string> so that you easily can print each single address line.
    Make a superclass which holds a vector of master struct elements and provides the functions to read and parse data from print file and output data to xml file. You could read from file using std::ifstream. If you use forward slashes for separation you could use the same (relative) path name for the input file at different platforms. For parsing the file I would define an enumeration which identifies the different parts of the input (i. e. enum { SUPPLIER, ADDRESS, DATE_CURRENCY, ...}; ) . Read the file using std::getline and have a separate evaluation (member function of superclass) depending on the current (enum) part. For single line parts increment the enum part after parsing. For multi-line evaluations you must detect end-of-current-part and begin-of-next part, e. g. the ADDRESS part ends when you detect a line with two dates and a currency values. You would need a function for extracting a (valid) date anyhow, so you simply could check the first term of a new line in the ADDRESS part whether it is a valid date. If yes, increment to DATE_CURRENCY part with the current line. If not, add a further address line to the address vector of the current master.

    You always should try to have only one instance for any object. So, if you begin to parse the file and have a positive SUPPLIER line, create a new master object in the master vector of the superclass and use a reference to that vector element to fill all the data:

    Code:
       ...
       case SUPPLIER:
             {
                  ret = parseSupplier(supplier);
                  if (ret != OK) return error("Super::parseInputfile", ret);  
                  masters.push_back(Master(supplier)); 
                  nextpart = ADDRESS;
                  break;
             }
    
    // Later you always can get a reference to the current master by calling the member function
    
    Master & Super::getCurrentMaster()
    {
         return masters.back();
    }
    With the same technique you could add and access address lines or detail elements to the containers of the parent classes/structs.

    For implementing the XML part you best try to get sample code for writing with libxml on Windows and Linux platform. If you are lucky the interface is identical and from the other parts I couldn't see any need for wrapping non-portable code with preprocessor statements.

    One last tip: don't care too much for a sophisticated error handling or for using new source and header file for each class. The time you got for the task is too short to make a program where each wrong or potential happening case has a proper handling. I also would go without getters and setters in that approach and use public members for faster implementation.

  9. #9
    Join Date
    Nov 2010
    Posts
    146

    Re: Help with assignment

    Thank you so much itsmeandnobodyelse for your time . Thanks a lot

  10. #10
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: Help with assignment

    You may also be able to utilise a set of nested std::map or std::multimap items to organise the input data, the top level key being the company name, a sub level being the date.
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

  11. #11
    Join Date
    Nov 2010
    Posts
    146

    Re: Help with assignment

    Thanks JohnW@Wessex

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