This document provides source codes and explanations for a Hostel Management System program. It includes functions for adding student entries, checking room availability based on gender, calculating total payment, checking student details, and managing payment options.
Contribute Materials
Your contribution can guide someone’s learning journey. Share your
documents today.
Running Head: HOSTEL MANAGEMENT SYSTEM HOSTEL MANAGEMENT SYSTEM Name of the Student: Name of the University: Author Note:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
1HOSTEL MANAGEMENT SYSTEM Table of Contents Source Codes...................................................................................................................................2 Add student entry.........................................................................................................................2 Check availability of rooms according to gender........................................................................9 Total payment to be made..........................................................................................................13 Check Student details................................................................................................................15 Payment options and to cancel the payment in mid-way..........................................................19
2HOSTEL MANAGEMENT SYSTEM Source Codes Add student entry This function is used to add student records to the data file or .dat file that is used in the program. There are structures made to take input from the user for the date and one for the student details. The name of the function is new_entry(), the variables that are used is an integer variable named as choice. FILE defines the two file pointers as *ptr and *hostel. Source Code to Add student entry: int new_entry() { int choice; FILE *ptr,*hostel; ptr=fopen("student_record.dat","a+"); printf("\t\t\t\******* ADD STUDENTS DATA *******\n"); printf("\nEnter student Id:"); scanf("%s",check.student_id); while(fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s\n",add.student_id, 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.hostel_name)!=EOF)
3HOSTEL MANAGEMENT SYSTEM { if (strcmp(check.student_id,add.student_id)==0) {printf("Students Id already in use!"); goto student_id; } } strcpy(add.student_id,check.student_id); printf("\nEnter the name:"); scanf("%s",add.name); printf("\nEnter the date of birth(mm/dd/yyyy):"); scanf("%d/%d/%d",&add.dob.month,&add.dob.day,&add.dob.year); printf("\nEnter the age:"); scanf("%d",&add.age); printf("\nEnter the city:"); scanf("%s",add.city); printf("\nEnter the phone number: "); scanf("%d",&add.phone);
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
4HOSTEL MANAGEMENT SYSTEM printf("\n Enter your email id :"); scanf("%s",add.mail_id); printf("\n Enter your Father's name:"); scanf("%s",add.father_name); printf("\n Enter your Father's phone no.:"); scanf("%d",&add.father_phone); printf("\n Enter your hostel name from A3, B1, B3, B4 :"); scanf("%s",add.hostel_name); fprintf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s %s\n",add.student_id, 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.hostel_name); //adding student Ids to hostels' list if(strcmp(add.hostel_name,"A3")==0) { hostel=fopen("A3.dat","a+"); fprintf(hostel, "%s\n", add.student_id); fclose(hostel); }
6HOSTEL MANAGEMENT SYSTEM fclose(ptr); printf("\nStudent added successfully!\n\n"); } int gender() { char ch; printf("Enter gender (M/m or F/f): "); scanf("%c",&ch); switch(ch) { case 'M': case 'm':{ printf("Available blocks are A3.\n"); printf("Number of available rooms are: 100\n"); break;
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
7HOSTEL MANAGEMENT SYSTEM } case 'F': case 'f':{ char choice[2]; printf("Available blocks are B1, B3, B4.\n"); printf("Number of available rooms in B1: 100\n"); printf("Number of available rooms in B3: 100\n"); printf("Number of available rooms in B4: 100\n"); printf("Please choose your block:"); scanf("%s",choice); if(choice[0]=='B' && choice[1]=='1') printf("The rates are: Room=400, Meal=120, GYM=10"); else if(choice[0]=='B' && choice[1]=='3') printf("The rates are: Room=150, Meal=120, GYM=10");
9HOSTEL MANAGEMENT SYSTEM Previews: Fig 1.Add Entry to the list Check availability of rooms according to gender The name of this function is gender(), and this function is used to input the gender of the student and displays the available room options for the student. The character variable ch is used to take the input of the gender as M/m for male and F/f for female. After that the function moves into the switch case according to the option chosen. Source Code to Check availability of rooms according to gender: int gender() {
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser
10HOSTEL MANAGEMENT SYSTEM char ch; printf("Enter gender (M/m or F/f): "); scanf("%c",&ch); switch(ch) { case 'M': case 'm':{ printf("Available blocks are A3.\n"); printf("Number of available rooms are: 100\n"); break; } case 'F': case 'f':{ char choice[2]; printf("Available blocks are B1, B3, B4.\n"); printf("Number of available rooms in B1: 100\n");
11HOSTEL MANAGEMENT SYSTEM printf("Number of available rooms in B3: 100\n"); printf("Number of available rooms in B4: 100\n"); printf("Please choose your block:"); scanf("%s",choice); if(choice[0]=='B' && choice[1]=='1') printf("The rates are: Room=400, Meal=120, GYM=10"); else if(choice[0]=='B' && choice[1]=='3') printf("The rates are: Room=150, Meal=120, GYM=10"); else if(choice[0]=='B' && choice[1]=='4') printf("The rates are: Room=100, Meal=120, GYM=10"); else printf("invalid choice"); break;
12HOSTEL MANAGEMENT SYSTEM } } printf("\n"); } Preview:
Secure Best Marks with AI Grader
Need help grading? Try our AI Grader for instant feedback on your assignments.
13HOSTEL MANAGEMENT SYSTEM Fig 2 & 3. Check availability of rooms according to gender Total payment to be made The name of the function is bill(). This function is used to check the total bill based on the user input. The variables used in this function are tot_week_pay_A3=280, tot_week_pay_B1=530, tot_week_pay_B3=280, tot_week_pay_B4=230, which are integer type and stores the total weekly payment for each block and block variable is a character type variable used to take the input of the block the student will be staying in. Another variable named as stay is an integer variable and is used to take input from the user for how many weeks they want to stay. Source Code to check the total payment to be made: int bill(){
14HOSTEL MANAGEMENT SYSTEM int tot_week_pay_A3=280; int tot_week_pay_B1=530; int tot_week_pay_B3=280; int tot_week_pay_B4=230; char block[2]; int stay; printf("Enter how many weeks you want to stay:\n"); scanf("%d",&stay); printf("Enter your block:\n"); scanf("%s",block); if(block[0]=='A' && block[1]=='3') printf("Total payment:%d",tot_week_pay_A3*stay); else if(block[0]=='B' && block[1]=='1') printf("Total payment:%d",tot_week_pay_B1*stay);
16HOSTEL MANAGEMENT SYSTEM Fig 4. Total payment to be made by the student Check Student details This function is used to check the student details which are already present in the data file and the name of this function is see(). A file pointer is used to point to the first data in the file and the checking process begins after the user inputs the student id or roll number or the name to check the details. Source Code to check student details: int see() {
17HOSTEL MANAGEMENT SYSTEM FILE *ptr; int test=0; int choice; ptr=fopen("student_record.dat","r"); printf("Do you want to check by\n1.Roll no\n2.Name\nEnter your choice:"); scanf("%d",&choice); if (choice==1) {printf("\n\nEnter the roll number:"); scanf("%s",check.student_id); while (fscanf(ptr,"%s %s %d/%d/%d %d %s %d %s %s %d %s\n",add.student_id, 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.hostel_name)!=EOF) { if(strcmp(add.student_id,check.student_id)==0) { test=1;
19HOSTEL MANAGEMENT SYSTEM n",add.student_id,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.hostel_name); } } } fclose(ptr); if(test!=1) printf("\nRecord not found!!\a\a\a"); } Preview:
20HOSTEL MANAGEMENT SYSTEM Fig 5. Check student details Payment options and to cancel the payment in mid-way This function is used to show the payment options available and to abort the payment in the midway. The name of this function is payment_facility(). The variables used in this function are num and choice1 both are integer type. Source Code for payment options and to cancel the payment in mid-way: int payment_facility() { int num; int choice1;
21HOSTEL MANAGEMENT SYSTEM printf("Choose 1 for card.\n Choose 2 for cash.\n Choose 3 to abort the payment process.\ n"); printf("Enter your choice:\n"); scanf("%d",&choice1); switch(choice1) { case 1: printf("\nEnter the card number to proceed:\n"); scanf("%d",&num); break; case 2: printf("\nYour choice was recorded. Please visit the office to pay the due bill.\n Thank you!\n"); break; case 3: printf("\nThe payment was aborted.\n"); break; default:
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser