Date Format Conversion : Create a simple data file like the example shown below
ID: 3764591 • Letter: D
Question
Date Format Conversion: 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: Month DayOfTheMonth, Year. All dates should be in this century. No error checking for invalid dates is necessary.
February 19, 2017
July 4, 2017
November 4, 2018
September 30, 2019
.
.
Write a program that will read the dates in the input date file and create an output data file with the form MonthNumber-DayOfTheMonth-Last2DigitsOfTheYear with no extra spaces. Example:
2-19-17
7-4-17
11-4-18
9-30-19
.
.only use these libraries
#include <iostream>
#include <string>
#include <cctype>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <numeric>
Explanation / Answer
Here is the code for you. If you have any further queries, just get back to me:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
string month;
int monthNumber;
int day;
int year;
char temp;
string fileName;
ifstream ipFile;
cout<<"Enter the file name: ";
cin>>fileName;
ipFile.open(fileName);
while(!ipFile.eof())
{
ipFile>>month;
ipFile>>day;
ipFile>>temp;
ipFile>>year;
if(month == "January")
monthNumber = 1;
else if(month == "February")
monthNumber = 2;
else if(month == "March")
monthNumber = 3;
else if(month == "April")
monthNumber = 4;
else if(month == "May")
monthNumber = 5;
else if(month == "June")
monthNumber = 6;
else if(month == "July")
monthNumber = 7;
else if(month == "August")
monthNumber = 8;
else if(month == "September")
monthNumber = 9;
else if(month == "October")
monthNumber = 10;
else if(month == "November")
monthNumber = 11;
else
monthNumber = 12;
cout<<monthNumber<<"-"<<day<<"-"<<year%2000<<endl;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.