Другие языки программирования и технологии
рандомизация даты рождения на с++
всем здравствуйте нужна помощь нужно на С++ написать программу которая будет рандомезировать дату рождения примерно с 1950, данная программа должна показывать год, месяц, и день.
#include <iostream>
#include <random>
#include <string>
using namespace std;
class random_date_of_birth {
public:
random_date_of_birth(int a, int b);
string get_date()const;
private:
int year;
int month;
int day;
string date;
int randomize(int a, int b);
void generate(int a, int b);
random_date_of_birth() {}
};
int main() {
int start = 1950;
int end = 2014;
for (int n = 0; n < 100; ++n) {
random_date_of_birth rdb(start, end);
cout << rdb.get_date() << '\n';
}
cin.get();
}
inline string random_date_of_birth::get_date()const {
return date;
}
random_date_of_birth::random_date_of_birth(int a, int b) : date("") {
generate(a, b);
}
void random_date_of_birth::generate(int a, int b) {
int months[] = { 29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
year = randomize(a, b);
month = randomize(1, 12);
if (0 == year % 4 && month == 2) day = randomize(1, months[0]);
else day = randomize(1, months[month]);
if (day < 10) date += "0";
date += to_string(day) + "/";
if (month < 10) date += "0";
date += to_string(month) + "/" + to_string(year);
}
int random_date_of_birth::randomize(int a, int b) {
if (a > b) swap(a, b);
uniform_int_distribution<int> rand(a, b);
random_device rnd;
return rand(rnd);
}
#include <random>
#include <string>
using namespace std;
class random_date_of_birth {
public:
random_date_of_birth(int a, int b);
string get_date()const;
private:
int year;
int month;
int day;
string date;
int randomize(int a, int b);
void generate(int a, int b);
random_date_of_birth() {}
};
int main() {
int start = 1950;
int end = 2014;
for (int n = 0; n < 100; ++n) {
random_date_of_birth rdb(start, end);
cout << rdb.get_date() << '\n';
}
cin.get();
}
inline string random_date_of_birth::get_date()const {
return date;
}
random_date_of_birth::random_date_of_birth(int a, int b) : date("") {
generate(a, b);
}
void random_date_of_birth::generate(int a, int b) {
int months[] = { 29, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
year = randomize(a, b);
month = randomize(1, 12);
if (0 == year % 4 && month == 2) day = randomize(1, months[0]);
else day = randomize(1, months[month]);
if (day < 10) date += "0";
date += to_string(day) + "/";
if (month < 10) date += "0";
date += to_string(month) + "/" + to_string(year);
}
int random_date_of_birth::randomize(int a, int b) {
if (a > b) swap(a, b);
uniform_int_distribution<int> rand(a, b);
random_device rnd;
return rand(rnd);
}
1.1.1950+х, где x - случайное целое, число дней (в примере - 1000)
http://ideone.com/FKuEZs
осталось цивильно оформить
http://ideone.com/FKuEZs
осталось цивильно оформить
Похожие вопросы
- Где можно найти картинки с именем Мадина?Что за человек с именем Мадина и датой рождения 16.11.94?
- Надо исправить дату рождения на ксерокопии паспорта
- определить день недели по дате
- Как рассчитать стаж между определенными датами с помощью MS OF EXCEL
- Подскажите, как сделать автоматическое добавление текущей даты в ячейку в excel???
- Как скриптом создать папку с вчерашней датой?
- как сортировать по дате столбцы в экселе?
- Как вывести на сайт дату в формате (дата + N дней) Но чтоб не получилось "37 декабря"
- Скажите сколько месяцев нужно изучать Делфи что бы написать программу вывода даты, дня недели и года в окно ?
- Хотел составить программу в PascalABC, которая по введённой дате пишет его день недели.