Friday, November 5, 2010

C language to a student enrollment system

This article comes from Designer handbags.Computer technology .

#include<stdio.h>
#include<stdlib.h>
int N1,N2,kk1,kk2,kk3;
struct couse * head1;
struct student * head2;
Struct couse//course information structure
{
    int num1;
    char name1[20];
    int score;
    Int nelepeo;//course number has been selected
    Int Melepeo;//maximum number of courses
    struct couse * next;
};
Struct student//student information structure
{
    int num2;
    char name2[20];
    Int nelenum [50];//the selected course number
    Int nelen;//number of the selected courses
    struct student * next;
};
void Ms()
{
    for(kk1=0;kk1<1100;kk1++)
                for(kk2=0;kk2<1200;kk2++)
                    for(kk3=0;kk3<1200;kk3++);
}
Void keyboardc ()//entry course child function (from keyboard input)
{
struct couse *p1,*p2;
N1=0;
p1=p2=(struct couse*)malloc(sizeof(struct couse));
Printf ("course number \t course name \t the maximum number of course credit \t \n");
scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
p1->nelepeo=0;
head1=NULL;
while(p1->num1!=0)
{
    N1=N1+1;
    if(N1==1)head1=p1;
    else p2->next=p1;
    p2=p1;
    p1=(struct couse * )malloc(sizeof(struct couse));
    scanf("%d%s%d%d",&p1->num1,p1->name1,&p1->score,&p1->Melepeo);
    p1->nelepeo=0;
}
p2->next=NULL;
}
Void filec ()//input keyboard sub function (from file input)
{
    FILE * fp;
    char filepath[20];
    struct couse *p1,*p2;
    N1=0;
    Printf ("enter the file path you want to read:");
    getchar();
    gets(filepath);
    if((fp=fopen(filepath,"r"))==NULL)
    {
        Printf ("couldn't find the file% s! \n", filepath);
        exit(0);
    }
    p1=p2=(struct couse*)malloc(sizeof(struct couse));
    fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
    head1=NULL;
    while(!feof(fp))
    {
        N1=N1+1;
        if(N1==1)head1=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct couse * )malloc(sizeof(struct couse));
        fscanf(fp,"%d%s%d%d%d",&p1->num1,p1->name1,&p1->score,&p1->nelepeo,&p1->Melepeo);
    }
    p2->next=NULL;
}
Void inputc ()//entry course main function
{
    int i;
    Printf ("\t\t\t entry course information \n");
    Printf ("\n from keyboard input \n1.");
    Printf ("input from file 2. \n");
    Printf ("return to the main menu 3. \n");
    Printf ("Please select (1 ~ 3): \n");
    scanf("%d",&i);
    switch(i)
    {
    case(1):keyboardc();break;
    case(2):filec();break;
    case(3):break;
    }
}
Void insertc (struct couse * incouse)//course management sub function (additional courses)
{
    struct couse *p0,*p1,*p2;
    p1=head1;
    p0=incouse;
    if(head1==NULL)
    {
        head1=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num1 > p1->num1) && (p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num1 <= p1->num1)
        {
            if(head1==p1) head1=p0;
            else p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
    }
    N1=N1+1;
}
Void delc (int num1)//course management sub function (remove courses)
{
    struct couse *p1,*p2;
    if(head1==NULL)
    {
        Printf ("\n no course, could not be deleted! \n");
        goto end;
    }
    p1=head1;
    while(num1!=p1->num1 && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num1==p1->num1)
    {
        if(p1==head1) head1=p1->next;
        else p2->next=p1->next;
        Printf ("the number of courses has been deleted! \n");
        N1=N1-1;
    }
    Else printf ("not the number of courses! \n");
    end:;
}
Void managementc ()//course management main function
{
    struct couse * incouse;
    int i,num1;
    Printf ("\t\t\t course management \n");
    Printf ("\n 1. Add new courses");
    Printf ("\n delete course 2.");
    Printf ("return to the main menu 3. \n");
    Printf ("Please select (1 ~ 3): \n");
    scanf("%d",&i);
    switch(i)
    {
    case(1):
        {
            incouse=(struct couse *)malloc(sizeof(struct couse));
            Printf ("course number \t course name \t the maximum number of course credit \t \n");
            scanf("%d%s%d%d",&incouse->num1,incouse->name1,&incouse->score,&incouse->Melepeo);
            incouse->nelepeo=0;
            insertc(incouse);
            break;
        }
    case(2):
        {
            Printf ("enter the number you want to delete courses: \n");
            scanf("%d",&num1);
            delc(num1);
            break;
        }
    case(3):break;
    }
}
Void keyboards ()//entry student information the child function (from keyboard input)
{
    int i;
    struct student *p1,*p2;
    N2=0;
    p1=p2=(struct student *)malloc(sizeof(struct student));
    Printf ("student learning, student name \t \n");
    scanf("%d%s",&p1->num2,p1->name2);
    p1->nelen=0;
    for(i=0;i<20;i++) p1->nelenum[i]=0;
    head2=NULL;
    while(p1->num2!=0)
    {
        N2=N2+1;
        if(N2==1)head2=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct student * )malloc(sizeof(struct student));
        scanf("%d%s",&p1->num2,p1->name2);
        p1->nelen=0;
        for(i=0;i<20;i++) p1->nelenum[i]=0;
    }
    p2->next=NULL;
}
Void files ()//entry student information the child function (from file input)
{
    int i=0;
    FILE * fp;
    char filepath[20];
    struct student *p1,*p2;
    N2=0;
    Printf ("enter the file path you want to read:");
    getchar();
    gets(filepath);
    if((fp=fopen(filepath,"r"))==NULL)
    {
        Printf ("couldn't find the file% s! \n", filepath);
        exit(0);
    }
    p1=p2=(struct student*)malloc(sizeof(struct student));
    fread(p1,sizeof(struct student),1,fp);
    head2=NULL;
    while(!feof(fp))
    {
        i=0;
        N2=N2+1;
        if(N2==1)head2=p1;
        else p2->next=p1;
        p2=p1;
        p1=(struct student * )malloc(sizeof(struct student));
        fread(p1,sizeof(struct student),1,fp);
    }
    p2->next=NULL;
}
Void inputs ()//entry student information main function
{
    int i;
    Printf ("\t\t\t entry student information \n");
    Printf ("\n from keyboard input \n1.");
    Printf ("input from file 2. \n");
    Printf ("return to the main menu 3. \n");
    Printf ("Please select (1 ~ 3): \n");
    scanf("%d",&i);
    switch(i)
    {
    case(1):keyboards();break;
    case(2):files();break;
    case(3):break;
    }
}
Void inserts (struct student * incouse)//student information management sub function (additional information)
{
    struct student *p0,*p1,*p2;
    p1=head2;
    p0=incouse;
    if(head2==NULL)
    {
        head2=p0;
        p0->next=NULL;
    }
    else
    {
        while((p0->num2 > p1->num2) && (p1->next!=NULL))
        {
            p2=p1;
            p1=p1->next;
        }
        if(p0->num2 <= p1->num2)
        {
            if(head2==p1) head2=p0;
            else p2->next=p0;
            p0->next=p1;
        }
        else
        {
            p1->next=p0;
            p0->next=NULL;
        }
    }
    N2=N2+1;
}
Void dels (int num2)//student information management sub function (delete student information)
{
    struct student *p1,*p2;
    if(head2==NULL)
    {
        Printf ("\n not the students ' information, not deleted! \n");
        goto end;
    }
    p1=head2;
    while(num2!=p1->num2 && p1->next!=NULL)
    {
        p2=p1;
        p1=p1->next;
    }
    if(num2==p1->num2)
    {
        if(p1==head2) head2=p1->next;
        else p2->next=p1->next;
        Printf ("the student information has been deleted! \n");
        N2=N2-1;
    }
    Else printf ("the numbers of students! \n");
    end:;
}
Void managements ()//student information management main function
{
    struct student * incouse;
    int i,num2;
    Printf ("\t\t\t student information management \n");
    Printf ("1. the new student information \n");
    Printf ("2. delete student information \n");
    Printf ("return to the main menu 3. \n");
    Printf ("Please select (1 ~ 3): \n");
    scanf("%d",&i);
    switch(i)
    {
    case(1):
        {
            incouse=(struct student *)malloc(sizeof(struct student));
            incouse->nelen=0;
            incouse->nelenum[0]=0;
            Printf ("student learning, student name \t \n");
            scanf("%d%s",&incouse->num2,incouse->name2);
            inserts(incouse);
            break;
        }
    case(2):
        {
            Printf ("enter to delete a student's school number: \n");
            scanf("%d",&num2);
            dels(num2);
            break;
        }
    case(3):break;
    }
}
Void elect (struct student * s)//courses
{
    struct couse * p;
    int num1,i;
    Printf ("enter a number to the course: \n");
    scanf("%d",&num1);
    for(i=0;s->nelenum[i]!=0;i++);
    s->nelenum[i]=num1;
    (s->nelen)++;
    p=head1;
    while(p->num1!=num1) p=p->next;
    (p->nelepeo)++;
}
Void cheak ()//Student elective sub function (query optional course)
{
    char e;
    struct couse * c;
    struct student * s;
    int num2,i,j=0,t=0;
    Printf ("Please enter your school number:");
    scanf("%d",&num2);
    s=head2;
    while(s->num2!=num2 && s->next!=NULL) s=s->next;
    if(s->n

No comments:

Post a Comment