Hey, so as part of an assignment, I have to write a program that "predicts the date, given a day" so for example, if I want to know what date it will be 5 days from now. As part of the assignment, we were given a txt file that the program must read from, and we were also given a mandatory function to use.
The text file looks like this...
Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
31 28 31 30 31 30 31 31 30 31 30 31
this is the mandatory function:
unsigned int getDayOfYear()
{
time_t t = time(0); // get time now
struct tm* timeinfo = localtime(&t); // populate time structure with current time
return timeinfo->tm_yday; // get the current day of the year
}
And this is what I have so far
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
#include <ctime>
#include <iostream>
#include <fstream>//the header file that helps you to actually use the ifstream
using namespace std;
//Function Prototypes...................................
unsigned int getDayOfYear();
//Main function...........................................
int main()
{
//string month[2][12] = {{months}{days}}
//cout<< month[][];
cout<<"I am the Incredible Date Predictor! \n";
cout<<"************************************* \n";
ifstream inFile;//ifstream is allowing us to read from a file, and inFile is basically just giving it a name
inFile.open("calender.txt");//directing the class to the exact file to be opened
//this is a precaution to display an error massege when the file cannot be accessed. it prevents the program from crashing
if(inFile.fail())
{
cerr<<"Error Opening File"<<endl;
exit(1);
}
string month;
//int days;
while(inFile >> month) // >> days)
{
cout << month<< endl;//<< " " << days <<endl;
}
inFile.close();
cout<<"Please enter the number of days in the future you want to predict the day for: "<<endl;
getDayOfYear();
cout<<"Behold! The day you have asked for is: "<<endl;
return 0;
}
//Function definitions.........................................
// returns the current day of the year
unsigned int getDayOfYear()
{
time_t t = time(0); // get time now
struct tm* timeinfo = localtime(&t); // populate time structure with current time
return timeinfo->tm_yday; // get the current day of the year
}
|