This a database management project  that demonstrate the database operations. The operations include add, edit and delete the records. User can also search the records.

//[email protected]
//student of BCE
# include < iostream.h >
# include < conio.h >
# include < fstream.h >
# include < dos.h >
# include < stdio.h >
# include < string.h >
# include < stdlib.h >
# include < graphics.h >
//function declaration phase

int alphachk(char string[], int);
int emptychk(char field[]);
int doublechk(char field[]);
void processing();
void enter();
void display();
void del();
void search();

//class declaration phase
class log {
public:
    char article[18];
    char brand[18];
    char modle[12];
    char sep[8];
    unsigned int quant;
    unsigned int price;
};

//global variables

int deletion = 0;
int exiting = 0;
int initial = 0;
int searching = 0;

//body of main function

void main() {

    char choice;
    initial = 1;
    processing();
    do {
        clrscr();
        cout << "\n" << __TIME__ << ", " << __DATE__ << ".
            "<<"This (MENU BASED DATABASE.) Bis a COPYRIGHT(C) SOFTSOLUTIONS(R).";
        cout << "Enter \"E\" to ENTER Record.\n";
        cout << "   Enter \"D\" to DISPLAY Record.\n";
        cout << "   Enter \"T\" to DELETE Record.\n";
        cout << "   Enter \"S\" to SEARCH Record.\n";
        cout << "   Enter \"X\" to EXIT.\n";
        cout << "\n Enter Choice :";
        _setcursortype(_NORMALCURSOR);
        choice = getch();
        switch (choice) {
        case 'E':
        case 'e':
            processing();
            enter();
            break;
        case 'D':
        case 'd':
            processing();
            display();
            break;
        case 'T':
        case 't':
            processing();
            del();
            break;
        case 'S':
        case 's':
            processing();
            search();
            break;
        case 'X':
        case 'x':
            exiting++;
            processing();
            exit(0);

        default:
            cout << "INVALID ENTRY!";
            getch();
        }

    } while (choice != 'A' || 
        choice != 'a' || 
        choice != 'D' || 
        choice != 'd' || 
        choice != 'E' || 
        choice != 'e' || 
        choice != 'B' || 
        choice != 'b' || 
        choice != 'C' || 
        choice != 'c' || 
        choice != 'X' || 
        choice != 'x');
}

//function to take onlyalphabets

int alphachk(char string[], int len) {
    int a = 0;
    for (int i = 0; i < len; i++) {
        if (!((string[i] >= 65 && string[i] < 91) || 
            (string[i] > 96 && string[i] < 123) || (string[i] == 32))
        )
            ++a;
    }
    if (a == 0)
        return 0;
    else
        cout << "Only Alphabatical value required!   ENTER AGAIN";
    getch();
    return 1;
}

//fuction to check and emptyentry

int emptychk(char field[]) {
    if (field[0] == 32 || field[0] == '\0') {
        cout << "You cannot leave this field empty!   ENTER AGAIN";
        getch();
        return 1;
    }
    else
        return 0;
}

//function to check double entry//

int doublechk(char field[]) {
    ifstream ptr1;
    log phy1;
    int flag = 0;
    ptr1.open("record.dat", ios::in);
    do {
        if ((strcmpi(field, phy1.modle)) == 0)
            flag = 1;
    } while (ptr1.read((char*)&phy1, sizeof(phy1)) && !flag);
    ptr1.close();
    if (flag == 1) {
        cout << "Data already exist!   ENTER AGAIN";
        getch();
    }
    return flag;
}

//function to display processing bar//

void processing() {
    _setcursortype(_NOCURSOR);
    textcolor(WHITE);
    textbackground(RED);
    clrscr();
    if (initial == 1) {
        gotoxy(34, 10);
        cout << "LOADING file...";
        gotoxy(34, 11);
        cout << "please wait";
        initial = 0;
    }
    else if (deletion == 1) {
        gotoxy(34, 10);
        cout << "DELETIG DATA...";
        deletion = 0;
    }
    else if (searching == 1) {
        gotoxy(34, 10);
        cout << "SEARCHING DATA...";
        searching = 0;
    }
    else if ((deletion == 0 && exiting == 0 && searching == 0)) {
        clrscr();
        gotoxy(34, 10);
        cout << "PROCESSING...";
    }
    gotoxy(15, 20);

    cout << "\n";
    gotoxy(15, 21);
    cout << "\n";
    gotoxy(15, 22);

    cout << "\xDB";
    for (int i = 0; i < 46; i++) {
        delay(30 + i);
        if ((exiting != 0) && i <= 23) {
            gotoxy(30, 10);
            cout << "saving changes... ";
        }
        else if ((exiting != 0) && i >= 23) {
            gotoxy(30, 10);
            cout << "exiting........";
        }

        gotoxy(17 + i, 21);
        cout << "";
    }
    textcolor(WHITE);
    textbackground(RED);
    clrscr();
}
//function to take entery//

void enter() {
    _setcursortype(_NORMALCURSOR);
    int ch;
    char c1[] = "monitor", c2[] = "speaker", c3[] = "RAM", c4[] = "CPU", c5[] = "HDD";
    int choice;
    log phy;
    ofstream ptr;
    do {
        do {
            clrscr();
            gotoxy(5, 3);
            cout << "  1\t\t2\t\t3\t\t4\t\t5";
            gotoxy(5, 5);
            cout << "monitors\tspeakers\tRAM\t        CPU\t       HDD";
            gotoxy(5, 10);
            cout << "NOTE: All the asseseries such as casing, floppy drives and cddrives \n\t \
                are included to change the specifications contact ourasinistrator \n\t\t\t\tTHANK YOU";
            gotoxy(5, 15);
            cout << "\n\tenter product no. to enter (6 for any other) : ";
            cin >> choice;
            if (choice >= 1 && choice <= 6)
                break;
            else {
                gotoxy(5, 17);
                cout << "invalid entry re enter : ";

            }
        } while (1);

        do {
            ptr.open("record.dat", ios::app);
            clrscr();
            gotoxy(10, 10);
            if (choice == 1) strcpy(phy.article, c1);
            if (choice == 2) strcpy(phy.article, c2);
            if (choice == 3) strcpy(phy.article, c3);
            if (choice == 4) strcpy(phy.article, c4);
            if (choice == 5) strcpy(phy.article, c5);
            if (choice == 6) {
                cout << "Enter name of Article : ";
                gets(phy.article);
            }

        } while (alphachk(phy.article, strlen(phy.article)) || emptychk(phy.article));
        do {
            clrscr();
            gotoxy(10, 10);
            cout << "Enter name of Manufecturer/Brand : ";
            gets(phy.brand);

        } while ((alphachk(phy.brand, strlen(phy.brand))) || (emptychk(phy.brand)));
        do {
            clrscr();
            gotoxy(10, 10);
            cout << "Enter Modle : ";
            gets(phy.modle);
        } while ((doublechk(phy.modle)) || (emptychk(phy.modle)));

        do {
            clrscr();
            gotoxy(10, 10);
            if (choice == 3 || choice == 4)
                cout << "Enter Memory/Clock speed : ";
            else if (choice == 1)
                cout << "Enter size in inches : ";
            else if (choice == 2)
                cout << "Enter power : ";
            else if (choice == 5)
                cout << "enter capacity in GB : ";
            else
                cout << "any specifications : ";
            gets(phy.sep);
        } while (emptychk(phy.sep));

        clrscr();
        gotoxy(10, 10);
        cout << "Enter Quantity : ";
        cin >> phy.quant;
        clrscr();
        gotoxy(10, 10);
        cout << "Enter Price : ";
        cin >> phy.price;
        ptr.write((char*)&phy, sizeof phy);
        do {
            clrscr();
            gotoxy(10, 10);
            cout << "Do you want to enter more data : ";
            ch = getche();
            ptr.close();
        } while (!(ch == 'Y' || ch == 'y' || ch == 'N' || ch == 'n'));
    } while (ch == 'y' || ch == 'Y');
    processing();
}

//function to display existing records//

void display() {
    _setcursortype(_NOCURSOR);
    int i = 5;
    ifstream ptr2;
    struct log phy2;
    ptr2.open("record.dat", ios::out);
    gotoxy(2, 2);
    cout << "Article";
    gotoxy(17, 2);
    cout << "Brand";
    gotoxy(32, 2);
    cout << "Model";
    gotoxy(47, 2);
    cout << "Specification";
    gotoxy(62, 2);
    cout << "Price";
    gotoxy(70, 2);
    cout << "Quantity";
    cout << "\n****************************************************************************\n";
    while (ptr2.read((char*)&phy2, sizeof phy2)) {

        gotoxy(2, i);
        cout << phy2.article;
        gotoxy(17, i);
        cout << phy2.brand;
        gotoxy(32, i);
        cout << phy2.modle;
        gotoxy(47, i);
        cout << phy2.sep;
        gotoxy(62, i);
        cout << phy2.price;
        gotoxy(70, i);
        cout << phy2.quant;
        i += 2;
    }
    ptr2.close();
    getch();
    processing();
}
//function to delete records//
void del() {
    _setcursortype(_NORMALCURSOR);
    log phy4;
    int delcount = 0;
    char kmodel[18];
    ifstream ptr4;
    ofstream ptr5;
    clrscr();
    char choice;
    int choice1;
    do {
        delcount = 0;
        _setcursortype(_NORMALCURSOR);
        do {
            clrscr();
            gotoxy(10, 10);
            cout << "Are You Sure To Delete Records (y/n) : ";
            cin >> choice;
        } while (!(choice == 'y' || choice == 'n'));
        clrscr();
        if (choice == 'n') {}
        else if (choice == 'y') {
            gotoxy(10, 8);
            cout << "NOTE: the compatibility is highly case sensitive ";
            gotoxy(10, 10);
            cout << "enter the product name to be deleted :";
            gets(kmodel);
            searching = 1;
            processing();
            ofstream ptr5;
            ptr4.open("record.dat", ios::in);
            ptr5.open("removerecord.dat", ios::out);
            while ((ptr4.read((char*)&phy4, sizeof(phy4)))) {
                if ((strcmp(kmodel, phy4.article)) != 0) {
                    ptr5.write((char*)&phy4, sizeof(phy4));
                }
                else
                    delcount++;
            }
            ptr4.close();
            ptr5.close();
            ofstream ptr6;
            ifstream ptr7;
            ptr6.open("record.dat", ios::out);
            ptr7.open("removerecord.dat", ios::in);

            while (ptr7.read((char*)&phy4, sizeof phy4)) {
                ptr6.write((char*)&phy4, sizeof phy4);
            }
            ptr6.close();
            ptr7.close();
            ptr7.open("removerecord.dat", ios::out);
            ptr7.close();
            if (delcount == 0) {
                gotoxy(10, 10);
                cout << "NO SUCH RECORD FOUND \n          UNABLE TO DELETE DATA";
            }
            else {
                deletion = 1;
                processing();
            }
        }
        getch();
        do {
            clrscr();
            gotoxy(10, 10);
            cout << "1 : return to deletion menu ";
            gotoxy(10, 12);
            cout << "2 : exit ";
            cin >> choice1;
        } while (!(choice1 == 1 || choice1 == 2));
    } while (choice1 == 1);

    //else;
}

//function to search arecord//

void search() {
    _setcursortype(_NORMALCURSOR);
    searching = 1;
    ifstream ptr3;
    log phy6;
    char choice;
    do {
        searching = 1;
        int i = 5;
        _setcursortype(_NORMALCURSOR);
        clrscr();
        ptr3.open("record.dat", ios::in);
        char kmodel[18];
        gotoxy(10, 8);
        cout << "NOTE : the search is highly case sensitive ";
        gotoxy(10, 10);
        cout << "enter a product to search : ";
        gets(kmodel);
        processing();
        clrscr();
        cout << "\n***********************\n";
        gotoxy(2, 3);
        cout << "Article";
        gotoxy(17, 3);
        cout << "Brand";
        gotoxy(32, 3);
        cout << "Model";
        gotoxy(47, 3);
        cout << "Specification";
        gotoxy(62, 3);
        cout << "Price";
        gotoxy(70, 3);
        cout << "Quantity";

        while ((ptr3.read((char*)&phy6, sizeof(phy6)))) {
            if ((strcmp(kmodel, phy6.article)) == 0) {
                gotoxy(2, i);
                cout << phy6.article;
                gotoxy(17, i);
                cout << phy6.brand;
                gotoxy(32, i);
                cout << phy6.modle;
                gotoxy(47, i);
                cout << phy6.sep;
                gotoxy(62, i);
                cout << phy6.price;
                gotoxy(70, i);
                cout << phy6.quant;
                i++;
            }
        }
        ptr3.close();
        if (i == 5) {
            _setcursortype(_NORMALCURSOR);
            clrscr();
            gotoxy(10, 10);
            cout << "NO RECORD FOUND, MODIFY THE SEARCH";
            gotoxy(10, 11);
            cout << "search again (y/n)";
            cin >> choice;
        }
        else
            break;
    } while (choice == 'y');

    getch();
}

//endofprogramm//