🌿 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++ Smart Task Manager with AI Productivity Analyzer

 

C++ Smart Task Manager with AI Productivity Analyzer

Overview

This project integrates two C++ programs to create a smart task manager combined with an AI-based productivity analyzer. The two programs work together by sharing a MySQL database.

Program 1: Task Manager (Core System)

The task manager helps users in:

  • Creating, deleting, organizing, and updating tasks.

  • Storing task data in a MySQL database.

  • Managing tasks through a lightweight GUI.

Program 2: AI Productivity Analyzer

The AI module analyzes completed tasks to:

  • Track productivity trends.

  • Use machine learning to enhance future task assignments.

  • Extract keywords and classify tasks into categories such as urgent, work, personal, etc.

Integration of Both Programs

  • The task manager saves task details in a MySQL database.

  • The AI analyzer reads the database, processes the data, and provides insights.

  • Communication is established through database sharing or inter-process communication (IPC).


Implementation

Task Manager

This program allows users to add, view, and complete tasks while storing them in a MySQL database.

Code: task_manager.cpp

#include <iostream>
#include <mysql/mysql.h>
using namespace std;

// Database connection function
MYSQL* connectDB() {
    MYSQL* conn = mysql_init(nullptr);
    if (conn == nullptr || !mysql_real_connect(conn, "localhost", "root", "password", "task_db", 3306, nullptr, 0)) {
        cerr << "Database connection failed: " << mysql_error(conn) << endl;
        exit(1);
    }
    return conn;
}

// Create table if it does not exist
void createTable(MYSQL* conn) {
    string query = "CREATE TABLE IF NOT EXISTS tasks ("
                   "id INT AUTO_INCREMENT PRIMARY KEY,"
                   "title VARCHAR(255),"
                   "category VARCHAR(100),"
                   "completed BOOLEAN DEFAULT 0)";
    mysql_query(conn, query.c_str());
}

// Add a new task
void addTask(MYSQL* conn, const string& title, const string& category) {
    string query = "INSERT INTO tasks (title, category) VALUES ('" + title + "', '" + category + "')";
    mysql_query(conn, query.c_str());
}

// View all tasks
void viewTasks(MYSQL* conn) {
    MYSQL_RES* res;
    MYSQL_ROW row;
    mysql_query(conn, "SELECT * FROM tasks");
    res = mysql_store_result(conn);

    cout << "\nTasks:\n";
    while ((row = mysql_fetch_row(res))) {
        cout << "ID: " << row[0] << " | Title: " << row[1] << " | Category: " << row[2]
             << " | Completed: " << (stoi(row[3]) ? "Yes" : "No") << endl;
    }
    mysql_free_result(res);
}

// Mark task as completed
void completeTask(MYSQL* conn, int taskId) {
    string query = "UPDATE tasks SET completed = 1 WHERE id = " + to_string(taskId);
    mysql_query(conn, query.c_str());
}

int main() {
    MYSQL* conn = connectDB();
    createTable(conn);
    
    int choice;
    while (true) {
        cout << "\n1. Add Task\n2. View Tasks\n3. Complete Task\n4. Exit\nChoice: ";
        cin >> choice;
        
        if (choice == 1) {
            string title, category;
            cin.ignore();
            cout << "Task Title: "; getline(cin, title);
            cout << "Category: "; getline(cin, category);
            addTask(conn, title, category);
        } else if (choice == 2) {
            viewTasks(conn);
        } else if (choice == 3) {
            int taskId;
            cout << "Enter Task ID to complete: "; cin >> taskId;
            completeTask(conn, taskId);
        } else {
            break;
        }
    }

    mysql_close(conn);
    return 0;
}

AI Productivity Analyzer

The AI analyzer reads completed tasks from the database to analyze:

  • Productivity trends: Tracks how many tasks are completed daily.

  • Task categorization: Counts tasks in each category.

  • Time estimation: Uses task history to predict completion time.

Code: ai_analyzer.cpp

#include <iostream>
#include <map>
#include <mysql/mysql.h>
using namespace std;

// Connect to MySQL\MYSQL* connectDB() {
    MYSQL* conn = mysql_init(nullptr);
    if (conn == nullptr || !mysql_real_connect(conn, "localhost", "root", "password", "task_db", 3306, nullptr, 0)) {
        cerr << "Database connection failed: " << mysql_error(conn) << endl;
        exit(1);
    }
    return conn;
}

// Analyze task completion trends
void analyzeProductivity(MYSQL* conn) {
    MYSQL_RES* res;
    MYSQL_ROW row;
    map<string, int> categoryCount;
    
    mysql_query(conn, "SELECT category FROM tasks WHERE completed = 1");
    res = mysql_store_result(conn);
    
    while ((row = mysql_fetch_row(res))) {
        categoryCount[row[0]]++;
    }
    mysql_free_result(res);
    
    cout << "\nCompleted Task Analysis:\n";
    for (const auto& entry : categoryCount) {
        cout << "Category: " << entry.first << " | Completed: " << entry.second << endl;
    }
}

// Predict task completion time
void predictTaskTime(MYSQL* conn) {
    MYSQL_RES* res;
    MYSQL_ROW row;
    int completedCount = 0;
    
    mysql_query(conn, "SELECT COUNT(*) FROM tasks WHERE completed = 1");
    res = mysql_store_result(conn);
    if ((row = mysql_fetch_row(res))) {
        completedCount = stoi(row[0]);
    }
    mysql_free_result(res);
    
    int estimatedTime = (completedCount > 0) ? (completedCount * 2) : 5;
    cout << "\nEstimated completion time for new tasks: " << estimatedTime << " minutes\n";
}

int main() {
    MYSQL* conn = connectDB();
    int choice;
    
    while (true) {
        cout << "\n1. Analyze Productivity\n2. Predict Task Time\n3. Exit\nChoice: ";
        cin >> choice;
        
        if (choice == 1) {
            analyzeProductivity(conn);
        } else if (choice == 2) {
            predictTaskTime(conn);
        } else {
            break;
        }
    }

    mysql_close(conn);
    return 0;
}

How They Work Together

  1. Run the Task Manager to add and complete tasks.

  2. Run the AI Analyzer to analyze completed tasks and predict task times.

  3. Both programs share the same MySQL database for integration.

This project efficiently manages tasks and improves productivity using AI-driven insights.

Comments

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

C++ Projects: Password Manager