Student Dormitory Information Enquiry

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;/* Dormitory number */
Char name[20];/* name */
Char sex[5];/* sex */
int age;/* Age */
Char studentclass[20];/* class */
int score;/* Score */
}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 \ nthe entry of the dorm information (max.%d) \ n", MAX);
printf ("----------------------------\ n");

printf ("\ n%d Hostels", k+1);
printf ("\ n Please enter dorm number:");
scanf ("%d", &stu[k].num);
printf ("\ n Please enter the president's name:");
scanf ("%s", stu[k].name);
printf ("\ n Please enter the number of people:");
scanf ("%s", stu[k].sex);
printf ("\ n Please enter class guide:");
scanf ("%d", &stu[k].age);
printf ("\ n Please enter class:");
scanf ("%s", Stu[k].studentclass);
printf ("\ n please lose dorm results:");
scanf ("%d", stu[k].studentclass);
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 dorm number:");
   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 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, President's name:%s, number of people:%s, Class:%d, class £ º%s, dorm score:%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 you are looking for");
    scanf ("%d", &num);
    for (i=0;i<k;i++)
      if (num==stu[i].num)
          printf ("\n\n\n:%d, President name:%s, Number:%s, class Guide:%d, class:%s, Dorm score:%d\n", Stu[i].num,stu [I].name,
   stu[i].sex,stu[i].age,stu[i].studentclass,stu[i].score);
    printf ("Press any key plus enter to 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 information you want to modify");
scanf ("%d", &num);
for (i=0;i<k;i++)
{if (num==stu[i].num)
printf ("\ n Dorm Number:%d, President's name:%s, number of people:%s, Class:%d, class,%s, dorm score:%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. The president's name \ n ");
printf ("3. The number of people \ n ");
printf ("4. Ban \ n ");
printf ("5. Class \ n ");
printf ("6. Dormitory 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 dorm length you changed");
scanf ("%s", stu[i].name);
Break
}
Case 3:{
printf ("\ n Please enter the number of quarters you have changed");
scanf ("%s", stu[i].sex);
Break
}
Case 4:{
printf ("\ n Please enter the class guide 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 dorm results");
scanf ("%d", &stu[i].score);
Break
}
}

printf ("Dorm number:%d, Name:%s, Gender:%s, Age:%d, class:%s, Score:%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 Student Dormitory information 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 ******** Student Information Management System ********\n\n");
printf ("1. Create dormitory information \ n ");
printf ("2. Print dormitory information \ n ");
printf ("3. Check the dormitory information \ n ");
printf ("4. Revise the dormitory information \ n ");
printf ("5. Delete Dormitory information \ n ");
printf ("6. Dormitory grade information rank \ 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 ();

}


Student Dormitory Information Enquiry

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.