SoFunction
Updated on 2024-07-16

C language implementation of membership billing system

In this article, we share the example of C language to realize the specific code of the membership billing system for your reference, the details are as follows

I. Introduction to the project

Through the practice of the C course design of "Membership Card Billing System", you will master functions, data reading and storing.

II. Overview of the mandate

(1) Registration of new members.
(2) Modification of membership information.
(3) Membership renewal.
(4) Membership spending settlement.
(4) Membership withdrawal.

III. Functional display

IV. Mind maps

V. Program source code

#include <>
#include <>
#include <>
#include <>
#define N 100
struct employee
{
int num;
char name[10];
char sex;
int age;
char xueli[30];
int wage;
int xiao;
int yu;
char addr[30];
long int tel;
}em[100]; /* Define a structure */
void menu();
void input();
void save(int);
void display();
void del();
void add();
void search();
void search_num();
void search_xueli();
void search_tel();
void modify(); /* Define each function */
void menu() /* Menu functions */
{
printf(" ****************** Menu Management ****************\n ");
printf(" 1. Registration of new members");
printf(" 2 Statistical functions \n");
printf(" 3. Membership consumption settlement ");
printf(" 4. Membership Refunds\n");
printf(" 5. Renewal of membership cards");
printf(" 6 Modification of membership information\n");
printf(" 7. Lost membership card");
printf(" 8. Exit \n ");
printf(" ************* Welcome to the Membership Card Billing System ************\n");
printf("\n");
printf("\n");
}
int main()
{    int n,flag;
 char a;
char *s1;
int b,j,flg=0;
menu(); /* Calling menu functions */// These can be switched around? Remember that the code that declares the variable comes before the do
{
printf("Please select the steps you need to take(1--8):\n");
scanf("%d",&n);
if(n>=1&&n<=8)
{
flag=1;
}
else
{
flag=0;
printf("You entered incorrectly? Please make a new selection!");
}
}
while(flag==0);
while(flag==1)
{
switch(n)
{
case 1:printf(" ◆◆◆ New Member Registration ◆◆◆\n");printf("\n");input();break;
case 2:printf(" ◆◆◆◆Statistical functions◆◆◆◆\n");printf("\n");display();break;
case 3:printf(" ◆◆◆◆ Member Consumption Settlement ◆◆◆◆\n");printf("\n");search();break;
case 4:printf(" ◆◆◆◆Membership Refunds◆◆◆◆\n");printf("\n");del();break;
case 5:printf(" ◆◆◆ Membership Card Renewal◆◆◆\n");printf("\n");add();break;
case 6:printf(" ◆◆◆Member Information Modification◆◆◆\n");printf("\n");modify();break;
case 7:printf(" ◆◆◆ Lost Membership Card ◆◆◆\n");printf("\n");modify();break;
case 8:exit(0);break;
default :break;
}
getchar();
printf("\n");
printf("Whether to proceed(y or n):\n");
scanf("%c",&a);
if(a=='y')
{
flag=1;
system("cls"); /*clear screen*/
menu(); /* Calling menu functions */
printf("Please select again the step you need to operate(1--7):\n");
scanf("%d",&n);
printf("\n");
}
else
exit(0);
}
}
void input() /* Entry functions */
{
int i,m;
printf("Please enter the number of members who need to create a message(1--100):\n");
scanf("%d",&m);
for (i=0;i<m;i++)
{
printf("Card number?");
srand((int)time(0));
em[i].num=rand()%100+20000000;
if(em[i].num!=em[i-1].num)
printf("%8d ",em[i].num);
printf("\n");
printf("Please enter your name:");
scanf("%s",em[i].name);
getchar();
printf("Please enter your gender(f--womenm--male): ");
scanf("%c",&em[i].sex);
getchar();
printf("Please enter your age:");
scanf("%d",&em[i].age);
getchar();
printf("Please enter academic qualifications:");
scanf("%s",em[i].xueli);
getchar();
printf("Please enter the amount of the contribution:");
scanf("%d",&em[i].wage);
getchar();
printf("Please enter your address:");
scanf("%s",em[i].addr);
getchar();
printf("Please enter phone number:");
scanf("%d",&em[i].tel);
printf("\n");
}
printf("\n Created! \n");
save(m);
}
void save(int m) /* Save file function */
{
int i;
FILE*fp;
if ((fp=fopen("employee_list","wb"))==NULL) /* Create a file and determine if it can be opened */{
printf ("cannot open file\n");
exit(0);
}
for (i=0;i<m;i++) /* Output information about members in memory to a disk file */
if (fwrite(&em[i],sizeof(struct employee),1,fp)!=1)
printf("file write error\n");
fclose(fp);
}
int load() /* Import function */
{
FILE*fp;
int i=0;
if((fp=fopen("employee_list","rb"))==NULL)
{
printf ("cannot open file\n");
exit(0);
}
else
{
do
{
fread(&em[i],sizeof(struct employee),1,fp);
i++;
}
while(feof(fp)==0);
}
fclose(fp);
return(i-1);
}
void display() /* Browse Functions */
{
int i;
int m=load();
printf("\n Card No. \t Name \t Sex \t Age \t Education \t Contribution Amount \t Spending Amount \t Address \t Phone Number \n");
for(i=0;i<m;i++) /*m is the number of members in the input section */
printf("\n %d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].xiao ,em[i].addr,em[i].tel);
}
void del() /* Delete function */
{
int m=load();
int i,j,n,t,flag;
char name[20];
printf("\n Original membership information:\n");
display(); /* Calling the browse function */
printf("\n");
printf("Please enter the name of the member to be deleted:\n");
scanf("%s",name);
for(flag=1,i=0;flag&&i<m;i++)
{
if(strcmp(em[i].name,name)==0)
{
printf("\n has found this person? The original record reads? \n");
printf("\n Card No. Name Gender Age Payment Amount Balance\n");
printf("\n%d\t%s\t%c\t%d\t%d\t%d\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].wage,em[i].yu);
printf("\n indeed to delete this person's information press 1, if not press 0\n");
scanf("%d",&n);
if(n==1) /* If deleted? then all other information is moved up one line */
{
for(j=i;j<m-1;j++)
{
strcpy(em[j].name,em[j+1].name);
em[j].num=em[j+1].num;
em[j].sex=em[j+1].sex;
em[j].age=em[j+1].age;
em[j].wage=em[j+1].wage;
em[j].yu=em[j+1].yu;
}
flag=0;
}
}
}
if(!flag)
m=m-1;
else
printf("\n sorry? We don't have him! \n");
printf("\n Browse all member information after deletion:\n");
save(m); /* Call save function */
display(); /* Calling the browse function */
printf("To continue deletion, press ? To stop deleting, press \n");
scanf("%d",&t);
switch(t)
{
case 1:del();break;
case 0:break;
default :break;
}
}
void add()/* Add function */
{
FILE*fp;
int num;
int t;
int i;
int m=load();
printf("\n Original membership information:\n");
display(); /* Calling the browse function */
printf("\n");
fp=fopen("emploee_list","a");
printf("Please enter the renewal membership number:\n");
scanf("%d",&num);
for(i=0;i<m;i++)
if(num==em[i].num)
{
printf("\n has found this person? Its record is? \n");
printf("\n card number\t name\t payment amount\t spending amount\n");
printf("\n%d\t%s\t%d\t%d\t%d\n",em[i].num,em[i].name, em[i].wage,em[i].xiao);printf("\n Enter renewal amount? \n");
scanf("%d",&t);
em[i].wage= em[i].wage+t;
printf("\n renewed amount? \t%d\n",em[i].wage);
printf("\n Renewal Successful! \n");
}
}
void search()/* Query function */
{
int t,flag;
do
{
printf("\n To search by card number press 1; to search by phone number press 3, to enter the main function press 4\n");
scanf("%d",&t);
if(t>=1&&t<=4)
{
flag=1;
break;
}
else
{
flag=0;
printf("You entered incorrectly? Please make a new selection!");
}
}
while(flag==0);
while(flag==1)
{
switch(t)
{
case 1:printf("Search by card number\n");search_num();break;
case 3:printf("Search by phone number\n");search_tel();break;
case 4:main();break;
default:break;
}
}
}
void search_num()
{
int num;
int i,t;
int m=load();
printf("Please enter the membership card number you are looking for(20000001---20000100):\n");
scanf("%d",&num);
for(i=0;i<m;i++)
if(num==em[i].num)
{
printf("\n has found this person? Its record is? \n");
printf("\n Card No. \t Name \t Sex \t Age \t Payment Amount \t Phone \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].wage,em[i].tel);
printf("\n That consumption is ;\n");
scanf("%d",&em[i].xiao);
em[i].yu=em[i].wage-em[i].xiao;
printf("\n Card No. \t Name \t Sex \t Age \t Payment Amount \t Spending Amount \t Balance \t Phone Number \n");printf("\n%d\t%s\t%c\t%d\t%d\t%d\t%d\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].wage, em[i].xiao,em[i].yu,em[i].tel);
break;
}
if(i==m)
printf("I'm sorry? I don't see anyone here.");
printf("\n");
printf("To return to the query function press 1, to continue querying the card number press 2\n.");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2: break;
default:break;
}
}
void search_tel()
{
long int tel;
int i, t;
int m=load();
printf("Please enter the phone number to be found:\n");
scanf("%ld",&tel);
for(i=0;i<m;i++)
if(tel==em[i].tel)
{
printf("\n has found this person? Its record is? \n");
printf("\n Card No. \t Name \t Sex \t Age \t Payment Amount \t Phone \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,
em[i].wage,em[i].tel);
printf("\n That consumption is ;\n");
scanf("%d",&em[i].xiao);
em[i].yu=em[i].wage-em[i].xiao;
printf("\n Card No. \t Name \t Sex \t Age \t Payment Amount \t Spending Amount \t Balance \t Phone Number \n");
printf("\n%d\t%s\t%c\t%d\t%d\t%d\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].wage, em[i].xiao,em[i].yu,em[i].tel);
break;
}
if(i==m)
printf("I'm sorry? I don't see anyone here.");
printf("\n");
printf("To return to the query function, press , to continue searching for the phone number, press \n.");
scanf("%d",&t);
switch(t)
{
case 1:search();break;
case 2:break;
default :break;
}
}
void modify() /* Modification of functions */
{
int num;
char name[10];
char sex;
int age;
char xueli[30];
int wage;
char addr[30];
long int tel;
int b,c,i,n,t,flag;
int m=load(); /* Import the information in the file */
printf("\n Original membership information:\n");
display(); /* Calling the browse function */
printf("\n");
printf("Please enter the name of the member to be changed:\n");
scanf("%s",name);
for(flag=1,i=0;flag&&i<m;i++)
{
if(strcmp(em[i].name,name)==0)
{
printf("\n has found this person? The original record reads? \n");
printf("\n Card No. \t Name \t Sex \t Age \t Education \t Payment Amount \t Address \t Phone \n");
printf("\n%d\t%s\t%c\t%d\t%s\t%d\t%s\t%ld\n",em[i].num,em[i].name,em[i].sex,em[i].age,em[i].xueli,em[i].wage,em[i].addr,em[i].tel);
printf("\n indeed to change this person's information press; not to change press\n");
scanf("%d",&n);
if(n==1)
{
printf("\n Options that need to be modified\n 1. card number 2. name 3. gender 4. age 5. education 6. contribution amount 7. address 8. phone number\n");printf("Please enter the serial number of the item you wish to modify:\n");
scanf("%d",&c);
if(c>8||c<1)
printf("\n Wrong choice? Please re-select! \n");
}
flag=0;
}
}
if(flag==1)
printf("\n sorry? We don't have him! \n");
do
{
switch(c) /*Because when the i-th member is found, i is added after the for statement, so the following should assign the changed information to the i-1th person */{
case 1:printf("The card number should read: ");
scanf("%d",&num);
em[i-1].num=num;
break;
case 2:printf("The name should read: ");
scanf("%s",name);
strcpy(em[i-1].name,name);
break;
case 3:printf("Replace gender with:");
getchar();
scanf("%c",&sex);
em[i-1].sex=sex;
break;
case 4:printf("Replace age with:");
scanf("%d",&age);
em[i-1].age=age;
break;
case 5:printf("Replace academic qualifications with the following:");
scanf("%s",xueli);
strcpy(em[i-1].xueli,xueli);
break;
case 6:printf("Replace the amount of the contribution with the following: ");
scanf("%d",&wage);
em[i-1].wage=wage;
break;
case 7:printf("For residential address read: ");
scanf("%s",addr);
strcpy(em[i-1].addr,addr);
break;
case 8:printf("The telephone number should read: ");
scanf("%ld",&tel);
em[i-1].tel=tel;
break;
}
printf("\n");
printf("\n Are you sure about the modified information? \n Yes, please press; No, to change it again, please press: \n".);scanf("%d",&b);
}
while(b==2);
printf("\n Browse all member information after modification:\n");
printf("\n");
save(m);
display();
printf("\n To continue, press ? To stop revising, press \n");
scanf("%d",&t);
switch(t)
{
case 1:modify();break;
case 0:break;
default :break;
}
getchar();
}

This is the whole content of this article.