Maximum Date

Posted on 2008-11-19
Last Modified: 2012-05-05
Hi Expert,

I have a file like this

Date,sales volume

How can I find out the max date and sales volume for that date?

Question by:justinY
    LVL 53

    Accepted Solution

    You can read in each of the records (date and sales volume) into a data structure (vector for example), sort it (descending order possibly) on date, and then you can easily retrieve the most recent sales volume.
    LVL 3

    Assisted Solution

    turn each date into a number, with the formula: X = dd + (31 * mm) + (31 * 12 * yyyy);
    where the date is dd/mm/yyyy, this converts the date into a number of days (rough estimate) since 0/0/0000.
    call this function date_num( date )

    now start be defining three variables,
    int max_date = 0
    int volume = 0
    string s_max_date = "0/0/0000";

    for each line you read,
    extract, date and sale_volume
    if max_date < date_num(date) then
       max_date = date_num(date)
       s_max_date = date
       volume = sale_volume
    go to next line


    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

      Included as part of the C++ Standard Template Library (STL) is a collection of generic containers. Each of these containers serves a different purpose and has different pros and cons. It is often difficult to decide which container to use and …
    Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
    The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
    The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now