Mim527

project

Aug 2nd, 2019
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 15.48 KB | None | 0 0
  1. //including header files
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4. #include<string.h>
  5.  
  6. //defining global variables
  7. int i,j,main_exit;
  8.  
  9. //declaring functions
  10. void menu();
  11. void new_entry();
  12. void edit();
  13. void view_list();
  14. void erase();
  15. void see();
  16. void sorter();
  17. void closer();
  18.  
  19. //defining structures
  20. struct date{
  21.     int month,day,year;
  22. };
  23. struct {
  24.  
  25.     char name[60];
  26.     int age;
  27.     char city[60];
  28.     char mail_id[30];
  29.     char room_no[8];
  30.     char father_name[60];
  31.     int father_phone;
  32.     int phone;
  33.     char hostel_name[6];
  34.     char roll_no[10];
  35.     struct date dob;
  36.     }add,upd,check,rem,sort;
  37.  
  38. //--------------------------------------------------------------------------------------------------------------------
  39. //main function
  40. int main()
  41. {
  42.     pass();
  43.   menu();
  44.   return 0;
  45. }
  46.  
  47.  
  48. //menu function
  49. void menu()
  50. {  
  51. system("CLS");
  52.     int choice;
  53.     printf("\n\n\t\t\tHOSTEL MANAGEMENT SYSTEM");
  54.     printf("\n\n\n\t\t\xB2\xB2\xB2\xB2\xB2\xB2\xB2 WELCOME TO THE MAIN MENU \xB2\xB2\xB2\xB2\xB2\xB2\xB2");
  55.     printf("\n\n\t\t1>> Enter new Student's data\n\t\t2>> Update information of existing account\n\t\t3>> Check the details of existing account\n\t\t4>> View all Students of a particlar Hostel\n\t\t5>> Removing existing account\n\t\t6>> View all students list\n\t\t7>> Exit\n\n\n\n\n\t\t Enter your choice:");
  56.     scanf("%d",&choice);
  57.  
  58.     switch(choice)
  59.     {
  60.  
  61.         case 1:new_entry();
  62.         break;
  63.         case 2:edit();
  64.         break;
  65.         case 3:see();
  66.         break;
  67.         case 4:sorter();
  68.         break;
  69.         case 5:erase();
  70.         break;
  71.         case 6:view_list();
  72.         break;
  73.         case 7:closer();
  74.         break;
  75.         default:menu();
  76.     }
  77. }
  78.  
  79. //------------------------------------------------------------------------------------------------------------------
  80. //function to display all students of a hostel
  81. void sorter()
  82. {
  83.     system("CLS");
  84.     int choice,test=0;
  85.    
  86.     printf("Enter year choice:\n\n\t\t1. BH-1 \n\t\t2. BH-2 \n\t\t3. BH-3 \n\t\t4. GH-1 \n\n");
  87.     scanf("%d",&choice);
  88.    
  89.     FILE *fp, *hostel;
  90.     switch(choice)
  91.     {
  92.         case 1: hostel=fopen("BH-1.dat","a+");break;
  93.         case 2: hostel=fopen("BH-2.dat","a+");break;
  94.         case 3: hostel=fopen("BH-3.dat","a+");break;
  95.         case 4: hostel=fopen("GH-1.dat","a+");break;
  96.         default: sorter();
  97.     }
  98.     while(fscanf(hostel,"%s\n",check.roll_no)!=EOF)
  99.     {
  100.         fp=fopen("record.dat","r");
  101.         while(fscanf(fp,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",sort.roll_no, sort.name, &sort.dob.month, &sort.dob.day, &sort.dob.year, &sort.age, sort.city, &sort.phone, sort.mail_id, sort.father_name, &sort.father_phone, sort.room_no, sort.hostel_name)!=EOF)
  102.         {
  103.             if(strcmp(check.roll_no,sort.roll_no)==0)
  104.             {
  105.                 if(test==0)
  106.                 {
  107.                     printf("\t\tFollowing is the list of requested students:");
  108.                     printf("\n\tROLL NO.\tNAME\tROOM NO.\n");
  109.                 }
  110.                 printf("\n\t%8s\t %8s\t %s", sort.roll_no, sort.room_no, sort.name);
  111.                 test++;
  112.             }
  113.         }
  114.     }
  115.    
  116.     fclose(fp);
  117.     if (test==0)
  118.         printf("\nNO RECORDS!!\n");
  119.    
  120.     sort_list_invalid:
  121.     printf("\n\nEnter 1 to go to the main menu and 0 to exit:");
  122.     scanf("%d",&main_exit);
  123.    
  124.     if (main_exit==1)
  125.         menu();
  126.     else if(main_exit==0)
  127.         closer();
  128.     else
  129.     {
  130.         printf("\nInvalid!\a");
  131.         goto sort_list_invalid;
  132.     }
  133.    
  134. }
  135.  
  136. //------------------------------------------------------------------------------------------------------------------
  137. //new entry function
  138. void new_entry()
  139. {
  140.     system("CLS");
  141.     int choice;
  142.     FILE *ptr,*hostel;
  143.  
  144.     ptr=fopen("record.dat","a+");
  145.     roll_no:
  146.    
  147.     printf("\t\t\t\xB2\xB2\xB2 ADD STUDENTS DATA  \xB2\xB2\xB2\xB2");
  148.     printf("\nEnter your roll number:");
  149.     scanf("%s",check.roll_no);
  150.     while(fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
  151.     {
  152.         if (strcmp(check.roll_no,add.roll_no)==0)
  153.             {printf("Students roll no. already in use!");
  154.              goto roll_no;
  155.         }
  156.     }
  157.  
  158.     strcpy(add.roll_no,check.roll_no);
  159.     printf("\nEnter the name:");
  160.     scanf("%s",add.name);
  161.     printf("\nEnter the date of birth(mm/dd/yyyy):");
  162.     scanf("%d/%d/%d",&add.dob.month,&add.dob.day,&add.dob.year);
  163.     printf("\nEnter the age:");
  164.     scanf("%d",&add.age);
  165.     printf("\nEnter the city:");
  166.     scanf("%s",add.city);
  167.     printf("\nEnter the phone number: ");
  168.     scanf("%d",&add.phone);
  169.     printf("\n Enter your email id :");
  170.     scanf("%s",add.mail_id);
  171.     printf("\n Enter your Father's name:");
  172.     scanf("%s",add.father_name);
  173.     printf("\n Enter your Father's phone no.:");
  174.     scanf("%d",&add.father_phone);
  175.     printf("\n Enter your room no.:");
  176.     scanf("%s",add.room_no);
  177.     printf("\n Enter your hostel name from BH-1, BH-2, BH-3, GH-1 :");
  178.     scanf("%s",add.hostel_name);
  179.         fprintf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
  180.    
  181.         //adding student roll no. to hostels' list
  182.     if(strcmp(add.hostel_name,"BH-1")==0)
  183.     {
  184.         hostel=fopen("BH-1.dat","a+");
  185.         fprintf(hostel, "%s\n", add.roll_no);
  186.         fclose(hostel);    
  187.     }
  188.     else if(strcmp(add.hostel_name,"BH-2")==0)
  189.     {
  190.         hostel=fopen("BH-2.dat","a+");
  191.         fprintf(hostel, "%s\n", add.roll_no);
  192.         fclose(hostel);    
  193.     }
  194.     else if(strcmp(add.hostel_name,"BH-3")==0)
  195.     {
  196.         hostel=fopen("BH-3.dat","a+");
  197.         fprintf(hostel, "%s\n", add.roll_no);
  198.         fclose(hostel);    
  199.     }
  200.     else if(strcmp(add.hostel_name,"GH-1")==0)
  201.     {
  202.         hostel=fopen("GH-1.dat","a+");
  203.         fprintf(hostel, "%s\n", add.roll_no);
  204.         fclose(hostel);    
  205.     }
  206.         //----------------------------------------
  207.    
  208.     fclose(ptr);
  209.     printf("\nStudent added successfully!");
  210.     add_invalid:
  211.     printf("\n\n\n\t\tEnter 1 to go to the main menu and 0 to exit:");
  212.     scanf("%d",&main_exit);
  213.    
  214.     if (main_exit==1)
  215.    
  216.         menu();
  217.     else if(main_exit==0)
  218.             closer();
  219.     else
  220.         {
  221.             printf("\nInvalid!\a");
  222.             goto add_invalid;
  223.         }
  224. }
  225.  
  226. //------------------------------------------------------------------------------------------------------------------
  227. //nsbfunction to view all students
  228. void view_list()
  229. {
  230.     system("CLS");
  231.     FILE *view;
  232.     view=fopen("record.dat","r");
  233.     int test=0;
  234.    
  235.     printf("\nROLL NO.\tNAME\t\t\tcity\t\t\tPHONE\n");
  236.  
  237.     while(fscanf(view,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
  238.        {
  239.            printf("\n%8s\t %10s\t\t\t %10s\t\t %d",add.roll_no,add.name,add.city,add.phone);
  240.            test++;
  241.        }
  242.     fclose(view);
  243.    
  244.     if (test==0)
  245.         {  
  246.             printf("\nNO RECORDS!!\n");}
  247.  
  248.     view_list_invalid:
  249.      printf("\n\nEnter 1 to go to the main menu and 0 to exit:");
  250.         scanf("%d",&main_exit);
  251.        
  252.         if (main_exit==1)
  253.             menu();
  254.         else if(main_exit==0)
  255.             closer();
  256.         else
  257.         {
  258.             printf("\nInvalid!\a");
  259.             goto view_list_invalid;
  260.         }
  261. }
  262.  
  263. //------------------------------------------------------------------------------------------------------------------
  264. //function to view all data of 1 student
  265. void see()
  266. {
  267.     system("CLS");
  268.     FILE *ptr;
  269.     int test=0;
  270.     int choice;
  271.     ptr=fopen("record.dat","r");
  272.     printf("Do you want to check by\n1.Roll no\n2.Name\nEnter your choice:");
  273.     scanf("%d",&choice);
  274.     if (choice==1)
  275.     {   printf("\n\nEnter the roll number:");
  276.         scanf("%s",check.roll_no);
  277.  
  278.         while (fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
  279.         {
  280.             if(strcmp(add.roll_no,check.roll_no)==0)
  281.             {  
  282.                 test=1;
  283.  
  284.                 printf("\nROLL NO.:%s\nName:%s \nDOB:%d/%d/%d \nAge:%d \ncity:%s \nPhone number:%d \nE-Mail id:%s \nFather's name:%s \n Father's Phone No.:%d \nRoom No:%s \nHostel:%s \n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
  285.             }
  286.         }
  287.     }
  288.     else if (choice==2)
  289.     {   printf("\n\nEnter the name:");
  290.         scanf("%s",check.name);
  291.         while (fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
  292.         {
  293.             if(strcmp(add.name,check.name)==0)
  294.             {  
  295.                 test=1;
  296.                 printf("\nROLL NO.:%s\nName:%s \nDOB:%d/%d/%d \nAge:%d \ncity:%s \nPhone number:%d \nE-Mail id:%s \nFather's name:%s \n Father's Phone No.:%d \nRoom No:%s \nHostel:%s \n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
  297.             }
  298.         }
  299.     }
  300.  
  301.     fclose(ptr);
  302.      if(test!=1)
  303.         printf("\nRecord not found!!\a\a\a");
  304.     see_invalid:
  305.         printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
  306.         scanf("%d",&main_exit);
  307.         if (main_exit==1)
  308.             menu();
  309.         else if (main_exit==2)
  310.             closer();
  311.         else if(main_exit==0)
  312.             erase();
  313.         else
  314.         {  
  315.             printf("\nInvalid!\a");
  316.             goto see_invalid;
  317.         }
  318. }
  319.  
  320. //------------------------------------------------------------------------------------------------------------------
  321. //function to update student info
  322. void edit()
  323. {
  324.     system("CLS");
  325.     int choice,test=0;
  326.     FILE *old,*newrec;
  327.     old=fopen("record.dat","r");
  328.     newrec=fopen("new.dat","w");
  329.  
  330.     printf("\nEnter the roll no. of the student whose info you want to change:");
  331.     scanf("%s",upd.roll_no);
  332.     while(fscanf(old,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
  333.  
  334.     {
  335.         if (strcmp(add.roll_no,upd.roll_no)==0)
  336.         {   test=1;
  337.             printf("\nWhich information do you want to change?\n1.Room no.\n2.Phone\n\nEnter your choice(1 for room no. and 2 for phone ):");
  338.             scanf("%d",&choice);
  339.            
  340.             if(choice==1)
  341.                 {printf("Enter the new room no.:");
  342.                 scanf("%s",upd.room_no);
  343.                 fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, upd.room_no, add.hostel_name);
  344.                 printf("Changes saved!");
  345.                 }
  346.             else if(choice==2)
  347.                 {
  348.                     printf("Enter the new phone number:");
  349.                 scanf("%d",&upd.phone);
  350.                 fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, upd.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
  351.                 printf("Changes saved!");
  352.                 }
  353.  
  354.         }
  355.         else
  356.             fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
  357.     }
  358.     fclose(old);
  359.     fclose(newrec);
  360.     remove("record.dat");
  361.     rename("new.dat","record.dat");
  362.  
  363.     if(test!=1)
  364.         printf("\nRecord not found!!\a\a\a");
  365.    
  366.     edit_invalid:
  367.         printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
  368.         scanf("%d",&main_exit);  
  369.         if (main_exit==1)
  370.             menu();
  371.         else if (main_exit==2)
  372.             closer();
  373.         else if(main_exit==0)
  374.             edit();
  375.         else
  376.         {
  377.             printf("\nInvalid!\a");
  378.             goto edit_invalid;
  379.         }
  380.        
  381. }
  382.  
  383. //------------------------------------------------------------------------------------------------------------------
  384. //cpfunction to delete records
  385. void erase()
  386. {
  387.     system("CLS");
  388.     FILE *old,*newrec;
  389.     int test=0;
  390.     old=fopen("record.dat","r");
  391.     newrec=fopen("new.dat","w");
  392.     printf("Enter the roll np. of student whose data you want to delete:");
  393.     scanf("%s",rem.roll_no);
  394.     while (fscanf(old,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, &add.dob.month, &add.dob.day, &add.dob.year, &add.age, add.city, &add.phone, add.mail_id, add.father_name, &add.father_phone, add.room_no, add.hostel_name)!=EOF)
  395.    {
  396.         if(add.roll_no!=rem.roll_no)
  397.             fprintf(newrec,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.roll_no, add.name, add.dob.month, add.dob.day, add.dob.year, add.age, add.city, add.phone, add.mail_id, add.father_name, add.father_phone, add.room_no, add.hostel_name);
  398.  
  399.         else
  400.             {test++;
  401.             printf("\nRecord deleted successfully!\n");
  402.             }
  403.     }
  404.     fclose(old);
  405.     fclose(newrec);
  406.     remove("record.dat");
  407.     rename("new.dat","record.dat");
  408.     if(test==0)
  409.         printf("\nRecord not found!!\a\a\a");
  410.     erase_invalid:
  411.         printf("\nEnter 0 to try again,1 to return to main menu and 2 to exit:");
  412.         scanf("%d",&main_exit);
  413.         if (main_exit==1)
  414.             menu();
  415.         else if (main_exit==2)
  416.             closer();
  417.         else if(main_exit==0)
  418.             erase();
  419.         else
  420.         {  
  421.             printf("\nInvalid!\a");
  422.             goto erase_invalid;
  423.         }
  424. }
  425.  
  426. //------------------------------------------------------------------------------------------------------------------
  427. //function displaying developer credits 1353functioncalls
  428. void closer()
  429. {
  430.     system("CLS");
  431.     printf("\n\n\n\nBrought To You by Code-Projects.org\n\n\n");
  432. }
  433.  
  434. int pass(void)
  435. {
  436.    int a=0,i=0;
  437.     char uname[10],c=' ';
  438.     char pword[10],code[10];
  439.     char user[10]="user";
  440.     char pass[10]="pass";
  441.     do
  442. {
  443.     system("cls");
  444.    
  445.     printf("\n  **************************  LOGIN FORM  **************************  ");
  446.     printf(" \n                       ENTER USERNAME:-");
  447.     scanf("%s", &uname);
  448.     printf(" \n                       ENTER PASSWORD:-");
  449.     while(i<10)
  450.     {
  451.         pword[i]=getch();
  452.         c=pword[i];
  453.         if(c==13) break;
  454.         else printf("*");
  455.         i++;
  456.     }
  457.     pword[i]='\0';
  458.     //char code=pword;
  459.     i=0;
  460.     //scanf("%s",&pword);
  461.         if(strcmp(uname,user)==0 && strcmp(pword,pass)==0)
  462.     {
  463.     printf("  \n\n\n       WELCOME !!!! LOGIN IS SUCCESSFUL\n");
  464.     system("PAUSE");
  465.     break;
  466.     }
  467.     else
  468.     {
  469.         printf("\n        SORRY !!!!  LOGIN IS UNSUCESSFUL\n");
  470.         system("PAUSE");
  471.         a++;
  472.        
  473.         getch();
  474.        
  475.     }
  476. }
  477.     while(a<=2);
  478.     if (a>2)
  479.     {
  480.         printf("\nSorry you have entered the wrong username and password for four times!!!");
  481.        
  482.         getch();
  483.        
  484.         }
  485.         system("cls"); 
  486. }
Advertisement
Add Comment
Please, Sign In to add comment