CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jul 2012
    Posts
    4

    Problem in C++ programming

    I have a dataset in which 1st column is the day of the month, 2nd column is the number of the month(1,2,3,4,5,6,7,8,9,10,11,12), 3rd column is the year, 4th, 5th and 6th columns are my data of interest. My problem is, I need a column between 3rd and 4th column with the values of day of the year(1-365 or 1-366). please help me to do this. I have the dataset of last 50 years.

  2. #2
    Join Date
    Feb 2002
    Posts
    4,640

    Re: Problem in C++ programming

    Load the file into Excel; insert column. You didn't specify how the data is stored (file on disk; some type of data structure in memory; etc.).

    Viggy

  3. #3
    Join Date
    Jul 2012
    Posts
    4

    Re: Problem in C++ programming

    my data is in my HDD. instead of Excel, we cant do it in C++ as it will be hectic to input data of day of the year for 50 years!! can t we make a column in C++ based on the data in the year column(leap year and not leap year)??

  4. #4
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Problem in C++ programming

    So what's your question? You haven't explained yourself well enough to get any real help.

    Is this a database, text file, what? Do you have any C++ experience? Why can't you import the file into Excel or Access as suggested?

  5. #5
    Join Date
    Jul 2012
    Posts
    4

    Re: Problem in C++ programming

    the file is in a database!! and i have data of 50 years. In that way I have 100 files. Doing the same thing in excel/ access as u told is really hectic. that is the reason why i am trying in C++. I dnt have much experience in C++. I have tried to write the code, but it is not working!! here is the code

    #include<iostream>
    #include<fstream>


    using namespace std;


    void main()
    {

    int col1,col2,col3,col10;
    float col4,col5,col6;

    ifstream weather("weather.txt");
    ofstream weather1("date.txt");
    while(weather>>col1>>col2>>col3>>col4>>col5>>col6)
    weather1<<col3<<endl;

    ifstream date("date.txt");
    ofstream weather2("weather1.txt");

    while(date>>col10)
    {
    if(col10%4==0)
    {
    for(int i=1; i<367; i++)

    weather2<<col10<<'\t'<<i<<endl;
    }

    else
    for(int j=1; j<366; j++)
    weather2<<col10<<'\t'<<j<<endl;
    }


    system("pause");
    }
    please suggest me what type of modifications I need to run the script as it is giving error and giving the out put of only the last year in the main file.

  6. #6
    Join Date
    Aug 2009
    Posts
    440

    Re: Problem in C++ programming

    C++ isn't a scripting language. You might be better off using Python or Perl. I would recommend Python.

  7. #7
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: Problem in C++ programming

    As many have said, this is extremely easy in Excel.

    If you load your data into Excel and have your 6 columns, simply insert a new column between the third and fourth column.

    Assuming your data starts in the top/left cell (A1), type this formula into cell D1 and then copy it down.
    Code:
    =DATE(C1,B1,A1)-DATE(C1-1,12,31)
    Now column D (4th column) will contain the day number in the year.

    Hope this helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  8. #8
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Problem in C++ programming

    Quote Originally Posted by tataidatta View Post
    the file is in a database!!
    You say it's a database but your code shows a txt file???

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