1 Replies - 691 Views - Last Post: 20 April 2015 - 05:34 AM Rate Topic: -----

#1 gsarrbeng   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 08-November 14

Extracting information from Data File

Posted 20 April 2015 - 03:39 AM

Create a simple data file like the example shown below containing the 4 dates below plus 10 or more additional dates. The file should include 1 date per line and each date should have the form MonthNumber-DayOfTheMonth-Last2DigitsOfTheYear with no extra spaces. All dates should be in this century. No error checking for invalid dates is necessary.


My Output displays like
February -19,1991

How do I get my program to ignore the dash between the dates?

#include <fstream>
#include <iostream>
#include <string>
#include <cmath>

using namespace std;

int main()	{
	const int M = 13;
	int count = 0, Temp= 0;
	string string1, Months[M];
	
	
	 ifstream InData("Dates.txt"), Month("Month.txt");
	 
	 ofstream OutData("HW7#2Data.txt");
	 
	 for (int j = 0; !Month.eof(); j++ )
	 	getline (Month, Months[j]);
	
	 	 
	 for(int i = 0; !InData.eof(); i++)	{
	 	InData >> Temp;
	 	OutData << Months[Temp];
	 	
	 
	 	//getline (InData, string1);  
	 	InData >> Temp;
	 	OutData << " " << Temp << ",";
	 	
	 	//getline (InData, string1, '\n');
	 	InData >> Temp;
	 	OutData << Temp + 2000 ;
	 	
	 	OutData << endl;
	 	count++;
	 }
	cout << "Leftovers: " << string1<< endl;
	cout<<count;
	
	return 0;
}


Is This A Good Question/Topic? 0
  • +

Replies To: Extracting information from Data File

#2 jimblumberg   User is offline

  • member icon

Reputation: 5771
  • View blog
  • Posts: 17,670
  • Joined: 25-December 09

Re: Extracting information from Data File

Posted 20 April 2015 - 05:34 AM

Quote

like the example shown below containing the 4 dates below

It would be helpful if you actually showed the examples you were given, not just a snippet that doesn't actually match the description.

Quote

The file should include 1 date per line and each date should have the form MonthNumber-DayOfTheMonth-Last2DigitsOfTheYear with no extra spaces.

I would expect dates with something like 4-20-15, not April-20,2015. And it should never contain a year like 1991 because:

Quote

All dates should be in this century.


So please show the contents of your Dates.txt and Month.txt input files.

Jim
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1