#include <iostream>
#include <cstring>
#include <cstdlib>
using namespace std;

struct Directory {
    char dname[10], fname[10][10];
    int fcnt;
} dir;

int main() {
    int i, ch;
    char f[30];
    dir.fcnt = 0;

    cout << "\nEnter name of directory: ";
    cin >> dir.dname;

    while (1) {
        cout << "\n\n1. Create File\t2. Delete File\t3. Search File\n4. Display Files\t5. Exit";
        cout << "\nEnter your choice: ";
        cin >> ch;

        switch (ch) {
            case 1:
                cout << "\nEnter the name of the file: ";
                cin >> dir.fname[dir.fcnt];
                dir.fcnt++;
                break;

            case 2:
                cout << "\nEnter the name of the file: ";
                cin >> f;
                for (i = 0; i < dir.fcnt; i++) {
                    if (strcmp(f, dir.fname[i]) == 0) {
                        cout << f << " is deleted";
                        strcpy(dir.fname[i], dir.fname[dir.fcnt - 1]); // last file overwrite
                        break;
                    }
                }
                if (i == dir.fcnt) 
                    cout << f << " not found";
                dir.fcnt--;
                break;

            case 3:
                cout << "\nEnter the name of the file to search: ";
                cin >> f;
                for (i = 0; i < dir.fcnt; i++) {
                    if (strcmp(f, dir.fname[i]) == 0)
                        cout << f << " is found";
                }
                if (i == dir.fcnt) 
                    cout << f << " not found";
                break;

            case 4:
                if (dir.fcnt == 0) 
                    cout << "\nDirectory Empty";
                else {
                    cout << "\nThe Files are:\n";
                    for (i = 0; i < dir.fcnt; i++)
                        cout << dir.fname[i] << "\n";
                }
                break;

            case 5:
                exit(0);

            default:
                cout << "\nInvalid choice!";
        }
    }
}