Advanced Mini-Project: Design a Custom Event Scheduler with Recurrence Rules in C++
Build a robust event scheduler application that supports creating, storing, and querying events with complex recurrence rules, such as daily, weekly, or custom intervals. The scheduler should efficiently handle overlapping events and allow users to fetch upcoming events within a date range.
Challenge prompt
Create a C++ mini-project that implements an Event Scheduler system. The scheduler must allow users to add events with titles, start times, durations, and recurrence rules (e.g., daily, weekly on specific weekdays, or custom intervals). It should store events efficiently and provide a method to query all events happening within a given date/time range, including instances generated by recurrence patterns. Your scheduler should also detect and manage overlapping events, returning all occurrences that fall within the range in chronological order.
Guidance
- • Define an Event class with attributes for title, start datetime, duration, and recurrence rules.
- • Implement logic to generate event occurrences on-demand based on recurrence rules for efficient querying.
- • Use an appropriate data structure to store events and optimize event lookup within date ranges.
- • Carefully handle edge cases like events spanning midnight, overlapping times, and non-standard recurrence intervals.
Hints
- • Use C++ chrono library types (std::chrono::system_clock::time_point) for handling dates and times safely.
- • Consider building a RecurrenceRule class or struct to encapsulate and parse recurrence logic cleanly.
- • Use iterators or generators to produce occurrences lazily instead of precomputing all repeats.
Starter code
#include <iostream>
#include <vector>
#include <string>
#include <chrono>
// Define Event class here with necessary fields
// Define RecurrenceRule class/struct for recurrence logic
class EventScheduler {
public:
void addEvent(const std::string& title, /* start time params */, /* duration params */, /* recurrence rule params */) {
// Implement adding event
}
std::vector</* Event occurrence struct/type */> getEventsInRange(/* range start */, /* range end */) {
// Implement querying events within date/time range
return {};
}
};
int main() {
EventScheduler scheduler;
// Example usage: add a recurring weekly event
// Query and print events between two dates
return 0;
}Expected output
All event occurrences within the queried date range printed chronologically with title, start time, and duration.
Core concepts
Challenge a Friend
Send this duel to someone else and see if they can solve it.