Student Information Management System

Source: Internet
Author: User
Tags fread strcmp

The variable of the number of data in the program is always the same, always the initial value 0,count++ does not play a role, because the variable representing the number of bars is always 0, resulting in the output function in the output data is not output.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#define ESC 0x1b; The ASCII code for ESC is 0x1b.
#define N 100
Char choice= ' y ';
int count=0;
int i=0;
struct student
{
int ID;
Char name[20];
Double score1;
Double Score2;
Double score3;
Double average;
}stud[n+1],s[n];
void Printstar ()
{
for (i=0;i<80;i++)
{
printf ("*");
}
printf ("n");
}
void Time ()
{
for (i=0;i<3.3e08;i++);
}

Void Login ()//user login
{
 char name[15],pwd[15],c;
 printf ("/n/n/t/t/t/t user landing/n/n");
 printf ("/t/t username:");
 gets (name);
 printf ("/n/t/t password:");
 c = Getch (); 
 while (c!= '/R ')
  {
  if (i >= 0)
    {
   if (c = = '/b ')
    {
    printf ("/b/b" );
    i = i-1;
    }
   else
    {
    printf ("*");
    pwd[i] = c;
    }  
   }
  c = Getch ();
  if (c!= '/b ')
   i = i + 1;
&NBSP;&NBSP}
 pwd[i] = '/0 ';
 if ((strcmp (name, little Boy) ==0) && (strcmp (pwd, "123456") ==0))
  printf ("/n/n login succeeded.") /n ");
 else
  printf ("/n/n Login failed. /n ");
}


void input ()//input data
{
FILE * FP;
if ((Fp=fopen ("Stu.dat", "RB")) ==null)
{
Fp=fopen ("Stu.dat", "w");
}
Else
{
Fp=fopen ("Stu.dat", "AB");
}
System ("CLS");
Todo
{
printf ("/n/t/t/t/t Student Information input/n");
Printstar ();
printf ("N/a school Number:");
scanf ("%d", &stud[i].id);
printf ("/N Name:");
scanf ("%s", stud[i].name);
printf ("N/A three class results are:");
scanf ("%lf%lf%lf", &stud[i].score1,&stud[i].score2,&stud[i].score3);
Stud[i].average= (Stud[i].score1+stud[i].score2+stud[i].score3)/3;
printf ("N/a average score:%3.1lf/n", stud[i].average);
Fwrite (&stud[i],sizeof (struct student), 1,FP);
count++;
Fflush (stdin);
printf ("Whether to continue typing (y/n)");
scanf ("%c", &choice);
System ("CLS");
if (choice!= ' y ' &&choice!= ' n ')
{
Printstar ();
printf ("/n/t you have entered an illegal character, please re-enter it.") /n/n ");
Printstar ();
Time ();
}
printf ("n");
}while (choice== ' y ');
Fclose (FP);
}

void browse ()//Browse
{
System ("CLS");
FILE * FP;
Fp=fopen ("Stu.dat", "RB");
printf ("/n/t/t/t/t Student information Browsing/n/n");
Printstar ();
for (i=0;i<count;i++)
{
Fread (&stud[i],sizeof (struct student), 1,FP);
printf ("T-learning number 1 score 2 accomplishment 3 GPA/n");
printf ("/t%d%s%4.1lf%4.1lf%4.1lf%4.1lf/n", Stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].scor E3,stud[i].average);
}
}

void Byid ()  //By school number query
{
 int ch_id;
 file * FP;
 fp=fopen ("Stu.dat", "RB");
 system ("CLS");
 printf ("/n/n/t/t input number:");
 scanf ("%d", &ch_id);
 if (ch_id==stud[i].id)
 {
  fread (&stud[i],sizeof (struct student), 1,FP);
  printf ("t-learning number   SCORE 1 score 2 accomplishment 3 average score/n");
  printf ("/t%d  %s    %4.1lf %4.1lf %4.1lf %4.1lf/n ", stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].score3,stud[i].average);
 }
 fclose (FP);
}

void ByName ()  //query by name.
{
 char ch_name[20];
 file * FP;
 fp=fopen ("Stu.dat", "RB");
 system ("CLS");
 printf ("Enter name:");
 scanf ("%d", ch_name);
 if (strcmp (ch_name,stud[i].name) ==0)
 {
  fread (&stud[i],sizeof (struct Student), 1,FP);
  printf ("t-learning number name   SCORE 1 2 accomplishment 3 GPA/n");
  printf ("/t%d  %s    %4.1lf %4.1lf %4.1lf %4.1lf/n ", stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].score3,stud[i].average);
 }
 fclose (FP);
}

Void query ()  //query function
{
 int choose;
 system ("CLS");
 do
 {
  //system ("CLS");
 printf ("/n/t/t/t/t Student Information Inquiry/n/n");
 printstar ();
 printf ("________________________________________________________________________________/n");
 printf ("/t/t/t/t1.〖 Inquiry 〗/n/n");
 printf ("/t/t/t/t2.〖 query 〗/n/n by name");
 printf ("/t/t/t/t3.  〖 return 〗/n");
 printf ("________________________________________________________________________________/n");
 printf ("/t/t Please select:");
 scanf ("%d", &choose);
 switch (choose)
 {
 case 1:
  byid ();
  break;
 case 2:
  byname ();
  break;
 case 3:
  return;
&NBSP}
 if (choose!=1 && choose!=2 && choose!=3)
  printf ("Select Error. ");
 }while (choose!=1 && choose!=2);
}

void update ()//Modify student Information
{
FILE * FP;
Fp=fopen ("Stu.dat", "rb+");
System ("CLS");
printf ("/n/t/t/t/t Student Information Modification/n/n");
Printstar ();
printf ("/t/n Enter the student number to modify the information:");
scanf ("%d", &stud[i].id);
Fread (&stud[i],sizeof (struct student), 1,FP);
printf ("Data before/n modified:/n");
printf ("T-learning number 1 score 2 accomplishment 3 GPA/n");
printf ("/t%d%s%4.1lf%4.1lf%4.1lf%4.1lf/n", Stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].scor E3,stud[i].average);

Fclose (FP);
}

void del ()//Information deletion function
{
FILE * FP;
int del_id;
Char choose= ' Y ';
Fp=fopen ("Stu.dat", "RB");
System ("CLS");
printf ("/n/t/t/t/t Student Information Delete/n/n");
if (count==0)
{
Printstar ();
printf ("/n/n/t/t/t no records in your student database!/n/n/n");
Printstar ();
Return
}
Todo
{
printf ("/t/n Enter the student number to delete the information:");
scanf ("%d", &del_id);
if (del_id==stud[i].id)
{
Fread (&stud[i],sizeof (struct student), 1,FP);
printf ("T-learning number 1 score 2 accomplishment 3 GPA/n");
printf ("/t%d%s%4.1lf%4.1lf%4.1lf%4.1lf/n", Stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].scor E3,stud[i].average);
printf (/n/n Are you sure you want to delete the information for student%d (y/n): ");
scanf ("%c", &choose);
if (choose== ' Y ')
{
for (i=0;i<count-1;i++)
{
STUD[I]=STUD[I+1];
count--;
}
printf ("All student information after/n deleted:/n");
for (i=0;i<count;i++)
{
Fread (&stud[i],sizeof (struct student), 1,FP);
printf ("T-learning number 1 score 2 accomplishment 3 GPA/n");
printf ("/t%d%s%4.1lf%4.1lf%4.1lf%4.1lf/n", Stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].scor E3,stud[i].average);
printf ("/n/n/t/t/t Press ESC to return/n/n");
}
}
Else
Return
}
Else
printf ("/n/n Sorry, there is no information for student%d.");
}while (choice== ' y ');
Fclose (FP);
}

void sort_id ()  //sorting by school number
{
 file * FP;
 int j=0,temp=0;
 fp=fopen ("Stu.dat", "RB");
 for (i=0;i<count;i++)
 {
  for (j=0;j<count-i-1;j++)
  {
   if (stud[j].id>stud[j+1].id)
   {
    temp=stud[j ].id;
    stud[j].ID=stud[j+1].ID;
    stud[j+1].ID=temp;
   }
  }
 }
 system ("CLS");
 printf ("/n/t/t/t/t list/n/n sorted by school number");
 for (i=0;i<count;i++)
 {
  fread (&stud[i],sizeof (struct student), 1,FP);
  printf ("t-learning number   name       score 1 score 2 accomplishment 3 GPA/n");
  printf ("/t%d   %s   %4.1lf %4.1lf %4.1lf %4.1lf/n ", stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].score3,stud[i].average);
 }
 fclose (FP);
}

void Sort_ave ()//sorted by average
{
FILE * FP;
int j=0;
Double temp=0;
Fp=fopen ("Stu.dat", "RB");
for (i=0;i<count;i++)
{
for (j=0;j<count-i-1;j++)
{
if (stud[j].average>stud[j+1].average)
{
Temp=stud[j].average;
Stud[j].average=stud[j+1].average;
Stud[j+1].average=temp;
}
}
}
System ("CLS");
printf ("/n/t/t/t/t sorted by average list/n/n");
for (i=0;i<count;i++)
{
Fread (&stud[i],sizeof (struct student), 1,FP);
printf ("T-learning number 1 score 2 accomplishment 3 GPA/n");
printf ("/t%d%s%4.1lf%4.1lf%4.1lf%4.1lf/n", Stud[i].id,stud[i].name,stud[i].score1,stud[i].score2,stud[i].scor E3,stud[i].average);
}
Fclose (FP);
}

Void sort ()  //Sort function
{
 int choose;
 system ("CLS");
 do
 {
  system ("CLS");
  printf ("/n/n/n/t/t/t/t Student Information Sorting/n/n");
  printstar ();
  printf ("/t/t/t/t1.〖 sorted by average 〗/n/n");
  printf ("/t/t/t/t2.") Sorted by School Number 〗/n/n ");
  printf ("/t/t/t/t3.   〖 return 〗/n/n");
  printstar ();
  printf ("/t/t/t Please select:");
  scanf ("%d", &choose);
  switch (choose)
  {
   case 1:
    sort_ Ave ();
    break;
   case 2:
    sort_id ();
    break;
   case 3:
    return;
&NBSP;&NBSP}
 }while (choose!=1&&choose!=2&&choose!=3);
}

void logout ()//Exit Program
{
System ("CLS");
printf ("/n/n/n/t/t/t you will exit the Student information management system.") /n/n ");
Printstar ();
printf ("/n/n/t/t Thank you for using this management system, if you have any questions please contact the developer/n/n");
printf ("/t/t Developer: Gao Zhilin/t/te-mail:gaozhi0@163.com/n/n/n/n/n");
Printstar ();
}

void Main ()
{
Char choice= ' 1 ';
Login ();
System ("CLS");
Todo
{
System ("CLS");
Printstar ();
printf ("/n/t/t/t Welcome to use Student information management system.") /n/n ");
Printstar ();
printf ("/n/t/t/t/t1." Information input "n");
printf ("/n/t/t/t/t2." Information Browsing "/n");
printf ("/n/t/t/t/t3." Information query "/n");
printf ("/N/T/T/T/T4." Information modifies "/n");
printf ("/n/t/t/t/t5." Deletes "/n");
printf ("/n/t/t/t/t6." Information sort "n");
printf ("/n/t/t/t/t7. "Quit"/n ");
printf ("/n/t/t/t Please select:");
scanf ("%c", &choice);
Switch (choice)
{
Case ' 1 ':
Input ();
Break
Case ' 2 ':
browse ();
Break
Case ' 3 ':
Query ();
Break
Case ' 4 ':
Update ();
Break
Case ' 5 ':
Del ();
Break
Case ' 6 ':
Sort ();
Break
Case ' 7 ':
Logout ();
Break
Default
printf ("Input error");
}
}while (choice!= ' 1 ' &&choice!= ' 2 ' &&choice!= ' 3 ' &&choice!= ' 4 ' &&choice!= ' 5 ' & &choice!= ' 6 ' &&choice!= ' 7 ');
}

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.