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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 | //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// |