Code of Bike Renting System in C
The Bike Renting System with Source Code is a project that can rent a bike. The system can help you edit, delete views, manage and search for the renting of bikes for your customer. The purpose of the Bike Renting System is to assist and to maintain the managing of customer renting records.
The Bike Renting System code was developed in a simple console application, the system is strictly needs user login information in order to access the system. The user can do a set of tasks in the system in the system, the user can register a rented bike detail, view the Record of the Rental, remove Record of the Rental, and edit the record. The system has all the needed functions to operate the renting system, you can easily edit, delete view, manage and search the renting process by filling in the customer details. The data that will be input will be stored as a text extension file. The Bike Renting System was created in a basic coding structure of C to teach and help the beginner to start their programming career.
Functional Requirements of Bike Renting System using C
- The user can Rent a Bike
- The user can view the Record of the Rental
- The user can Remove the Record of the Rental
- The user can Search Record of the Rental
- The user can Edit Record
Installation of Bike Renting System using C:
- Extract the zip file.
- Open the extracted folder
- Locate the c file.
- Then open the file via code blocks or any IDE’s that can run C++ files.
- Then click run and build.
User Login Information
Username: Username is admin
Password: Password is admin
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 |
#include<stdio.h> #include<conio.h> #include<ctype.h> #include<windows.h> #include<stdlib.h> #include<time.h> void main_menu(); void add(); void list(); void edit(); void delete1(); void search(); void gotoxy(int x, int y) { COORD CR; CR.X=x; CR.Y=y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), CR); } void setcolor(int ForgC) { WORD wColor; HANDLE hStdOut=GetStdHandle(STD_OUTPUT_HANDLE); CONSOLE_SCREEN_BUFFER_INFO csbi; if(GetConsoleScreenBufferInfo(hStdOut,&csbi)) { wColor=(csbi.wAttributes & 0xF0)+(ForgC & 0x0F); SetConsoleTextAttribute(hStdOut,wColor); } } void login() { int a=0,i=0; char uname[10],c=' '; char pword[10],code[10]; char user[10]="admin"; char pass[10]="admin"; do { printf("\n <<<<<<<<<<<<<<<<<<<<<<<<< LOGIN FORM >>>>>>>>>>>>>>>>>>>>>>>>>> "); printf(" \n ENTER USERNAME:-"); scanf("%s", &uname); printf(" \n ENTER PASSWORD:-"); while(i<10) { pword[i]=getch(); c=pword[i]; if(c==13) break; else printf("*"); i++; } pword[i]='\0'; i=0; if(strcmp(uname,"admin")==0 && strcmp(pword,"admin")==0) { printf(" \n\n\n NOW YOU ARE LOGGED IN. WELCOME TO OUR SYSTEM !!"); printf("\n\n\n\t\t\t\tPress any key to continue..."); getch(); break; } else { printf("\n SORRY !!!! LOGIN IS UNSUCESSFUL"); a++; getch();//holds the screen } } while(a<=2); if (a>2) { printf("\nSorry you have entered the wrong username and password for four times!!!"); getch(); } system("cls"); } struct CustomerDetails //STRUCTURE DECLARATION { int bikenumber; char name[20]; char address[20]; char phonenumber[15]; char nationality[15]; char email[35]; int period; }s; int main() { int i=0; time_t t; time(&t); system("cls"); setcolor(55); printf("\t\t|------------------------------------------------|\n"); printf("\t\t| |\n"); printf("\t\t| ----------------------------- |\n"); printf("\t\t| BIKE RENTAL SYSTEM |\n"); printf("\t\t| ----------------------------- |\n"); printf("\t\t| |\n"); printf("\t\t| |\n"); printf("\t\t| |\n"); printf("\t\t|------------------------------------------------|\n\n\n"); for(i=0;i<80;i++) printf(">"); printf("\nCurrent date and time : %s",ctime(&t)); for(i=0;i<80;i++) printf("<"); printf(" \n Press any key to continue:"); getch(); system("cls"); login(); main_menu(); } void main_menu() { int i=0; time_t t; time(&t); char customername; char choice; system("cls"); while (1) // INFINITE LOOP { system("cls"); setcolor(55); for(i=0;i<80;i++) printf("-"); printf("\n"); printf(" ************************************** |MAIN MENU| ************************************** \n"); for(i=0;i<80;i++) printf("-"); printf("\n"); setcolor(55); printf("\t\t *Select and Enter Your Choice From Menu*:"); printf("\n\n"); printf("\n**************************************"); printf(" \n Enter 1 ->> Rent a bike"); printf("\n**************************************"); printf(" \n Enter 2 ->> View Rental Record"); printf("\n**************************************"); printf(" \n Enter 3 ->> Remove Rental Record"); printf("\n**************************************"); printf(" \n Enter 4 ->> Search Rental Record"); printf("\n**************************************"); printf(" \n Enter 5 ->> Edit Record"); printf("\n**************************************"); printf(" \n Enter 6 ->> Exit"); printf("\n**************************************"); printf("\n \n"); for(i=0;i<80;i++) printf(">"); printf("\nCurrent date and time : %s",ctime(&t)); for(i=0;i<80;i++) printf("<"); choice=getche(); choice=toupper(choice); switch(choice) // SWITCH STATEMENT { case '1': add();break; case '2': list();break; case '3': delete1();break; case '4': search();break; case '5': edit();break; case '6': system("cls"); printf("\n\n\t >>>>>THANK YOU<<<<<"); printf("\n\t FOR USING OUR SERVICE"); // Sleep(2000); exit(0); break; default: system("cls"); printf("Incorrect Input"); printf("\n Press any key to continue"); getch(); } } } void add() { FILE *f; int bikenumber, n, i, valid=0; char test; f=fopen("add.txt","a+"); if(f==0) { f=fopen("add.txt","w+"); system("cls"); printf("Please hold on while we set our database in your computer!!"); printf("\n Process completed press any key to continue!! "); getch(); } system("cls"); printf("\n Enter Customer Details:"); printf("\n-------------------------"); if((f = fopen("add.txt","r+"))!=NULL) { ADD: printf("\n Enter bike number\t: "); scanf(" i%",&bikenumber); while(fscanf(f,"%i %s %s %s %s %s %i\n", &s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, &s.period)!=EOF) { if(bikenumber == s.bikenumber) { printf("\n\tTHIS BIKE IS ALREADY ON RENT."); goto ADD; } } s.bikenumber == bikenumber; Q: printf("\n Enter Name\t\t: "); fflush(stdin); gets(s.name); if(strlen(s.name)>20||strlen(s.name)<2) { printf("\nInvalid!!\n\tThe maximum number for customer's name is less than 21 and more than 1.\n"); goto Q; } else { for (i=0;i<strlen(s.name);i++) { if(isalpha(s.name[i])) { valid = 1; } else { valid = 0; break; } } if (!valid) { printf("\nName contain invalid character. Please enter again.\n"); goto Q; } } do { A: printf("\n Enter Address\t\t:"); scanf("%s",s.address); if(strlen(s.address)>20 || strlen(s.address)<2) { printf("\nInvalid!!\n\tThe maximum number for customer's name is less than 21 and more than 1.\n"); goto A; } else { for (i=0;i<strlen(s.address); ++i) { if(isalpha(s.address[i])) { valid = 1; } else { valid = 0; break; } } if (!valid) { printf("\nName contain invalid character. Please enter again.\n"); } } }while(!valid); do { P: printf("\n Enter Phone Number\t: "); scanf("%s",s.phonenumber); if (strlen(s.phonenumber)!=10 || strlen(s.phonenumber)>10) { printf("\nPhone number should be of 10 numbers from 0-9. Please, enter valid number.\n"); goto P; } for(i=0;i<strlen(s.phonenumber); i++) { if(!isalpha(s.phonenumber[i])) { valid=1; } else { valid=0; break; } } if(!valid) { printf("\nThe phone number is invalid. Please, enter numbers only.\n"); } }while(!valid); do { X: printf("\nEnter Nationality\t: "); scanf("%s",s.nationality); if(strlen(s.nationality)>10 || strlen(s.nationality)<2) { printf("\nInvalid!!\n\tThe maximum name can be upto 15 and and more than 1.\n"); goto X; } for(i=0;i<strlen(s.nationality); i++) { if(isalpha(s.nationality[i])) { valid=1; } else { valid=0; break; } } if(!valid) { printf("\nThe nationality name contains only character. Please, enter again.\n"); } }while(!valid); do { printf("\nEnter Email\t\t: "); scanf(" %s",s.email); if(strlen(s.email)>35||strlen(s.email)<10) { printf("\nInvalid!!\n\tThe maximum number for customer's email is less than 31 and more than 10.\n"); } }while(strlen(s.email)>35||strlen(s.email)<2); do { printf("\nEnter Time Period(\'x\'days)\t: "); scanf("%i",&s.period); if(s.period>10 || s.period<=0) { printf("\tInvalid!!\n\tThe maximum bike rental days for customer is upto 10 days .\n"); } }while(s.period>10 || s.period<=0); fprintf(f,"%i %s %s %s %s %s %i\n", s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, s.period); printf("\n\n Your Desired Bike is rented successfully!!"); fclose(f); } printf("\n Press esc key to exit, any other key to add another customer detail:"); test=getche(); if(test==27) main_menu(); else add(); } void list() { FILE *f; int i, q; if((f=fopen("add.txt","r"))==NULL) exit(0); system("cls"); gotoxy(1,6); printf("BIKENUMBER "); gotoxy(15,6); printf("NAME "); gotoxy(30,6); printf("ADDRESS "); gotoxy(45,6); printf("PHONENUMBER "); gotoxy(60,6); printf("NATIONALITY "); gotoxy(75,6); printf("EMAIL "); gotoxy(100,6); printf("PERIOD \n"); for(i=0;i<110;i++) { printf("-"); } q=9; while(fscanf(f,"%i %s %s %s %s %s %i\n", &s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, &s.period)!=EOF) { /*printf("BIKENUMBER :\t%s\n",s.bikenumber); printf("NAME:\t%s\n",,s.name); printf("ADDRESS:\t%s\n",s.address); printf("PHONENUMBER:\t%s\n",s.phonenumber); printf("NATIONALITY \n");*/ gotoxy(1,q); printf("%i",s.bikenumber); gotoxy(16,q); printf("%s",s.name); gotoxy(31,q); printf("%s",s.address); gotoxy(46,q); printf("%s",s.phonenumber); gotoxy(61,q); printf("%s",s.nationality); gotoxy(76,q); printf("%s",s.email); gotoxy(101,q); printf("%i",s.period); q++; } printf("\n"); for(i=0;i<110;i++) printf("-"); fclose(f); getch(); } void delete1() { FILE *f,*t; int i=0; int bikenumb; t=fopen("temp.txt","w"); if ((f=fopen("add.txt","r"))==NULL) { printf("NO RECORD ADDED."); main_menu(); } else { system("cls"); printf("Enter the Bike Number to be deleted from the database: "); fflush(stdin); scanf("%i",&bikenumb); while(fscanf(f,"%i %s %s %s %s %s %i\n", &s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, &s.period)!=EOF) { if(bikenumb != s.bikenumber) { fprintf(t,"%i %s %s %s %s %s %i\n", s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, s.period); } else { i=1; } } if(!i) { printf("\n\n Records of Customer in this bike number not found!!"); //remove("E:/file.txt"); //rename("E:/temp.txt","E:/file.txt"); getch(); fclose(f); fclose(t); main_menu(); } else { printf("\n\tSuccessfully deleted.\n"); } fclose(f); fclose(t); remove("add.txt"); rename("temp.txt","add.txt"); getch(); } } void search() { system("cls"); FILE *f; int bikenumber; int flag=1; f=fopen("add.txt","r+"); if(f==0) { printf("NO RECORD ADDED."); main_menu(); } else { fflush(stdin); printf("Enter bike number of the customer to search its details: \n"); scanf("%i", &bikenumber); while(fscanf(f,"%i %s %s %s %s %s %i\n", &s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, &s.period)!=EOF) { if(bikenumber==s.bikenumber) { flag=0; printf("\n\tRecord Found\n"); printf("\nBike Number\t: %i",s.bikenumber); printf("\nName\t\t: %s",s.name); printf("\nAddress\t\t: %s",s.address); printf("\nPhone number\t: %s",s.phonenumber); printf("\nNationality\t: %s",s.nationality); printf("\nEmail\t\t: %s",s.email); printf("\nPeriod\t\t: %i",s.period); break; } } if(flag==1){ printf("\n\tRequested Customer could not be found!"); } getch(); fclose(f); main_menu(); } } void edit() { FILE *f, *r; int k=0; char ed; int bikenumber; long int size=sizeof(s); if((f=fopen("add.txt","r+"))==NULL) { printf("NO RECORD ADDED."); main_menu(); } else { r = fopen("temp.txt","a"); system("cls"); printf("Enter bike number of the customer to edit:\n\n"); scanf("%i",&bikenumber); fflush(stdin); while(fscanf(f,"%i %s %s %s %s %s %i\n", &s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, &s.period)!=EOF) { if(bikenumber==s.bikenumber) { k=1; printf("\n\t*** Existing Record ***"); printf("\nBike Number\t: %i",s.bikenumber); printf("\nName\t\t: %s",s.name); printf("\nAddress\t\t: %s",s.address); printf("\nPhone number\t: %s",s.phonenumber); printf("\nNationality\t: %s",s.nationality); printf("\nEmail\t\t: %s",s.email); printf("\nPeriod\t\t: %i",s.period); printf("\n\n\t*** New Record ***"); printf("\nEnter New Name : "); fflush(stdin); scanf("%s",s.name); printf("\nEnter New Address : "); scanf("%s",s.address); printf("\nEnter New Phone number : "); scanf("%s",s.phonenumber); printf("\nEnter New Nationality : "); scanf("%s",s.nationality); printf("\nEnter New Email : "); scanf("%s",s.email); printf("\nEnter New Period : "); scanf("%i",&s.period); printf("Press 'm' to edit the existing record or any key to cancel..."); ed=getche(); if(ed=='m' || ed=='M') { fprintf(r,"%i %s %s %s %s %s %i\n", s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, s.period); fflush(stdin); printf("\n\n\t\tYOUR RECORD IS SUCCESSFULLY EDITED!!!"); } } else { fprintf(r,"%i %s %s %s %s %s %i\n", s.bikenumber, s.name, s.address, s.phonenumber, s.nationality, s.email, s.period); fflush(stdin); } } if(!k) { printf("\n\nTHE RECORD DOESN'T EXIST!!!!"); } fclose(r); fclose(f); remove("add.txt"); rename("temp.txt","add.txt"); getch(); } main_menu(); } |