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.
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
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)??
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?
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.
Re: Problem in C++ programming
C++ isn't a scripting language. You might be better off using Python or Perl. I would recommend Python.
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.
Re: Problem in C++ programming
Quote:
Originally Posted by
tataidatta
the file is in a database!!
You say it's a database but your code shows a txt file???