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

Image
  🌿  Smart Garden Manager in C++ with Robotics, UI, Drones, and Sound "A Rainwater Conservation System for Tomorrow’s Farms" 🧭  1. Introduction: Farming in the Age of Climate Change In a world where clean water is more precious than gold, efficient  rainwater harvesting and plant care systems  are no longer optional — they’re essential. Smart farming doesn’t mean just automating irrigation. It means combining  robotic drones, environmental sensors, and intelligent scheduling  to build a garden that practically takes care of itself. In this guide, we build a  fully functional Garden Manager System  using  C++  that: Captures and conserves rainwater Uses  robotic drones and sensors  to monitor crop health Integrates a  real-time UI  with progress bars and alerts Includes  timers  for scheduling plant growth and drone tasks Plays  interactive sounds  based on crop state and events Whether you'r...

C++ Mini Projects: Calendar Application

C++ Mini Projects: Calendar Application

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!


Skills Used

  • Input of Month and Year: Users will input the desired month and year.
  • Displaying the Calendar: The application will generate a properly formatted calendar for the given input.
  • Highlighting Weekends: Weekends will be enclosed in parentheses.
  • Marking Important Dates: Users can specify important dates to be highlighted.

The Code to Build the Project

#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;
}

Explanation

  • Leap Year Calculation: Determines if a given year is a leap year.
  • Days in a Month: Adjusts for varying month lengths and leap years.
  • First Day of the Month: Uses Zeller's Congruence algorithm to determine the first day of a given month.
  • Calendar Display: Formats the output to show weekends in parentheses and important dates marked with asterisks.
  • User Input Handling: Ensures users provide valid months and dates.

Real-World Applications

Personal Schedules and Reminders

People often use calendar apps to mark events, deadlines, and meetings. This project lays the foundation for building a fully functional scheduling tool.

Automatic Payments and Billing Systems

Many subscription-based services use calendar logic to automate billing cycles. This program demonstrates how to track dates efficiently.

Employee Attendance Tracking

Businesses use calendar-based applications to manage employee attendance, shifts, and leave schedules.

Case Study: Google Calendar

Google Calendar helps users manage schedules, special events, and reminders. Our project follows a similar concept by allowing users to mark different dates.

Financial Market Planning

Businesses rely on calendar applications to track tax deadlines, financial reports, and investment schedules.

University Class Scheduling

Universities use scheduling software for managing classes, exams, and holidays. This project can be extended to create a comprehensive timetable planner.


Problem-Solving Approaches

Handling User Input

  • Ensures valid month selection (1-12).
  • Prevents invalid date entries for selected months.
  • Uses loops to re-prompt users in case of incorrect input.

Formatting the Output Properly

  • Uses setw() for aligning calendar columns.
  • Highlights weekends and important dates clearly.

Adding Modern Features

  • Implementing a graphical interface for better user experience.
  • Extending the project to integrate with database storage for event persistence.

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

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

C++ Projects: Password Manager