C++ Project for beginners | Green house management system source code

 Introduction:

This program is written in C++ that allows to manage a greenhouse according to authorities given to a particular person. Each function in this program has a specific function. In this program concept of arrays,functions and other basic concepts have been used.



#include <iostream>
#include <string>

using namespace std;


const int maxplants = 20;


//list of plants

void list(string plants[],int & nplants) {
    

        for (int i = 0; i < nplants; i++) {

            cout << "Plant " << i + 1 << ": " << plants[i] << endl;

        }

    }



// Adding plants

void addplants(string plants[], int& nplants) {

    string choice;

    do {

        if (nplants >= maxplants) {

            cout << "You can't add more plants." << endl;

            break;

        }


        string plant;

        cout << "Enter the name of a new plant: ";

        cin >> plant;

        plants[nplants] = plant;

        nplants++;


        cout << "Want to add more? (yes/no): ";

        cin >> choice;

    } while (choice == "yes");


    for (int i = 0; i < nplants; i++) {

        cout << "Plant " << i + 1 << ": " << plants[i] << endl;

    }

    

}


// Replacing plant

void replacePlant(string plants[], int n) {

    string planttoreplace;

    cout << "Enter the plant to be replaced: ";

    cin >> planttoreplace;


    for (int i = 0; i < n; i++) {

        if (plants[i] == planttoreplace) {

            string newplant;

            cout << "Enter the new name of the plant: ";

            cin >> newplant;

            plants[i] = newplant;

            break;

        }

    }


    for (int i = 0; i < n; i++) {

        cout << i + 1 << ": " << plants[i] << endl;

    }

}


// Removing plant

void removeplant(string plants[], int& n) {

    string planttoremove;

    cout << "Enter plant name to be removed: ";

    cin >> planttoremove;


    int i;

    for (i = 0; i < n; i++) {

        if (plants[i] == planttoremove) {

            for (int j = i; j < n - 1; j++) {

                plants[j] = plants[j + 1];

            }

            n--;

            break;

        }

    }


    if (i == n) {

        cout << "Plant not found." << endl;

    }


    for (int i = 0; i < n; i++) {

        cout << i + 1 << ": " << plants[i] << endl;

    }

}


// Adding plants by user

void addnewplants(string plants[], int& nplants) {

    string choice;

    do {

        if (nplants >= 5) {

            cout << "You can't add more plants." << endl;

            break;

        }


        string plant;

        cout << "Enter the name of a new plant: ";

        cin >> plant;

        plants[nplants] = plant;

        nplants++;


        cout << "Want to add more? (yes/no): ";

        cin >> choice;

    } while (choice == "yes");


    for (int i = 0; i < nplants; i++) {

        cout << "Plant " << i + 1 << ": " << plants[i] << endl;

    }

}


// Check temperature

void checktemp() {

    int temp = 70; // in Fahrenheit

    int c_temp;

    cout << "Enter the current value of temperature: ";

    cin >> c_temp;


    if (c_temp > temp) {

        cout << "Turning on AC" << endl;

        while (c_temp > temp) {

            c_temp--;

        }

        cout << "loading................................." << endl;

        cout << "Turned off AC" << endl;

    } else if (c_temp < temp) {

        cout << "Turning on heater" << endl;

        while (c_temp < temp) {

            c_temp++;

        }

        cout << "loading................................." << endl;

        cout << "Turned off heater as it reached desired value" << endl;

    } else {

        cout << "Temperature is according to the desired condition" << endl;

    }

}


// Check amount of carbon dioxide

void checkgas() {

    int carbon = 1500;

    int c;

    cout << "Enter the current value of carbon dioxide: ";

    cin >> c;


    if (c < carbon) {

        cout << "Provide carbon dioxide" << endl;

        while (c < carbon) {

            c++;

        }

        cout << "loading................................." << endl;

        cout << "Reached the desired amount" << endl;

    }

}


// Display desired values

void values() {

    cout << "Temperature: 70F" << endl;

    cout << "Humidity: 50" << endl;

    cout << "Carbon dioxide: 1500 ppm" << endl;

}


//humidity

void humidity() {

    int h = 50;

    int c_h;

    cout << "Enter current humidity: ";

    cin >> c_h;


    if (c_h > h) {

        cout << "Turn on heater" << endl;

        while (c_h > h) {

            c_h--;

        }

        cout << "loading................................." << endl;

        cout << "Turned off heater humidity reached desired value" << endl;

    } else if (c_h < h) {

        cout << "Turn on water pump" << endl;

        while (c_h < h) {

            c_h++;

        }

        cout << "loading................................." << endl;

        cout << "Turned off water pump as it reached desired value" << endl;

    } else {

        cout << "Desired humidity" << endl;

    }

}


int main()

 {

    string p[maxplants] = {"tomato", "cherry", "lemon"};

    string person, password;

    int nplants = 3;

    authority:

    do{

    cout << "****************************" << endl;

    cout << "  WELCOME TO GREEN HOUSE " << endl;

    cout << "*************************""**" << endl;

    

    cout << "Are you user or admin?" << endl;

    cin >> person;

    cin.ignore();


    if (person == "admin") {

        cout << "Enter password: ";

        getline(cin, password);

        if (password == "blog by hannan") {

            while (1) {

                cout << "Select 1 for list of plants" << endl;

                cout << "Select 2 for adding plants" << endl;

                cout << "Select 3 for replacing plant" << endl;

                cout << "Select 4 for removing plant" << endl;

                cout << "Select 5 for exit" << endl;

                cout << "                              " << endl;

                int s;

                cout << "Enter your selection: ";

                cin >> s;


                switch (s) {

                case 1:

                    list(p, nplants);

                    break;

                case 2:

                    addplants(p, nplants);

                    break;

                case 3:

                    replacePlant(p, nplants);

                    break;

                case 4:

                    removeplant(p, nplants);

                    break;

                case 5:

                    goto authority;

                    break;

                default:

                    cout << "Not available" << endl;

                    break;

                }

            }

        }

    } else if (person == "user") {

        cout << "Enter password: ";

        getline(cin, password);

        if (password == "blog") {

            while (1) {

                cout << "Select 1 for list of plants" << endl;

                cout << "Select 2 for adding plants" << endl;

                cout << "Select 3 for desired values" << endl;

                cout << "Select 4 to manage temperature" << endl;

                cout << "Select 5 to provide carbon dioxide if necessary" << endl;

                cout << "Select 6 to manage humidity" << endl;

                cout << "Select 7 to exit" << endl;

                cout << "                              " << endl;

                int s;

                cout << "Enter your selection: ";

                cin >> s;


                switch (s) {

                case 1:

                    list(p, nplants);

                    break;

                case 2:

                    addnewplants(p, nplants);

                    break;

                case 3:

                    values();

                    break;

                case 4:

                    checktemp();

                    break;

                case 5:

                    checkgas();

                    break;

                case 6:

                    humidity();

                    break;

                case 7:

                    goto authority;

                    break;

                default:

                    cout << "Not available" << endl;

                    break;

                }

            }

        }

    } else {

        cout << "You can't access this system" << endl;

    }

    } while(true);

    

    return 0;

}

Main Features:

1 list of plants:

Both user and admin has authority to view number of plants present in green house. 


2. Adding Plants:

Admin has given authority to add plants but not more than 20 because green house supports only 20 plants. On the other hand user can add 6 plants.



3. Replacing Plant:

Admin has authority to replace a particular plant in green house with another plant.



4. Removing Plant:

Admin has the only authority to remove plants he wants.



5. Desired Values:

User can view the desired values of temperature, humidity and carbon dioxide because he has to manage all the system.

6. Manage Temperature:

 User can manage temperature by viewing the temperature from sensor and turn on AC and heater until it reached to desired value.



7. Provide Carbon Dioxide:

 User can add carbon dioxide for plants to grow.



8. Manage Humidity:

Users can control the humidity level by turning on heater and water pump.




Conclusion:

This program controls all the environmental aspects for plants and decides which plants should be introduce,replace and remove.



Comments

Popular posts from this blog

How to hack Facebook account using termux (password guessing method)

From Start To Success| A Step By Step Guide To Becoming A Profitable Amazon Seller

Bitcoin Price Prediction In 2024: Boom Or Bust?