[Solved] Food Court-Billing System with C

Food Court-Billing System: A popular food court in the mall decides to give points for each order which is equal to the total amount of the bill, inorder to maintain this system as a simple one each customer is provided an e-card which will keep track of each and every bill of the particular customer and generates scores for the customer and store it in the card.

Now, the food court wants to upgrade the system by developing with some additional functionally such as showing the list of transaction and view the sum of gained score. If you think you can help them for developing such app, let’s start at this point.

Define a structure
struct food_court
{
    int bill_amount;
    struct food_court * link;
};

Include functions:
    append — to add new bill amount.
    display — to display all the bill paid by the customer.
     sum — to display sum of the total score gained by the customer.

void append(struct food_court**,int);

void display(struct food_court*);

int sum(struct food_court*);

Refer function specifications for further details.
[Note: The stmt. ‘Elements in the linked list are’ should be in the main function.]


Input and Output Format:
Refer sample input and output for formatting specifications.

[All text in bold corresponds to input and the rest corresponds to output.]

Sample Input and Output 1:
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
1
Pay bill amount:
20
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
2
Card transactions :
20
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
1
Pay bill amount:
25
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
1
Pay bill amount:
200
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
2
Card transactions :
20
25
200
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
3
Gained points :245
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
4
Please visit again

Sample Input and Output 2:
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
2
No transactions found
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
3
Your score is NIL
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
1
Pay bill amount:
25
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
1
Pay bill amount:
500
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
2
Card transactions :
25
500
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
3
Gained points :525
1.Visit the food court
2.View my transactions
3.Show my points
Enter your choice
4
Please visit again

Solution

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct food_court
{
  int data;
  struct food_court*link;
};
void append(struct food_court**,int);
void display(struct food_court*);
int sum(struct food_court*);
int main()
{
  int n,b;
  struct food_court*p;
  p=NULL;
  int x=0;
  do
  {
        printf("1.Visit the food court\n");
	printf("2.View my transactions\n");  
	printf("3.Show my points\n");
	printf("Enter your choice\n");
	scanf("%d",&x);
switch(x)
{
case 1:
    	printf("Pay bill amount:\n");
    	scanf("%d",&n);
    	append(&p,n);
	break;

case 2:
	if(p!=NULL)
	{
		printf("Card transactions :\n");
		display(p);
	}
	else
	{

		printf("No transactions found\n");
	}
	break;
case 3:
	if(p!=NULL)
	{
		b=sum(p);
		printf("Gained points :%d\n",b);
	}
	else
	{
		printf("Your score is NIL\n");
	}
	break;
case 4:
	printf("Please visit again\n");
	break;    
    
  }}while(x!=4);
  return 0;
}
void append(struct food_court **q, int data)
{
    // Fill in the code here
    struct food_court *temp;
    temp = (struct food_court *)malloc(sizeof(struct food_court));
    temp->data = data;
    temp->link = NULL;
    if (*q == NULL)
    {
        *q = temp;
    }
    else
    {
        struct food_court *p;
        p = *q;
        while (p->link != NULL)
        {
            p = p->link;
        }
        p->link = temp;
    }
}
void display(struct food_court *q)
{
    // Fill in the code here
    struct food_court *p;
    p = q;
    while (p != NULL)
    {
        printf("%d\n", p->data);
        p = p->link;
    }

}

int sum(struct food_court *q)
{
    // Fill in the code here
// sauravhathi
    int sum = 0;
    struct food_court *p;
    p = q;
    while (p != NULL)
    {
        sum = sum + p->data;
        p = p->link;
    }
    return sum;
    
}

Happy Learning – If you require any further information, feel free to contact me.

Share your love
Saurav Hathi

Saurav Hathi

I'm currently studying Bachelor of Computer Science at Lovely Professional University in Punjab.

📌 Nodejs and Android 😎
📌 Java

Articles: 444

Leave a Reply

Your email address will not be published. Required fields are marked *