🌿 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: Simple To-do List

C++ Mini Projects: Simple to-do List

Hey guys, welcome back to the blog! We're continuing the series with another awesome addition of a simple todo list using your skills by coding in C++.

In case you're not sure, a todo list is a list of things that you have in mind to do. This list helps you keep a track.

Programmatically our task is to create a functionality like this:

First you add new tasks to your list 
Second you display the tasks according to their respective numbers
Third you have ability to delete a particular task according to its number 
Fourth you exit the app

Skills you will learn throughout:


Vectors 

Loops 

Menu management system 

Vectors: To manage task list dynamically 

Loops.... for interaction of menu continuously 

Menu management system....an interface for selecting options in a user friendly way

So lets get started on coding!

The code to build the desired project:


#include <iostream>
#include <vector>
#include <string>
using namespace std;

int main() {
    vector<string> todoList; // Vector to store tasks
    int choice; // Menu choice
    string task; // Task input by user
    int taskNumber; // Task number to delete

    do {
        // Display menu
        cout << "\nSimple To-Do List\n";
        cout << "-----------------\n";
        cout << "1. Add Task\n";
        cout << "2. View Tasks\n";
        cout << "3. Delete Task\n";
        cout << "4. Exit\n";
        cout << "Enter your choice: ";
        cin >> choice;

        switch (choice) {
            case 1:
                // Add a task
                cin.ignore(); // Clear input buffer
                cout << "Enter the task: ";
                getline(cin, task); // Get full task input
                todoList.push_back(task); // Add task to vector
                cout << "Task added successfully.\n";
                break;

            case 2:
                // View tasks
                if (todoList.empty()) {
                    cout << "Your to-do list is empty.\n";
                } else {
                    cout << "Your To-Do List:\n";
                    for (size_t i = 0; i < todoList.size(); ++i) {
                        cout << i + 1 << ". " << todoList[i] << endl;
                    }
                }
                break;

            case 3:
                // Delete a task
                if (todoList.empty()) {
                    cout << "Your to-do list is empty. Nothing to delete.\n";
                } else {
                    cout << "Enter the task number to delete: ";
                    cin >> taskNumber;

                    if (taskNumber > 0 && taskNumber <= static_cast<int>(todoList.size())) {
                        todoList.erase(todoList.begin() + taskNumber - 1); // Delete the task
                        cout << "Task deleted successfully.\n";
                    } else {
                        cout << "Invalid task number!\n";
                    }
                }
                break;

            case 4:
                // Exit the program
                cout << "Exiting the to-do list. Goodbye!\n";
                break;

            default:
                cout << "Invalid choice. Please try again.\n";
        }
    } while (choice != 4); // Continue until user chooses to exit

    return 0;
}

How the code works...

Vectors:
vector<string> todoList;

A vector works like an array that grows and then shrinks when you run code.
In the vector all tasks can be stored as strings


Menu display

cout << "1. Add Task\n";
cout << "2. View Tasks\n";
cout << "3. Delete Task\n";
cout << "4. Exit\n";
cin >> choice;

Menu system is used to guide the user
Selection of user is stored in choice 

Add a task

cin.ignore();
cout << "Enter the task: ";
getline(cin, task);
todoList.push_back(task);
Cin.ignore() is used for clearing the input buffer so that getline has no issues 
Getline (cin,task) 
Fully reads the input tasks with all spaces 

Push_back (task) 
Its for adding the tasks to vectors

View a task

for (size_t i = 0; i < todoList.size(); ++i) {
    cout << i + 1 << ". " << todoList[i] << endl;
}


Loops through vectors for displaying all task with their numbers

Delete tasks

if (taskNumber > 0 && taskNumber <= static_cast<int>(todoList.size())) {
    todoList.erase(todoList.begin() + taskNumber - 1);
}

Validates the input 

Makes sure that task that is entered is correct and valid 

Erase.... delete a task 

Quitting the program 
while (choice != 4);

Program keeps looping till user chooses option no. 4

Hope you enjoyed and learned something new from this blog. 

See you next time!

Comments

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

C++ Projects: Password Manager