🌿 Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms"

Hey guys! Today, we are going to build something simple yet useful using our skills in C++. As the name suggests, it's going to be a calendar application. We all know what a calendar does, so let's jump right in and start building!
#include <iostream>
#include <iomanip> // for setw
#include <vector>
using namespace std;
bool isLeapYear(int year) {
return (year % 4 == 0 && year % 100 != 0) || (year % 400 == 0);
}
int getDaysInMonth(int month, int year) {
if (month == 2) {
return isLeapYear(year) ? 29 : 28;
}
if (month == 4 || month == 6 || month == 9 || month == 11) {
return 30;
}
return 31;
}
int getFirstDayOfMonth(int month, int year) {
int day = 1, y = year, m = month;
if (m < 3) {
m += 12;
y -= 1;
}
int k = y % 100, j = y / 100;
int firstDay = (day + (13 * (m + 1)) / 5 + k + (k / 4) + (j / 4) - (2 * j)) % 7;
return (firstDay + 5) % 7;
}
void displayCalendar(int month, int year, const vector<int>& importantDates) {
vector<string> months = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
cout << "\n " << months[month - 1] << " " << year << endl;
cout << " Sun Mon Tue Wed Thu Fri Sat" << endl;
int daysInMonth = getDaysInMonth(month, year);
int firstDay = getFirstDayOfMonth(month, year);
for (int i = 0; i < firstDay; ++i) {
cout << " ";
}
for (int day = 1; day <= daysInMonth; ++day) {
bool isWeekend = (firstDay % 7 == 0 || firstDay % 7 == 6);
bool isImportant = find(importantDates.begin(), importantDates.end(), day) != importantDates.end();
if (isImportant) {
cout << setw(5) << "*" + to_string(day) + "*";
} else if (isWeekend) {
cout << setw(5) << "(" + to_string(day) + ")";
} else {
cout << setw(5) << day;
}
++firstDay;
if (firstDay % 7 == 0) {
cout << endl;
}
}
cout << endl;
}
int main() {
int year, month;
vector<int> importantDates;
cout << "Welcome to the Calendar Application!" << endl;
cout << "Enter the year: ";
cin >> year;
cout << "Enter the month (1-12): ";
cin >> month;
int numImportant;
cout << "Enter the number of important dates to mark: ";
cin >> numImportant;
cout << "Enter the important dates (day of the month): ";
for (int i = 0; i < numImportant; ++i) {
int date;
cin >> date;
importantDates.push_back(date);
}
displayCalendar(month, year, importantDates);
return 0;
}
People often use calendar apps to mark events, deadlines, and meetings. This project lays the foundation for building a fully functional scheduling tool.
Many subscription-based services use calendar logic to automate billing cycles. This program demonstrates how to track dates efficiently.
Businesses use calendar-based applications to manage employee attendance, shifts, and leave schedules.
Google Calendar helps users manage schedules, special events, and reminders. Our project follows a similar concept by allowing users to mark different dates.
Businesses rely on calendar applications to track tax deadlines, financial reports, and investment schedules.
Universities use scheduling software for managing classes, exams, and holidays. This project can be extended to create a comprehensive timetable planner.
setw()
for aligning calendar columns.This project is a great starting point for building advanced calendar applications. I hope you liked it! See you again with another cool project soon!
Comments
Post a Comment