forked from CodersSquad/tmp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathperson.cpp
More file actions
61 lines (48 loc) · 1.74 KB
/
person.cpp
File metadata and controls
61 lines (48 loc) · 1.74 KB
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
#include <iostream>
#include <string>
#include <ctime> // For handling dates
#include <random>
#include <algorithm>
#include "person.h"
// Constructor
Person::Person(const std::string& name, int age, const std::string& birthdate)
: name(name), age(age), birthdate(birthdate) {}
std::string Person::getName() const {
return name;
}
int Person::getAge() const {
return age;
}
std::string Person::getBirthdate() const {
return birthdate;
}
void Person::displayInfo() const {
std::cout << "Name: " << name << std::endl;
std::cout << "Age: " << age << std::endl;
std::cout << "Birthdate: " << birthdate << std::endl;
}
bool Person::operator<(const Person& other) const {
return age < other.age;
}
std::string generateRandomName(size_t length) {
// A string of all possible letters for the name
const std::string lower_chars = "abcdefghijklmnopqrstuvwxyz";
const std::string upper_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
// Create a high-quality, non-deterministic random number generator
std::random_device rd;
std::mt19937 generator(rd());
// Create a uniform integer distribution for character indices
// The distribution's range is from 0 to the size of the alphabet minus 1
std::uniform_int_distribution<size_t> upper_dist(0, upper_chars.size() - 1);
std::uniform_int_distribution<size_t> lower_dist(0, lower_chars.size() - 1);
std::string random_name;
if (length > 0) {
// First character is always an uppercase letter
random_name += upper_chars[upper_dist(generator)];
// Remaining characters are lowercase letters
for (size_t i = 1; i < length; ++i) {
random_name += lower_chars[lower_dist(generator)];
}
}
return random_name;
}