CHARITY MANAGEMENT SYSTEM Institution Student name Location Tutor Date #include #include //contains printf,scanf etc #include //contains delay(),getch(),gotoxy(),etc #include #include //contains strcmp(),strcpy(),Strlen(),etc #include //contains toupper(),tolower(),etc #include //contains dos getdate #include #define RETURNTIME 1 // contains return date, etc //list of function prototype char catagories[][16]={"Buying bag","selling bag",}; //global variables void returnfunc(void); //it simply sets the value of hidden variable, a function accepts zero or more parameter and return one variable void welcome(void); //declaration for welcome function void login(void); //declaration for login function void mainmenu(void); //declaration for the menu function void addbags(void); //declaration for the add function void sellbags(void); //declaration for the delete function void exitapplication(void); //declaration for exiting function int getdata(); int checkid(int); int t(void); COORD coord = {0, 0}; //function to set coordinates to 0,0 COORD max_res,cursor_size; void gotoxy (int x, int y) //function that sets the cursor positiion for simply to move the cursor on your monitor screen wherever desired. { coord.X = x; coord.Y = y; //function to input X and Y coordinates SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } void delay(unsigned int mseconds) { clock_t goal = mseconds + clock(); //shows the processor clock time used since the beginning of an //implementation defined era (normally the beginning of the program). while (goal > clock()); } FILE *fp,*ft,*fs; //global files that can be accessed from anywhere in program //list of global variable int s; char findbag; struct meroDate { int mm,dd,yy; }; struct bags { int id; char stname[20]; char name[20]; char Writer[20]; int quantity; float Amount; int bagno; char *cat; struct meroDate issued; struct meroDate duedate; }; struct bags r; int main() { welcome(); login(); getch(); return 0; } void welcome() //function to display welcome screen { gotoxy(4,6); printf("By student\n"); //printf is used to display the output by print the character, string, integer etc. gotoxy(1,10); printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"); gotoxy(32,12); printf("WELCOME TO CHARITY MANAGEMENT SYSTEM"); gotoxy(32,14); printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"); //sleep(3); system("cls"); getch(); //it is used as a trick to hold the output screen live for a desired period of time by the user login(); mainmenu(); } char u[30],p[30]; void login() //function that display login screen { do{ printf("\n\n\n\t\t\t ENTER THE USERNAME AND PASSWORD\n\n\n\n"); printf("\n\t\t\tUSERNAME: "); scanf("%s",&u); //scanf is used to read input such as character, string, numeric data from keyboard. printf("\n\t\t\tPASSWORD: "); scanf("%s",&p); if((strcmp(u,"nil")==0) && (strcmp(p,"nil")==0)) { printf("\n\n\t\t login successful"); printf("\n\n\n\t\t\t\t Press any key for main menu....."); getch(); mainmenu(); } else { printf("\n\n\t\tInvalid username and password"); } }while("number_of_try"); } // function to display main menu void mainmenu() { system("cls"); int i; //local variable for switch options gotoxy(20,3); printf(" MAIN MENU "); gotoxy(20,5); printf(" 1. Buy bag "); gotoxy(20,7); printf(" 2. sell bag"); gotoxy(20,9); printf(" 3. Exit Application"); gotoxy(20,11); t(); gotoxy(20,13); printf("Enter your choice:"); switch(getch()) { case '1': addbags(); break; case '2': sellbags(); break; case '3': { system("cls"); delay(3000); exit(0); } default: { gotoxy(10,23); printf("\nWrong Entry!!"); if(getch()) mainmenu(); } } } void addbags(void) //function to add bags { system("cls"); int i; //local variable for switch option gotoxy(20,5); printf("\tSTATE OF BAGS"); gotoxy(20,7); printf(" 1. Excellent condition "); gotoxy(20,9); printf(" 2. Very good condition"); gotoxy(20,11); printf(" 3. Good condition"); gotoxy(20,13); printf(" 4. Fair condition"); gotoxy(20,15); printf(" 5. Poor condition"); gotoxy(20,17); printf(" 6. Reject condition"); gotoxy(20,19); printf(" 7. Main menu"); gotoxy(20,21); printf("Enter your choice:"); scanf("%d",&s); if(s==7) mainmenu() ; system("cls"); fp=fopen("Project.dat","ab+"); if(getdata()==1) { r.cat=catagories[s-1]; fseek(fp,0,SEEK_END); //fseek sets the file position of the given offset fwrite(&r,sizeof(r),1,fp); //size_r this is the unsigned integral type and is the result of the sizeof keyword. fclose(fp); gotoxy(21,14); printf("The record is sucessfully saved"); gotoxy(21,15); printf("Save any more?(Y / N):"); if(getch()=='n') mainmenu(); else system("cls"); addbags(); } } void sellbags() //function that delete from file fp { system("cls"); int d; int h; char another='y'; while(another=='y') //cause infinite loop { system("cls"); gotoxy(10,5); printf("Enter the number of bags to sell :"); scanf("%d",&d); printf("Enter the customer's carrying capacity :"); scanf("%d",&h); if(&h>=r.quantity){ fp=fopen("Project.dat","rb+"); rewind(fp); while(fread(&r,sizeof(r),1,fp)==1) { if(r.id==d) { gotoxy(10,7); printf("The bag record is available"); gotoxy(10,8); printf("Bag location is %s",r.name); gotoxy(10,9); //printf("Bags description weight is %d",r.bagno); //gotoxy(10,11); printf("Bag description weight is %d",r.quantity); gotoxy(10,13); printf("Customer's carrying capacity is %d",h); findbag='t'; } }} else{ printf("The buyer needs more carrying capacity :"); } if(findbag!='t') { gotoxy(10,10); printf("No record is found to sell"); if(getch()) mainmenu(); } if(findbag=='t' ) { gotoxy(10,17); printf("Compare customer's carrying capacity with the bag's description weight"); printf("Is it possible to sell it?(Y/N):"); if(getch()=='y') { ft=fopen("temp.dat","wb+"); //for deleting temporary files rewind(fp); //sets the file position to the beginning of the file of the given stream while(fread(&r,sizeof(r),1,fp)==1) { if(r.id!=d) { fseek(ft,0,SEEK_CUR); //sets current position of file fwrite(&r,sizeof(r),1,ft); //write all items in temporary file except we want to delete } } fclose(ft); fclose(fp); remove("Project.dat"); rename("temp.dat","Project.dat"); //read all items from temporary file except we want to delete fp=fopen("Project.dat","rb+"); if(findbag=='t') { gotoxy(10,13); printf("The bag is successfully sold"); gotoxy(10,15); printf("sell another bag?(Y/N)"); } } else mainmenu(); fflush(stdin); //the fflush function causes any unwritten data for that stream to be delivered to the host environment to be written to the file, //so the behaviour is undefined another=getch(); } } gotoxy(10,15); mainmenu(); } void issuebags(void) //function for issuing bags { int t; //local variable for switch option system("cls"); gotoxy(10,3); printf(" ISSUE SECTION "); gotoxy(10,5); printf(" 1. Issue a Bag"); gotoxy(10,7); printf(" 2. View Issued Bag"); gotoxy(10,9); printf(" 3. Search Issued Bag"); gotoxy(10,11); printf(" 4. Remove Issued Bag"); gotoxy(10,14); printf("Enter a Choice:"); switch(getch()) { case '1': //issue bag { system("cls"); int c=0; char another='y'; while(another=='y') //infinite loop { system("cls"); gotoxy(15,4); printf(" Issue Bag section "); gotoxy(10,6); printf("Enter the Bag Id:"); scanf("%d",&t); fp=fopen("Project.dat","rb"); fs=fopen("Issue.dat","ab+"); if(checkid(t)==0) //check weather the bag is available in library or not { gotoxy(10,8); printf("The bag record is available"); gotoxy(10,9); printf("There are %d unissued bags ",r.quantity); gotoxy(10,10); printf("The name of bag is %s",r.name); gotoxy(10,11); printf("Enter name:"); scanf("%s",r.stname); gotoxy(10,12); printf("Issued date=%d-%d-%d",r.issued.dd,r.issued.mm,r.issued.yy); //for current date gotoxy(10,13); printf("The BAG of ID %d is issued",r.id); r.duedate.dd=r.issued.dd+RETURNTIME; //for return date r.duedate.mm=r.issued.mm; r.duedate.yy=r.issued.yy; if(r.duedate.dd>30) { r.duedate.mm+=r.duedate.dd/30; r.duedate.dd-=30; } if(r.duedate.mm>12) { r.duedate.yy+=r.duedate.mm/12; r.duedate.mm-=12; } gotoxy(10,14); printf("To be return:%d-%d-%d",r.duedate.dd,r.duedate.mm,r.duedate.yy); fseek(fs,sizeof(r),SEEK_END); //end of the file fwrite(&r,sizeof(r),1,fs); fclose(fs); c=1; } if(c==0) { gotoxy(10,11); printf("No record found"); } gotoxy(10,15); printf("Issue any more(Y/N):"); fflush(stdin); another=getche(); fclose(fp); } break; } case '2': //case shows the issue bags list { system("cls"); int j=4; gotoxy(2,1); printf(" Issued bag list "); gotoxy(2,2); printf("NAME CATEGORY ID BAG NAME ISSUED DATE RETURN DATE"); fs=fopen("Issue.dat","rb"); while(fread(&r,sizeof(r),1,fs)==1) { gotoxy(2,j); printf("%s",r.stname); gotoxy(18,j); printf("%s",r.cat); gotoxy(30,j); printf("%d",r.id); gotoxy(36,j); printf("%s",r.name); gotoxy(51,j); printf("%d-%d-%d",r.issued.dd,r.issued.mm,r.issued.yy ); gotoxy(65,j); printf("%d-%d-%d",r.duedate.dd,r.duedate.mm,r.duedate.yy); gotoxy(50,25); //printf("Current date=%d-%d-%d",d.day,d.month,d.year); j++; } fclose(fs); gotoxy(1,25); returnfunc(); } break; case '3': //search issued bags by id { system("cls"); gotoxy(10,6); printf("Enter Bag ID:"); int p,c=0; char another='y'; while(another=='y') { scanf("%d",&p); fs=fopen("Issue.dat","rb"); while(fread(&r,sizeof(r),1,fs)==1) { if(r.id==p) { issuerecord(); gotoxy(10,12); printf("Press any key......."); getch(); issuerecord(); c=1; } } fflush(stdin); fclose(fs); if(c==0) { gotoxy(10,8); printf("No Record Found"); } gotoxy(10,13); printf("Try Another Search?(Y/N)"); another=getch(); } } break; case '4': //case remove issued bags from list { system("cls"); int b; FILE *fg; //delete for temporary file is declared char another='y'; while(another=='y') { gotoxy(10,5); printf("Enter bag id to remove:"); scanf("%d",&b); fs=fopen("Issue.dat","rb+"); while(fread(&r,sizeof(r),1,fs)==1) { if(r.id==b) { issuerecord(); findbag='t'; } if(findbag=='t') { gotoxy(10,12); printf("Do You Want to Remove it?(Y/N)"); if(getch()=='y') { fg=fopen("record.dat","wb+"); rewind(fs); while(fread(&r,sizeof(r),1,fs)==1) { if(r.id!=b) { fseek(fs,0,SEEK_CUR); fwrite(&r,sizeof(r),1,fg); } } fclose(fs); fclose(fg); remove("Issue.dat"); rename("record.dat","Issue.dat"); gotoxy(10,14); printf("The issued bag is removed from list"); } } if(findbag!='t') { gotoxy(10,15); printf("No Record Found"); } } gotoxy(10,16); printf("Delete any more?(Y/N)"); another=getch(); } } default: gotoxy(10,18); printf("\nWrong Entry!!"); getch(); issuebags(); break; } gotoxy(1,30); returnfunc(); } void returnfunc(void) { { printf(" Press ENTER to return to main menu"); } r: if(getch()==13) //allow only the use of enter mainmenu(); else goto r; } int getdata() { int t; gotoxy(20,3); printf("Enter the Information Below"); gotoxy(21,5); printf("Category:"); gotoxy(31,5); printf("%s",catagories[s-1]); gotoxy(21,6); printf("No of bags:\t"); gotoxy(30,6); scanf("%d",&t); r.id=t; gotoxy(21,7); printf("Location:"); scanf("%s",r.name); gotoxy(21,9); printf("Description weight:"); scanf("%d",&r.quantity); gotoxy(21,10); printf("Description cost:"); scanf("%f",&r.Amount); return 1; } int checkid(int t) //checks weather the bag exist in library or not { rewind(fp); while(fread(&r,sizeof(r),1,fp)==1) //size_r this is the unsigned integral type and is the result of the sizeof keyword. if(r.id==t) return 0; //return 0 if bag exist return 1; //return 1 if bag not exist } int t(void) //for adding time { time_t t; time(&t); printf("Date and time:%s\n",ctime(&t)); return 0 ; } void issuerecord() //function that displayed the bag's information { system("cls"); gotoxy(10,8); printf("Issued Date:%d-%d-%d",r.issued.dd,r.issued.mm,r.issued.yy); gotoxy(10,10); printf("Returning Date:%d-%d-%d",r.duedate.dd,r.duedate.mm,r.duedate.yy); } // End of program REFERENCES By Hueman theme, semicolon codes, 2018. Michael Vine C Programming for the Absolute Beginner, 2nd Edition