🌿 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: Expense Splitter

C++ Mini Projects: Expense Splitter

This is a very handy app used to split expenses between people. When multiple individuals contribute money for a shared expense, this C++ expense splitter helps determine each person's fair share. Isn't that interesting and useful? Let's dive in and build one!


Skills Used

  • Handling multiple participants: The program can accommodate any number of people.
  • Precision calculations: Ensures accurate financial division.
  • Displaying results with two decimal places: Uses setprecision and fixed to format output.

The Code to Build the Project

#include <iostream>
#include <vector>
#include <string>
#include <iomanip> // for fixed and setprecision

using namespace std;

struct Person {
    string name;
    double amountPaid;
};

void calculateExpenses(const vector<Person>& people) {
    double total = 0.0;
    int numPeople = people.size();
    
    // Calculate total expense
    for (const auto& person : people) {
        total += person.amountPaid;
    }
    
    double average = total / numPeople;
    cout << "\nTotal expense: $" << fixed << setprecision(2) << total << endl;
    cout << "Each person should contribute: $" << fixed << setprecision(2) << average << endl;

    // Calculate who owes or gets back
    cout << "\nSummary of contributions:\n";
    for (const auto& person : people) {
        double balance = person.amountPaid - average;
        if (balance > 0) {
            cout << person.name << " should get back $" << fixed << setprecision(2) << balance << endl;
        } else if (balance < 0) {
            cout << person.name << " owes $" << fixed << setprecision(2) << -balance << endl;
        } else {
            cout << person.name << " is settled.\n";
        }
    }
}

int main() {
    vector<Person> people;
    int numPeople;

    cout << "Welcome to the Expense Splitter!" << endl;
    cout << "Enter the number of people: ";
    cin >> numPeople;

    // Input data for each person
    for (int i = 0; i < numPeople; ++i) {
        Person person;
        cout << "\nEnter name of person " << i + 1 << ": ";
        cin >> person.name;
        cout << "Enter the amount paid by " << person.name << ": $";
        cin >> person.amountPaid;
        people.push_back(person);
    }

    // Calculate and display expense summary
    calculateExpenses(people);

    return 0;
}

Explanation

Definition of Structure

struct Person {
    string name;
    double amountPaid;
};
  • name: Stores the participant’s name.
  • amountPaid: Stores the amount paid by the person.

Handling Input

vector<Person> people;
int numPeople;
cout << "Enter the number of people: ";
cin >> numPeople;
  • Uses a vector<Person> to dynamically store participant details.
  • A loop collects input for each participant.

Calculating Total and Average Contributions

double total = 0.0;
for (const auto& person : people) {
    total += person.amountPaid;
}
double average = total / numPeople;
  • total: Sums all contributions.
  • average: Divides the total by the number of people to determine equal shares.

Analyzing Expenses

for (const auto& person : people) {
    double balance = person.amountPaid - average;
    if (balance > 0) {
        cout << person.name << " should get back $" << fixed << setprecision(2) << balance << endl;
    } else if (balance < 0) {
        cout << person.name << " owes $" << fixed << setprecision(2) << -balance << endl;
    } else {
        cout << person.name << " is settled.\n";
    }
}
  • balance: Determines the amount each person owes or is owed.
  • Positive balance → They overpaid and should be reimbursed.
  • Negative balance → They underpaid and owe others.
  • Displays a transparent breakdown of all contributions.

Sample Run

Input:

Enter the number of people: 3

Enter name of person 1: Alice
Enter the amount paid by Alice: $100

Enter name of person 2: Bob
Enter the amount paid by Bob: $50

Enter name of person 3: Charlie
Enter the amount paid by Charlie: $150

Output:

Total expense: $300.00
Each person should contribute: $100.00

Summary of contributions:
Alice is settled.
Bob owes $50.00
Charlie should get back $50.00

Real-World Applications

Friends Having Dinner Together

A group of friends at a café place a shared order. After the meal, they receive a $200 bill, and each pays a different amount based on cash in hand. Instead of manually calculating who owes whom, they can use the expense splitter to determine fair contributions.

Office Team Buying Supplies

In workplaces, teams often pool money for office supplies, gifts, or snacks. Each colleague contributes differently, and the expense splitter ensures fair contributions while preventing misunderstandings.

Cost of Group Vacations

When planning group trips, different people may book flights, accommodations, or food. The expense splitter fairly distributes costs to ensure no one overpays.


Case Studies

Case Study 1: College Trip

A group of five college students take turns paying for gas, food, and lodging on a trip. The total expenses amount to $750, with each contributing differently. Using the expense splitter, they calculate who needs to pay whom for a fair distribution.

Advantages:

  • Eliminates human errors in financial calculations.
  • Maintains transparency among participants.

Case Study 2: Office Gift Purchase

Employees collect money to buy a wedding gift for a coworker. Some contribute more, while others contribute less. Instead of confusion, the expense splitter calculates each person's fair share and ensures smooth financial cooperation.

Advantages:

  • Useful for both professional and social settings.
  • Reduces friction in collective financial matters.

Problem-Solving Approaches

Dealing with Floating Point Precision

Floating point calculations can lead to rounding issues. The program uses setprecision(2) and fixed to consistently display amounts to two decimal places, ensuring accuracy.

Handling Large Groups

For large groups (50+ people), the program efficiently processes data using vectors and optimized algorithms for better performance.

Integrating Automatic Payments

A future enhancement could involve integrating a payment API, allowing users to transfer funds directly within the app.


This project is a fantastic starting point for more advanced financial management applications. Hope you enjoyed it! Stay tuned for another exciting project soon!

Comments

Popular posts from this blog

C++ Projects: Basic Traffic Management System

C++ Projects: Book Shop Management System

C++ Projects: Password Manager