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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
|
#include <iostream>
#include <ctime>
using namespace std;
int main()
{
const int TOTAL_MONTHS = 12;
int months[TOTAL_MONTHS] = { 1,2,3,4,5,6,7,8,9,10,11,12 };
int num, year,search;
cout << "Enter the number of dates to generate: ";
cin >> num;
cout << "Enter year: ";
cin >> year;
}
void random_dates (int months[], int numDays[], int Days[], num, year)
{
srand((unsigned)time(0));
const int TOTAL_MONTHS = 12;
if (year % 4 == 0 || (year % 4 == 0 && year % 100 != 0))
{
int numDays[TOTAL_MONTHS] = { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
for (int i = 0; i < num; i++)
{
int index = rand() % 12;
if (index == 1 || index == 3 || index == 5 || index == 7 || index == 8 || index == 10 || index == 12)
{
int Days[31] = { 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 };
int day_index = rand() % 31;
cout << months[index] << "/" << Days[day_index] << ' ';
}
else if (index == 4 || index == 6 || index == 9 || index == 11)
{
int Days[30] = { 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 };
int day_index = rand() % 30;
cout << months[index] << "/" << Days[day_index] << ' ';
}
else if (index ==2)
{
int Days[29] = { 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};
int day_index = rand() % 29;
cout << months[index] << "/" << Days[day_index] << ' ';
}
}
cout << endl;
}
else
{
int numDays[TOTAL_MONTHS] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
{
for (int i = 0; i < num; i++)
{
int index = rand() % 12;
if (index == 1 || index == 3 || index == 5 || index == 7 || index == 8 || index == 10 || index == 12)
{
int Days[31] = { 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 };
int day_index = rand() % 31;
cout << months[index] << "/" << Days[day_index] << ' ';
}
else if (index == 4 || index == 6 || index == 9 || index == 11)
{
int Days[30] = { 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 };
int day_index = rand() % 30;
cout << months[index] << "/" << Days[day_index] << ' ';
}
else if (index == 2)
{
int Days[28] = { 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 };
int day_index = rand() % 28;
//int day_index = rand() % ((28 - 1) + 1); I've tried this as well, hoping it would limit February to 28 days, but it will still surpass it and go to 30 days.
cout << months[index] << "/" << Days[day_index] << ' ';
}
}
}
cout << endl;
}
cout << endl;
}
|