Database Management System In C++ With Source Code
The Database Management System In C++ is developed in C++ Programming Language and this Project With Source Code only focused in Student Database Management In C++, This Student Database Management Project In C++ is based on the concept to save and generate all the records of the user especially the students.
A Student Data Management In C++ is considered as a simple database of students in college, you can make it ordered by name or by ID, there are some functions help you to create a database. In this Student Database Management System Mini Project In C++ the user can save data in file after you finish their work, be attention the folder of the program must contain (save.text).
This Lic Database Management System C++ also includes a downloadable Student Database System Project In C++ Source Code for free, just find the downloadable source code below and click to start downloading.
To start creating a Database Management System In C++, make sure that you have code blocks or any platform of C/C++ language installed in your computer.
Steps on how to create a Database Management System In C++ With Source Code
Database Management System In C++ With Source Code
- Step 1: Create a new project.
First open the code blocks IDE and click “create a new project“.
- Step 2: Choose console application.
Second click the “console application” and after that click “next“.
- Step 3: Choose C++ language.
Third choose “C++ language” and click “next“.
- Step 4: Name Your Project.
Fourth name the project you’ve created and click “next” after that click “finish“.
- Step 5: The actual code.
You are free to copy the given source code below or download the downloadable source code given.
The Code Given Below Is The Main Module
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 |
int main() { show(); SDB obj ; long int type , test , num_cases ; long int num_insert , num_del ,num_search ,check_insert , check_del ,check_search ; long double gpa; string name , id ; test = 1; cout << " Enter your choice: \n"; num_cases = check_num(3); while( test == 1 ) { switch ( num_cases ) { case 1 : system("CLS"); cout << "You chose 1 to create a database, Please enter the Name, ID and GPA of the student\n"; getline(cin ,name); while ( name[0] < 65 or name[0] > 122) { cout << " Wrong input !\n"; getline(cin ,name); } getline(cin ,id); while ( !(cin >> gpa) or gpa > 4) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; cout << " What type of database arrangement you want ? \n " << " 1-Name 2-ID \n"; type = check_num(2); obj.Construct(type , name , id , gpa); num_cases = menu(); break ; case 2 : system("CLS"); cout << " You chose 2 to insert data , Please enter number of students you want to save . \n" ; check_insert = 1 ; num_insert = check_num(0) ; for ( int j = 1 ; j <= num_insert ; j++) { if ( check_insert == 1) { cout << " Please enter name of student , Please enter the Name, ID and GPA of the student\n"; getline(cin ,name); while ( name[0] < 65 or name[0] > 122) { cout << " Wrong Name ! \n"; getline(cin ,name); } getline(cin ,id); while ( !(cin >> gpa) or gpa > 4) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; check_insert = obj.insertelement(name , id , gpa); } } num_cases = menu(); break; case 3 : system("CLS"); cout << "You chose 3 to delete data, Please enter number of students you want to delete \n"; check_del = 1 ; num_del = check_num(0); for ( int k = 1 ; k <= num_del ; k++) { if ( check_del != 0) { cout << "Please enter ID of student \n"; getline(cin , id); check_del = obj.deleteelement(id); if ( check_del == 3) k-- ; } } num_cases = menu(); break; case 4 : system("CLS"); cout << "You chose 4 to search on data,Please enter number of students you want to search on \n"; check_search = 1 ; num_search = check_num(); for ( int l = 1 ; l <= num_search ; l++) { if ( check_search != 0 ) { cout << " Please enter ID of student \n"; getline(cin , id); check_search = obj.searchelement(id); if ( check_search == 3) l--; } } num_cases = menu(); break; case 5 : system("CLS"); obj.print() ; num_cases = menu(); break ; case 6 : system("CLS"); int save_cheak ; save_cheak =obj.savefile(); num_cases = menu(); break ; case 7 : obj.help(); num_cases = menu(); break ; case 8 : exit(EXIT_SUCCESS); break ; default : cout << "Wrong input ! \n"; cout << "Enter your choice: \n"; num_cases = check_num(3); break ; } } return 0; } |
In this module which is the main module of the system.
Complete Source Code
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 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 |
#include <iostream> #include <fstream> #include <string> #include <cctype> #include <conio.h> #include <stdlib.h> using namespace std; struct id { string name; string no ; int gpa ; }; struct node { id data ; node * next ; node * back ; }; class SDB { private : node * first , *last , *new_node ; long int type ; int counter ; int flag = 0 ; public: SDB(){first = last = NULL ; int counter = 1; } int Construct ( long int i ,string n ,string x , long double y ) { if ( first == NULL) { type = i ; new_node = new node ; new_node -> data.name = n; new_node -> data.no = x ; new_node -> data.gpa = y ; new_node -> next = NULL; new_node -> back = NULL; first = new_node ; last = new_node ; counter++ ; return 1 ; } else { cout << " You used create option previously \n " ; return 0 ; } } int insertelement ( string n , string x , long double y ) { new_node = new node ; new_node -> data.name = n; new_node -> data.no = x ; new_node -> data.gpa = y ; if( first != NULL) { switch ( type ) { case 1 : if ( first -> data.name[0] >= n[0]) { first -> back = new_node ; new_node -> next = first ; new_node -> back = NULL ; first = new_node ; counter++ ; return 1 ; } else if ( last -> data.name[0] <= n[0] ) { last -> next = new_node ; new_node -> next = NULL ; new_node -> back = last ; last = new_node ; counter++ ; return 1 ; } else { node * current = first ; node * cur_next = current-> next ; for ( ; cur_next -> next != NULL ; ) { current = current -> next ; cur_next = cur_next ->next ; if( cur_next -> data.name[0] >= n[0]) break ; } cur_next -> back = new_node ; new_node -> next = cur_next ; new_node -> back = current ; current -> next = new_node ; counter++ ; return 1 ; } break ; case 2 : if ( first -> data.no >= x) { first -> back = new_node ; new_node -> next = first ; new_node -> back = NULL ; first = new_node ; counter++ ; return 1 ; } else if ( last -> data.no <= x ) { last -> next = new_node ; new_node -> next = NULL ; new_node -> back = last ; last = new_node ; counter++ ; return 1 ; } else { node * current = first ; node * cur_next = current-> next ; for ( ; cur_next -> next != NULL ; ) { current = current -> next ; cur_next = cur_next ->next ; if( cur_next -> data.no >= x) break ; } cur_next -> back = new_node ; new_node -> next = cur_next ; new_node -> back = current ; current -> next = new_node ; counter++ ; return 1 ; } break ; } } else { cout << " Please use create option first \n"; return 0 ; } } int deleteelement (string x ) { if ( first != NULL) { node * del_first = first ; node * del_last = last; node * del_next = del_first -> next ; node * del_back = last -> back ; if ( first -> data.no == x ) { first = del_next ; delete (del_first); counter-- ; return 1; } else if ( last -> data.no == x) { last = del_back; last -> next = NULL ; delete (del_last); counter-- ; return 1; } else { for ( ; del_first ->next != NULL ; ) { del_first = del_first -> next ; del_back = del_first -> back ; del_next = del_first -> next ; if ( x == del_first -> data.no) { del_next -> back = del_first ->back ; del_back -> next = del_first ->next; delete (del_first); flag = 1 ; counter-- ; return 1; } } } if ( flag == 0 ) { cout << "Wrong ID \n" ; return 3; } } else { cout << "Empty database !!\n"; return 0; } } void print ( void ) { cout << " Name\t\tID\tGPA\n\n"; node* pri_ele = first ; for ( ; pri_ele != NULL ; ) { cout << pri_ele-> data.name << "\t" << pri_ele ->data.no << "\t" << pri_ele->data.gpa << endl ; pri_ele = pri_ele-> next ; } } int savefile ( void ) { node *save = first ; int fs = 0 ; ofstream fout("save.txt") ; if (!fout.is_open()) // failed to open file { cout << "Could not open the file " << "save.txt" << endl; return 0 ; } fout << " Name\t\tID\tGPA\n\n"; for ( ; save != NULL ; ) { fout << save-> data.name << "\t" << save ->data.no << "\t" << save ->data.gpa << endl ; save = save-> next ; fs = 1 ; } fout.close(); if (fs == 0) { cout << "Empty database !! \n"; return 0 ; } else { cout << "Done \n"; return 1 ; } } int searchelement ( string x) { node* sch = first ; int f = 0; if ( first == NULL ) { cout << "Empty Database \n"; return 0 ; } else { while ( sch != NULL) { if( sch -> data.no == x ) { cout <<sch -> data.name << "\t" << sch -> data.no << "\t" << sch -> data.gpa << endl ; f = 1; return 1; break ; } sch = sch ->next; } if (f == 0) { cout << "Wrong ID \n" ; return 3; } } } void help ( void ) { system("CLS"); cout << "This program considered as simple database of students in collage , you can make it ordered by name or by ID , there are some functions help you to create a database : \n" << "Crate Function : \n" << "You must use this is function at first to create database ,in this function you must enter type of order ( name or ID ) , if you want to insert another data you can use insert function \n" << "Insert/Delete/Search Functions :\n" << "In this function you can insert/delete/search on any number of data , you must use this functions after using create function \n" << "Save Function :\n" << "You can save data in file after you finish your work ,be attention the folder of program must contain (save.text)\n " << "Thanks for reading \n" ; } }; void show (void) ; int check_num(int x = 0); int menu (); int main() { show(); SDB obj ; long int type , test , num_cases ; long int num_insert , num_del ,num_search ,check_insert , check_del ,check_search ; long double gpa; string name , id ; test = 1; cout << " Enter your choice: \n"; num_cases = check_num(3); while( test == 1 ) { switch ( num_cases ) { case 1 : system("CLS"); cout << "You chose 1 to create a database, Please enter the Name, ID and GPA of the student\n"; getline(cin ,name); while ( name[0] < 65 or name[0] > 122) { cout << " Wrong input !\n"; getline(cin ,name); } getline(cin ,id); while ( !(cin >> gpa) or gpa > 4) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; cout << " What type of database arrangement you want ? \n " << " 1-Name 2-ID \n"; type = check_num(2); obj.Construct(type , name , id , gpa); num_cases = menu(); break ; case 2 : system("CLS"); cout << " You chose 2 to insert data , Please enter number of students you want to save . \n" ; check_insert = 1 ; num_insert = check_num(0) ; for ( int j = 1 ; j <= num_insert ; j++) { if ( check_insert == 1) { cout << " Please enter name of student , Please enter the Name, ID and GPA of the student\n"; getline(cin ,name); while ( name[0] < 65 or name[0] > 122) { cout << " Wrong Name ! \n"; getline(cin ,name); } getline(cin ,id); while ( !(cin >> gpa) or gpa > 4) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; check_insert = obj.insertelement(name , id , gpa); } } num_cases = menu(); break; case 3 : system("CLS"); cout << "You chose 3 to delete data, Please enter number of students you want to delete \n"; check_del = 1 ; num_del = check_num(0); for ( int k = 1 ; k <= num_del ; k++) { if ( check_del != 0) { cout << "Please enter ID of student \n"; getline(cin , id); check_del = obj.deleteelement(id); if ( check_del == 3) k-- ; } } num_cases = menu(); break; case 4 : system("CLS"); cout << "You chose 4 to search on data,Please enter number of students you want to search on \n"; check_search = 1 ; num_search = check_num(); for ( int l = 1 ; l <= num_search ; l++) { if ( check_search != 0 ) { cout << " Please enter ID of student \n"; getline(cin , id); check_search = obj.searchelement(id); if ( check_search == 3) l--; } } num_cases = menu(); break; case 5 : system("CLS"); obj.print() ; num_cases = menu(); break ; case 6 : system("CLS"); int save_cheak ; save_cheak =obj.savefile(); num_cases = menu(); break ; case 7 : obj.help(); num_cases = menu(); break ; case 8 : exit(EXIT_SUCCESS); break ; default : cout << "Wrong input ! \n"; cout << "Enter your choice: \n"; num_cases = check_num(3); break ; } } return 0; } int check_num(int x ) { int num ; switch ( x ) { case 1 : case 2 : while ( !(cin >> num) or num > 2) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; break ; case 3 : while ( !(cin >> num) or num > 8) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; break ; default : while ( !(cin >> num) ) { cin.clear(); while ( cin.get() != '\n') continue; cout << " Wrong input !\n"; } while ( cin.get() != '\n') continue; break ; } return num ; } int login(); void show (void) { login(); cout <<"\n\t ------WELCOME TO DATABASE MANAGEMENT SYSTEM------ \n\n"; cout << "********************************************************************************\n" << "********************************************************************************\n" << "*** 1- Create Database ***\n" << "*** 2- Insert Data ***\n" << "*** 3- Delete Data ***\n" << "*** 4- Search on Data ***\n" << "*** 5- Print Data ***\n" << "*** 6- Save ***\n" << "*** 7- Help ***\n" << "*** 8- Exit ***\n" << "********************************************************************************\n" << "********************************************************************************\n"; } int menu() { int num_cases; cout << " Do you want to do another operation?\n " << " 1- Yes 2-No \n"; int t = check_num(1); if ( t == 1) { system("cls"); show(); cout << "Enter your choice: \n"; num_cases = check_num(3); return num_cases; } else return 8 ; } int login () { //Low Protection Login Code /*string userName; string userPassword; int loginAttempt = 0; while (loginAttempt < 5) { cout << "\n\tPlease enter your user name: "; cin >> userName; cout << "\n\tPlease enter your user password: "; cin >> userPassword; if (userName == "greg" && userPassword == "pass") { cout << "\n\tWelcome Greg!\n"; //cp nsb break; } else if (userName == "code" && userPassword == "projects") { cout << "\n\tWelcome Admin!\n"; break; } else { cout << "Invalid login attempt. Please try again.\n" << '\n'; loginAttempt++; } } if (loginAttempt == 5) { cout << "Too many login attempts! The program will now terminate."; return 0; } cout << "\n\tThank you for logging in.\n\n"; system("PAUSE"); system("CLS"); */ string pass =""; char ch; cout << "\n\n\n\n\t\t\t\t Database Management System"; cout << "\n\n\n\n\n\n\n\t\t\t\t\tEnter Password: "; ch = _getch(); while(ch != 13){//character 13 is enter pass.push_back(ch); cout << '*'; ch = _getch(); } if(pass == "pass"){ cout << "\n\n\t\t\t\t\tAccess Granted \n"; }else{ cout << "\n\n\t\t\t\t\tAccess Aborted...Press Any Key To Try Again\n"; ch = _getch(); system("CLS"); login(); } system("PAUSE"); system("CLS"); } |
ABOUT PROJECT | PROJECT DETAILS |
---|---|
Project Name : | Database Management System |
Project Platform : | C/C++ |
Programming Language Used: | C++ Programming Language |
Developer Name : | itsourcecode.com |
IDE Tool (Recommended): | Dev-C++/Codeblocks |
Project Type : | Desktop Application |
Database: | Stores data in .DAT file |
Upload Date and Time: | October 19, 2020 – 8:26 am |
Downloadable Source Code
Summary
The whole project is designed in ‘C++’ language and different variables and strings have been used for the development of this project. This mini project is easy to operate and understand by the users.
This simple project can enhance the knowledge of the beginners or the students to develop their skills in programming, also this project is easy to understand the module and their variables.
Related Articles
- School Management System In C++ With Source Code
- Bus Reservation System in C++ with Source Code
- Library Management System In C++ With Source Code
- Food Ordering System Project in C++ with Source Code
- Hostel Booking System Project in C++ with Source Code
- Bank Management System in C++ with Source Code
Inquiries
If you have any questions or suggestions about Database Management System In C++ With Source Code , please feel free to leave a comment below.