Dormitory Management System

Source: Internet
Author: User

#include "stdio.h"
#include "Stdlib.h"
#include "string.h"
#include "conio.h"
#define PAGE 3
#define MAX 1000
#define N 5
int k=0;
/* struct type */
typedef struct
{int num;/* room number */
Char name[20];/* name */
Char sex[5];/* sex */
int age;/* Age */
Char studentclass[20];/* class */
int score;/* Rating */
}students;

int Read_file (STUDENTS stu[])
{FILE *FP;
int i=0;
if ((Fp=fopen ("Stu.txt", "RT")) ==null)
{printf ("\n\n***** inventory file does not exist! Please create ");
return 0;
}
while (feof (FP)!=1)
{
Fread (&stu[i],sizeof (STUDENTS), 1,FP);
if (stu[i].num==0)
Break
Else
i++;
}
Fclose (FP);
return i;
}
void Save_file (STUDENTS stu[],int sum)
{FILE*FP;
int i;
if ((Fp=fopen ("Stu.txt", "WB")) ==null)
{printf ("Write file Error!\n");
Return
}
for (i=0;i<sum;i++)
if (Fwrite (&stu[i],sizeof (STUDENTS), 1,FP)!=1)
printf ("Write file Error!\n");
Fclose (FP);
}


/* Create student information */
int input (STUDENTS stu[])
{int i,x;
for (i=0;i<1000;i++)
{
System ("CLS");
printf ("\ n \ nyou Enter dorm information (up to%d) \ n", MAX);
printf ("----------------------------\ n");

printf ("\ n%d students", k+1);
printf ("\ n Please enter the student's dorm number:");
scanf ("%d", &stu[k].num);
printf ("\ n Please enter the student's name:");
scanf ("%s", stu[k].name);
printf ("\ n Please enter the student's gender:");
scanf ("%s", stu[k].sex);
printf ("\ n Please enter the student's Age:");
scanf ("%d", &stu[k].age);
printf ("\ n Please enter student's class:");
scanf ("%s", Stu[k].studentclass);
printf ("\ n Please enter the student's dorm rating score:");
scanf ("%d", &stu[k++].score);
printf ("\ n Press the 1 key to return to the menu or press 0 to continue creating");
scanf ("%d", &x);
if (x)
break;
}

return k;
}


/* Delete Student information */
void Deletel (STUDENTS stu[])
{System ("CLS");
Char stuname2[20];
int i,j;
printf ("Please enter student's name:");
scanf ("%s", Stuname2);
printf ("\ n");
for (i=0;i<k;i++)
if (strcmp (stu[i].name,stuname2) ==0)
for (j=0;j<20;j++)
STU[I].NAME[J]=STU[I+1].NAME[J];
k--;


printf ("Delete succeeded \ n");
printf ("Press any key and return to the main menu!");
scanf ("%d", &i);
GetChar ();
}

/* Print Student information */
void output (STUDENTS stu[])
{System ("CLS");
int i;
for (i=0;i<k;i++)
printf ("Dorm number:%d, Name:%s, Gender:%s, Age:%d, class:%s, Rating:%d\n", Stu[i].num,stu[i].name,
Stu[i].sex,stu[i].age,stu[i].studentclass,stu[i].score);
printf ("Press any key and return to the main menu!");
scanf ("%d", &i);
GetChar ();
}

/* Query Student information */
void inquire (STUDENTS stu[])
{int i;
int num;
System ("CLS");
printf ("\ n Please enter the dorm number of the student you are looking for");
scanf ("%d", &num);
for (i=0;i<k;i++)
if (num==stu[i].num)
printf ("\n\n\n Dorm number:%d, Name:%s, Gender:%s, Age:%d, class:%s, Rating:%d\n", Stu[i].num,stu[i].name,
Stu[i].sex,stu[i].age,stu[i].studentclass,stu[i].score);
printf ("Press any key and return to the main menu!");
scanf ("%d", &i);
GetChar ();
}


/* Modify Student Information */
void change (STUDENTS stu[])
{int num,i,choice;
System ("CLS");
printf ("\n\n\n Please enter the dorm number of the student you wish to modify");
scanf ("%d", &num);
for (i=0;i<k;i++)
{if (num==stu[i].num)
printf ("\ n Dorm number:%d, Name:%s, Gender:%s, Age:%d, class:%s, Rating:%d\n", Stu[i].num,stu[i].name,
Stu[i].sex,stu[i].age,stu[i].studentclass,stu[i].score);

printf ("\n\n\n ******** Please enter the data you want to modify ********\n\n");
printf ("1. Dormitory no. \ n ");
printf ("2. Name \ n ");
printf ("3. Gender \ n ");
printf ("4. Age \ n ");
printf ("5. Class \ n ");
printf ("6. Rating results \ n \ ");
printf ("Please select (1-6):");
scanf ("%d", &choice);
Switch (choice)
{Case 1:{
printf ("\ n Please enter the new dorm number you changed");
scanf ("%d", &stu[i].num);
Break
}
Case 2:{
printf ("\ n Please enter the new name you Changed");
scanf ("%s", stu[i].name);
Break
}
Case 3:{
printf ("\ n Please enter your new gender");
scanf ("%s", stu[i].sex);
Break
}
Case 4:{
printf ("\ n Please enter the New Age you Changed");
scanf ("%d", &stu[i].age);
Break
}
Case 5:{
printf ("\ n Please enter the new class you Changed");
scanf ("%s", Stu[i].studentclass);
Break
}
Case 6:{
printf ("\ n Please enter your new rating");
scanf ("%d", &stu[i].score);
Break
}
}

printf ("Dorm number:%d, Name:%s, Gender:%s, Age:%d, class:%s, Rating:%d\n", Stu[i].num,stu[i].name,
Stu[i].sex,stu[i].age,stu[i].studentclass,stu[i].score);
printf ("Press any key and return to the main menu!");
scanf ("%d", &i);
Break
}
}


/* Ranking of student achievement information */
void sort (STUDENTS stu[])
{int i,j,n=1,x;
System ("CLS");
int t;
for (i=0;i<k-1;i++)
for (j=i+1;j<k;j++)
if (Stu[i].score<stu[j].score)
{T=stu[i].score;
Stu[i].score=stu[j].score;
stu[j].score=t;
T=stu[i].num;
Stu[i].num=stu[j].num;
stu[j].num=t;

}
for (i=0;i<k;i++)
printf ("Ranked dormitory number \%d%d%d\n", n++,stu[i].num,stu[i].score);
printf ("Press any key and return to the main menu!");
scanf ("%d", &x);
GetChar ();
}

void Pagedis ()
{
printf ("\n\n\n **********************************\n");
printf ("* *\n");
printf ("* *\n");
printf ("* *\n");
printf ("* Welcome to the Dormitory management system *\n");
printf ("* *\n");
printf ("* *\n");
printf ("* *\n");
printf ("**********************************\n");

}
void Check ()
{
Char username[5];/* user name */
Char userpwd[5];/* password */
int i,sum;
System ("Color 4E");
for (i = 1; i < 4; i++)
{
/* User name and password are abcde;*/
printf ("User name and password are abcde\n\n");
printf ("\ n Please enter your user name:");
Gets (UserName);

printf ("\ n Please enter your password:");
Gets (USERPWD);

if ((strcmp (UserName, "ABCDE") ==0) && (strcmp (userpwd, "ABCDE") */* Verify username and password */
{
printf ("User name and password correct, show main Menu");
Return
}
Else
{
if (I < 3)
{
printf ("User name or password error, prompt user to re-enter");
printf ("Username or password is wrong, please re-enter!");
}
Else
{
printf ("3 consecutive incorrect user names or passwords, exit the system.") ");
printf ("You've lost your username or password 3 consecutive times, the system will exit!");
Exit (1);
}
}
}
}
void menu ()
{
STUDENTS STU[20];
int choice,k,sum;
Sum=read_file (Stu);
if (sum==0)
{printf ("First enter basic inventory information! Press ENTER after entering *****\n ");
Getch ();
Sum=input (Stu);
}

Do
{System ("CLS");
printf ("\n\n\n ******** Dormitory Management system ********\n\n");
printf ("1. Create student information \ n ");
printf ("2. Print student information \ n ");
printf ("3. Query student information \ n ");
printf ("4. Modification of student information \ n ");
printf ("5. Delete Student information \ n ");
printf ("6. Student grade information ranking \ n ");
printf ("0. Exit system \ n ");
printf ("Please select (0-6):");
scanf ("%d", &choice);
Switch (choice)
{
Case 1:k=input (STU); break;/* Creating Student Information * *
Case 2:output (STU); break;/* Print Student Information * *
Case 3:inquire (STU); break;/* Query Student Information * *
Case 4:change (STU); break;/* Modify Student Information * *
Case 5:deletel (STU); break;/* Delete Student Information * *
Case 6:sort (STU); break;/* Ranking of student achievement information */
Case 0:break;
}
}while (choice!=0);
Save_file (stu,sum);
}
int main ()
{


int i,sum;
Pagedis ();
Check ();
menu ();

}

Dormitory Management System

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.