Page

Fee Management System In C

#include<stdio.h>
#include<conio.h>

void main()
{
FILE *fp, *ft;
char another, choice;

struct fee
{       int r_no;
     char name[40];
     char add[40];
     char f_name[40];
     char stream[40];
     long int d_fee;
};
struct fee f;
long int amount,flag;
long int total=2000;
long int pending=0;
long int recsize;
char stream[40];
int r_no;
fp=fopen("FEE2.DAT","rb+");
if(fp==NULL)
{
     fp=fopen("FEE2.DAT","wb+");
     if(fp==NULL)
     {
            puts("Cannot open file");
            exit(1);
     }
}

recsize = sizeof(f);
while(1)
{
     clrscr();
     gotoxy(30,10);
     printf("1. Student detail");
     gotoxy(30,12);
     printf("2. Display Record");
     gotoxy(30,14);
     printf("3. deposite fee");
     gotoxy(30,16);
     printf("4. Pending fee");
     gotoxy(30,18);
     printf("5. Delete Record");
     gotoxy(30,20);
     printf("0.Exit");
     gotoxy(30,22);
     printf("Your choice");
     fflush(stdin);
     choice = getche();
     switch(choice)
     {
            case '1':
            fseek(fp,0,SEEK_END);
            another = 'Y';
            while((another == 'Y') || (another == 'y'))
            {
                        printf("\nEnter Roll_no");
                        scanf("%d", &f.r_no);
                        printf("\nEnter Name");
                        scanf(" %s",f.name);
                        printf("\nEnter Address");
                        scanf("%s",f.add);
                        printf("\nEnter Father name");
                        scanf("%s",f.f_name);
                        printf("\nEnter deposited fee");
                        scanf("%ld", &f.d_fee);
                        printf("\nEnter Stream");
                        scanf("%s",f.stream);
                        fwrite(&f, recsize, 1, fp);
                        printf("\nCreate another Student Record(Y/N)");
                        fflush(stdin);
                        another = getche();
            }
            break;

            case '2':
            clrscr();
            rewind(fp);
            printf("Roll no\tname\tAddress\tFather name\tStream\tdeposited fee\tTotal amount");
            while(fread(&f, recsize, 1, fp) == 1)
                        printf("\n%d\t%s\t%s\t%s\t%s\t%ld\t%ld", f.r_no,f.name, f.add, f.f_name,f.stream, f.d_fee,total);
            getch();
            break;

            case '3':
            another='Y';
            while(another=='Y')
            {
                        printf("\nEnter Roll number to check balance");
                        scanf("%d",&r_no);
                        printf("\nEnter the Stream");
                        scanf("%s",stream);
                        rewind(fp);
                        flag=0;
                        while(fread(&f, recsize, 1, fp)==1)
                        {
                                    if((f.r_no==r_no)&&(strcmp(f.stream,stream)==0))
                                    {
                                    if(f.d_fee<=total)
                                    {
                                                flag=1;
                                                printf("\nEnter amount to deposite");
                                                scanf("%ld",&amount);
                                                f.d_fee=f.d_fee + amount;
                                                fseek(fp, -recsize, SEEK_CUR);
                                                fwrite(&f,recsize,1,fp);
                                                break;
                                    }
                                    }}
                                    if(flag==0)
                                    {
                                                printf("sorry !! invalid rollno");
                                                getch();
                                    }
                        printf("deposite more amount");
                        fflush(stdin);
                        another=getche();
                }
                break;
            case '4':
            another='Y';
            while(another=='Y')
            {
                        printf("\nEnter roll number to check pending amount");
                        scanf("%d",&r_no);
                        printf("\nEnter the Stream");
                        scanf("%s",stream);
                        rewind(fp);
                        flag=0;
                        while(fread(&f, recsize, 1, fp)==1)
                        {
                                    flag=1;
                                    if((f.r_no==r_no)&&(strcmp(f.stream,stream)==0))
                                    {
                                                pending=total-f.d_fee;
                                                printf("\nYour pending amount is %ld",pending);
                                                f.d_fee=f.d_fee+pending;
                                                getch();
                                    }
                        }
                        if(flag==0)
                        {
                                    printf("Sorry !! Invalid roll number");
                                    getch();
                        }

                        fflush(stdin);
                        another=getche();
            }
            break;

            case '5':
            another='Y';
            while(another=='Y')
            {
                        printf("\nEnter roll number to delete");
                        scanf("%d",&r_no);
                        ft = fopen("TEMP.DAT","wb");
                        rewind(fp);
                        while(fread(&f, recsize, 1, fp) == 1)
                        {
                                    if(f.r_no!=r_no)
                                                fwrite(&f, recsize, 1, fp);
                        }
                        fclose(fp);
                        fclose(ft);
                        remove("FEE2.DAT");
                        rename("TEMP.DAT", "FEE2.DAT");
                        fp=fopen("FEE2.DAT", "rb+");
                        printf("Delete another record(Y/N)");
                        fflush(stdin);
                        another = getche();
            }
            break;

            case '0':
            fclose(fp);
            exit();
     }
}}


























No comments:

Post a Comment