User: Analyse this C++ code:&nbsp;<code fileName="untitled" notes="">#include &lt;iostream&gt;
#include &lt;vector&gt;
#include &lt;fstream&gt;
#include &lt;string&gt;
#include &lt;iomanip&gt;

using namespace std;

// Structure to represent an inventory item
struct Item {
    int id;
    string name;
    int quantity;
    double price;
};

// Function Prototypes
void displayMenu();
void addItem(vector&lt;Item&gt; &amp;inventory);
void viewInventory(const vector&lt;Item&gt; &amp;inventory);
void updateItem(vector&lt;Item&gt; &amp;inventory);
void deleteItem(vector&lt;Item&gt; &amp;inventory);
void searchItem(const vector&lt;Item&gt; &amp;inventory);
void saveToFile(const vector&lt;Item&gt; &amp;inventory, const string &amp;filename);
void loadFromFile(vector&lt;Item&gt; &amp;inventory, const string &amp;filename);
bool idExists(const vector&lt;Item&gt; &amp;inventory, int id);

int main() {
    vector&lt;Item&gt; inventory;
    string filename = &quot;inventory.txt&quot;;
    loadFromFile(inventory, filename);

    int choice;
    do {
        displayMenu();
        cout &lt;&lt; &quot;Enter your choice: &quot;;
        cin &gt;&gt; choice;

        // Handle invalid input (non-integer)
        if(cin.fail()){
            cin.clear(); // clear the error flag
            cin.ignore(numeric_limits&lt;streamsize&gt;::max(), &#039;\n&#039;); // discard invalid input
            cout &lt;&lt; &quot;Invalid input! Please enter a number between 1 and 7.\n&quot;;
            continue;
        }

        switch(choice) {
            case 1:
                addItem(inventory);
                break;
            case 2:
                viewInventory(inventory);
                break;
            case 3:
                updateItem(inventory);
                break;
            case 4:
                deleteItem(inventory);
                break;
            case 5:
                searchItem(inventory);
                break;
            case 6:
                saveToFile(inventory, filename);
                cout &lt;&lt; &quot;Inventory saved to &quot; &lt;&lt; filename &lt;&lt; &quot; successfully.\n&quot;;
                break;
            case 7:
                saveToFile(inventory, filename);
                cout &lt;&lt; &quot;Exiting the program. Inventory saved to &quot; &lt;&lt; filename &lt;&lt; &quot;.\n&quot;;
                break;
            default:
                cout &lt;&lt; &quot;Invalid choice! Please select a number between 1 and 7.\n&quot;;
        }
    } while(choice != 7);

    return 0;
}

void displayMenu(){
    cout &lt;&lt; &quot;\n===== Inventory Management System =====\n&quot;;
    cout &lt;&lt; &quot;1. Add New Item\n&quot;;
    cout &lt;&lt; &quot;2. View Inventory\n&quot;;
    cout &lt;&lt; &quot;3. Update Item\n&quot;;
    cout &lt;&lt; &quot;4. Delete Item\n&quot;;
    cout &lt;&lt; &quot;5. Search Item\n&quot;;
    cout &lt;&lt; &quot;6. Save Inventory\n&quot;;
    cout &lt;&lt; &quot;7. Exit\n&quot;;
}

bool idExists(const vector&lt;Item&gt; &amp;inventory, int id){
    for(const auto &amp;item : inventory){
        if(item.id == id) return true;
    }
    return false;
}

void addItem(vector&lt;Item&gt; &amp;inventory){
    Item newItem;
    cout &lt;&lt; &quot;Enter Item ID: &quot;;
    cin &gt;&gt; newItem.id;

    // Check for unique ID
    if(idExists(inventory, newItem.id)){
        cout &lt;&lt; &quot;Item with ID &quot; &lt;&lt; newItem.id &lt;&lt; &quot; already exists.\n&quot;;
        return;
    }

    cout &lt;&lt; &quot;Enter Item Name: &quot;;
    cin.ignore(); // To ignore the newline character left in the buffer
    getline(cin, newItem.name);

    cout &lt;&lt; &quot;Enter Quantity: &quot;;
    cin &gt;&gt; newItem.quantity;
    if(cin.fail() || newItem.quantity &lt; 0){
        cin.clear();
        cin.ignore(numeric_limits&lt;streamsize&gt;::max(), &#039;\n&#039;);
        cout &lt;&lt; &quot;Invalid quantity. Operation cancelled.\n&quot;;
        return;
    }

    cout &lt;&lt; &quot;Enter Price: &quot;;
    cin &gt;&gt; newItem.price;
    if(cin.fail() || newItem.price &lt; 0){
        cin.clear();
        cin.ignore(numeric_limits&lt;streamsize&gt;::max(), &#039;\n&#039;);
        cout &lt;&lt; &quot;Invalid price. Operation cancelled.\n&quot;;
        return;
    }

    inventory.push_back(newItem);
    cout &lt;&lt; &quot;Item added successfully!\n&quot;;
}

void viewInventory(const vector&lt;Item&gt; &amp;inventory){
    if(inventory.empty()){
        cout &lt;&lt; &quot;Inventory is empty.\n&quot;;
        return;
    }

    cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; &quot;ID&quot; 
         &lt;&lt; left &lt;&lt; setw(30) &lt;&lt; &quot;Name&quot; 
         &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; &quot;Quantity&quot; 
         &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; &quot;Price&quot; &lt;&lt; endl;
    cout &lt;&lt; string(60, &#039;-&#039;) &lt;&lt; endl;

    for(const auto &amp;item : inventory){
        cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; item.id 
             &lt;&lt; left &lt;&lt; setw(30) &lt;&lt; item.name 
             &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; item.quantity 
             &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; item.price 
             &lt;&lt; endl;
    }
}

void updateItem(vector&lt;Item&gt; &amp;inventory){
    if(inventory.empty()){
        cout &lt;&lt; &quot;Inventory is empty. Nothing to update.\n&quot;;
        return;
    }

    int id;
    cout &lt;&lt; &quot;Enter the ID of the item to update: &quot;;
    cin &gt;&gt; id;

    for(auto &amp;item : inventory){
        if(item.id == id){
            cout &lt;&lt; &quot;Item found: &quot; &lt;&lt; item.name &lt;&lt; &quot;\n&quot;;
            cout &lt;&lt; &quot;Enter new name (leave blank to keep current): &quot;;
            cin.ignore();
            string newName;
            getline(cin, newName);
            if(!newName.empty()){
                item.name = newName;
            }

            cout &lt;&lt; &quot;Enter new quantity (enter -1 to keep current): &quot;;
            int newQty;
            cin &gt;&gt; newQty;
            if(!cin.fail() &amp;&amp; newQty &gt;= 0){
                item.quantity = newQty;
            } else if(newQty != -1){
                cin.clear();
                cin.ignore(numeric_limits&lt;streamsize&gt;::max(), &#039;\n&#039;);
                cout &lt;&lt; &quot;Invalid quantity input. Quantity not updated.\n&quot;;
            }

            cout &lt;&lt; &quot;Enter new price (enter -1 to keep current): &quot;;
            double newPrice;
            cin &gt;&gt; newPrice;
            if(!cin.fail() &amp;&amp; newPrice &gt;= 0){
                item.price = newPrice;
            } else if(newPrice != -1){
                cin.clear();
                cin.ignore(numeric_limits&lt;streamsize&gt;::max(), &#039;\n&#039;);
                cout &lt;&lt; &quot;Invalid price input. Price not updated.\n&quot;;
            }

            cout &lt;&lt; &quot;Item updated successfully!\n&quot;;
            return;
        }
    }

    cout &lt;&lt; &quot;Item with ID &quot; &lt;&lt; id &lt;&lt; &quot; not found.\n&quot;;
}

void deleteItem(vector&lt;Item&gt; &amp;inventory){
    if(inventory.empty()){
        cout &lt;&lt; &quot;Inventory is empty. Nothing to delete.\n&quot;;
        return;
    }

    int id;
    cout &lt;&lt; &quot;Enter the ID of the item to delete: &quot;;
    cin &gt;&gt; id;

    for(auto it = inventory.begin(); it != inventory.end(); ++it){
        if(it-&gt;id == id){
            cout &lt;&lt; &quot;Are you sure you want to delete item \&quot;&quot; &lt;&lt; it-&gt;name &lt;&lt; &quot;\&quot;? (y/n): &quot;;
            char confirm;
            cin &gt;&gt; confirm;
            if(confirm == &#039;y&#039; || confirm == &#039;Y&#039;){
                inventory.erase(it);
                cout &lt;&lt; &quot;Item deleted successfully.\n&quot;;
            } else {
                cout &lt;&lt; &quot;Deletion cancelled.\n&quot;;
            }
            return;
        }
    }

    cout &lt;&lt; &quot;Item with ID &quot; &lt;&lt; id &lt;&lt; &quot; not found.\n&quot;;
}

void searchItem(const vector&lt;Item&gt; &amp;inventory){
    if(inventory.empty()){
        cout &lt;&lt; &quot;Inventory is empty.\n&quot;;
        return;
    }

    cout &lt;&lt; &quot;Search by:\n1. ID\n2. Name\nEnter choice: &quot;;
    int choice;
    cin &gt;&gt; choice;

    if(choice == 1){
        int id;
        cout &lt;&lt; &quot;Enter Item ID: &quot;;
        cin &gt;&gt; id;
        for(const auto &amp;item : inventory){
            if(item.id == id){
                cout &lt;&lt; &quot;Item Found:\n&quot;;
                cout &lt;&lt; &quot;ID: &quot; &lt;&lt; item.id &lt;&lt; &quot;\nName: &quot; &lt;&lt; item.name 
                     &lt;&lt; &quot;\nQuantity: &quot; &lt;&lt; item.quantity 
                     &lt;&lt; &quot;\nPrice: &quot; &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; item.price &lt;&lt; &quot;\n&quot;;
                return;
            }
        }
        cout &lt;&lt; &quot;No item found with ID &quot; &lt;&lt; id &lt;&lt; &quot;.\n&quot;;
    }
    else if(choice == 2){
        cout &lt;&lt; &quot;Enter Item Name: &quot;;
        cin.ignore();
        string name;
        getline(cin, name);
        bool found = false;
        for(const auto &amp;item : inventory){
            if(item.name.find(name) != string::npos){
                if(!found){
                    cout &lt;&lt; &quot;Matching Items:\n&quot;;
                    cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; &quot;ID&quot; 
                         &lt;&lt; left &lt;&lt; setw(30) &lt;&lt; &quot;Name&quot; 
                         &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; &quot;Quantity&quot; 
                         &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; &quot;Price&quot; &lt;&lt; endl;
                    cout &lt;&lt; string(60, &#039;-&#039;) &lt;&lt; endl;
                    found = true;
                }
                cout &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; item.id 
                     &lt;&lt; left &lt;&lt; setw(30) &lt;&lt; item.name 
                     &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; item.quantity 
                     &lt;&lt; left &lt;&lt; setw(10) &lt;&lt; fixed &lt;&lt; setprecision(2) &lt;&lt; item.price 
                     &lt;&lt; endl;
            }
        }
        if(!found){
            cout &lt;&lt; &quot;No items match the name \&quot;&quot; &lt;&lt; name &lt;&lt; &quot;\&quot;.\n&quot;;
        }
    }
    else{
        cout &lt;&lt; &quot;Invalid choice. Returning to main menu.\n&quot;;
    }
}

void saveToFile(const vector&lt;Item&gt; &amp;inventory, const string &amp;filename){
    ofstream outFile(filename);
    if(!outFile){
        cout &lt;&lt; &quot;Error opening file for writing.\n&quot;;
        return;
    }

    for(const auto &amp;item : inventory){
        outFile &lt;&lt; item.id &lt;&lt; &#039;,&#039; 
                &lt;&lt; item.name &lt;&lt; &#039;,&#039; 
                &lt;&lt; item.quantity &lt;&lt; &#039;,&#039; 
                &lt;&lt; item.price &lt;&lt; &#039;\n&#039;;
    }

    outFile.close();
}

void loadFromFile(vector&lt;Item&gt; &amp;inventory, const string &amp;filename){
    ifstream inFile(filename);
    if(!inFile){
        // File does not exist. Start with empty inventory.
        return;
    }

    string line;
    while(getline(inFile, line)){
        if(line.empty()) continue;
        Item item;
        size_t pos1 = line.find(&#039;,&#039;);
        if(pos1 == string::npos) continue;
        item.id = stoi(line.substr(0, pos1));

        size_t pos2 = line.find(&#039;,&#039;, pos1 + 1);
        if(pos2 == string::npos) continue;
        item.name = line.substr(pos1 + 1, pos2 - pos1 - 1);

        size_t pos3 = line.find(&#039;,&#039;, pos2 + 1);
        if(pos3 == string::npos) continue;
        item.quantity = stoi(line.substr(pos2 + 1, pos3 - pos2 - 1));

        item.price = stod(line.substr(pos3 + 1));

        inventory.push_back(item);
    }

    inFile.close();
}</code>