-
July 3rd, 2012, 11:53 AM
#1
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.
-
July 3rd, 2012, 11:58 AM
#2
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
-
July 3rd, 2012, 12:35 PM
#3
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)??
-
July 3rd, 2012, 12:50 PM
#4
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?
-
July 4th, 2012, 08:32 AM
#5
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.
-
July 4th, 2012, 09:07 AM
#6
Re: Problem in C++ programming
C++ isn't a scripting language. You might be better off using Python or Perl. I would recommend Python.
-
July 4th, 2012, 09:39 AM
#7
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
-
July 5th, 2012, 07:17 AM
#8
Re: Problem in C++ programming
Originally Posted by tataidatta
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|