Skip to content
This repository has been archived by the owner on Mar 22, 2022. It is now read-only.

Commit

Permalink
new project added
Browse files Browse the repository at this point in the history
  • Loading branch information
tbhaxor committed Oct 2, 2018
1 parent 0e65077 commit e61a43a
Show file tree
Hide file tree
Showing 5 changed files with 163 additions and 37 deletions.
157 changes: 127 additions & 30 deletions C/CAFETERIA_ORDER_PROGRAM/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,42 @@
#include <stdlib.h>
#include <time.h>
#include <string.h>

/**
* Function to print order details
*
* */
void printOrder(int i)
{
printf("Invoice: %d\n", c[i].order.invoice);
printf("Customer Name: %s\tPhone Number: %ld\n", c[i].customer.name, c[i].customer.pno);
printf("Order: %s\n", c[i].order.item);
printf("Quantity: %d\t\t", c[i].order.quantity);
printf("Price: %.2f\n", c[i].order.price);
if (c[i].order.isPaid)
{
printf("Status: Paid");
}
else
{
printf("Status: Not Paid");
}
}

/**
* Clear output screen
*
* */
void clear()
{
if (system("clear") != 0)
system("cls");
}

/**
* Clears input Buffer
*
* */
void flush()
{
char c;
Expand All @@ -20,6 +50,10 @@ void flush()
}
}

/**
* Prints menu and returns user selection
*
* */
int menu()
{
clear();
Expand All @@ -28,17 +62,20 @@ int menu()
printf("==================================\n\n");
printf("1. Add new order");
printf("\n2. Delete order");
printf("\n3. Edit order");
printf("\n4. Show all order");
printf("\n5. Search order");
printf("\n6. Quit");
printf("\n3. Show all order");
printf("\n4. Search order");
printf("\n5. Quit");
printf("\n> ");
int opt;
scanf("%d", &opt);
flush();
return opt;
}

/**
* Prints banner and info of coder
*
* */
void info()
{
clear();
Expand All @@ -50,28 +87,33 @@ void info()
clear();
}

/**
* Add new order
*
* */
void addNew()
{
++top;
if (top > MAX_SIZE)
{
printf("Buffer Overflow");
exit(1);
}
srand(time(NULL));
printf("==================================\n");
printf("== ADD NEW ==\n");
printf("==================================\n\n");
if (top > MAX_SIZE)
{
printf("Buffer Overflow");
return;
}
c[top].order.invoice = (rand() % 99999999 + 1);
printf("enter name: ");
fgets(c[top].customer.name, 30, stdin);
c[top].customer.name[strcspn(c[top].customer.name, "\r\n")] = 0;
printf("enter phone number: ");
scanf("%ld", &c[top].customer.pno);
flush();
printf("invoice: %d\n", c[top].order.invoice);
printf("enter item name: ");
fgets(c[top].order.item, 30, stdin);
strtok(c[top].order.item, '\n');
c[top].order.item[strcspn(c[top].order.item, "\r\n")] = 0;
printf("price (per item): ");
float p;
scanf("%f", &p);
Expand All @@ -86,42 +128,97 @@ void addNew()
flush();
}

/**
* Deleting existing order
*
* */
void deleteOld()
{
printf("==================================\n");
printf("== DELETE ORDER ==\n");
printf("==================================\n\n");
if (top == -1)
{
return;
}
int iv;
printf("enter invoice number: \n");
scanf("%d", &iv);
flush();
int found = 0;
for (int i = 0; i <= top; i++)
{
if (c[i].order.invoice == iv)
{
if (i == top)
found = 1;
else
{
for (int j = i + 1; j <= top; j++)
{
c[j - 1] = c[j];
}
}
found = 1;
}
}
if (!found)
{
printf("Not Found");
}
else
{
printf("Deleted");
--top;
}
}

/**
* Searching order
* */
void search()
{
printf("==================================\n");
printf("== SEARCH ORDER ==\n");
printf("==================================\n\n");
if (top == -1)
{
return;
}
int iv;
printf("enter invoice number: \n");
scanf("%d", &iv);
flush();
int found = 0;
for (int i = 0; i <= top; i++)
{
if (c[i].order.invoice == iv)
{
printOrder(i);
found = 1;
}
}
if (!found)
{
printf("Not Found");
}
}

void modify()
{
}

/**
* SHOWING all orders
*
*
* */
void showall()
{
printf("==================================\n");
printf("== SHOWING ALL ORDERS ==\n");
printf("==================================\n\n");
printf("%s", c[0].order.item);
printf("%s", c[0].customer.name);
return;
for (int i = 0; i < top + 1; i++)
{
printf("Invoice: %d\n", c[i].order.invoice);
printf("Customer Name: %sPhone Number: %ld\n", c[i].customer.name, c[i].customer.pno);
printf("Order: %s", c[i].order.item);
printf("Quantity: %d\n", c[i].order.quantity);
printf("Price: %f\n", c[i].order.price);
if (c[i].order.isPaid)
{
printf("Status: Paid");
}
else
{
printf("Status: Not Paid");
}
printOrder(i);
printf("\n------------------------------------------------------\n");
}
}

#endif // ACTOR
5 changes: 4 additions & 1 deletion C/CAFETERIA_ORDER_PROGRAM/cafeteria.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@

#include "config.h"

// schema for customer
struct Customer
{
char name[30];
long pno;
};

// schema for order placed
struct Order
{
char item[30];
Expand All @@ -18,10 +20,11 @@ struct Order
int isPaid;
};

// schema for Cafeteria
struct Cafeteria
{
struct Order order;
struct Customer customer;
} c[MAX_SIZE];
int top = -1;
int top = -1; // top
#endif
8 changes: 2 additions & 6 deletions C/CAFETERIA_ORDER_PROGRAM/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,14 @@ int main()
deleteOld(); // calling function to delete order
break;
case 3:
clear(); // clearing output screen
modify(); // calling function to modify an order
break;
case 4:
clear(); // clearing output screen
showall(); // calling function to show all order
break;
case 5:
case 4:
clear(); // clearing output screen
search(); // calling function to search an order
break;
case 6:
case 5:
return 0; // exiting of option selected 6
default:
printf("Invalid Input");
Expand Down
30 changes: 30 additions & 0 deletions C/CAFETERIA_ORDER_PROGRAM/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Cafeteria Management System
This is C based program for demonstrating the use of `struct` in C


# Requirements
+ gcc v5+ installed

# How to Run
+ Change the `config.h` file
```cpp
// coder settings
#define NAME "Gurkirat"
#define INSTITUTION "MDU Rohtak"
#define SUBMITTED_TO "Mr. Deepak"

// program settings
#define MAX_SIZE 100
```
+ Building the program
```
$ gcc main.c -o program
```

+ Running the program
```
$ program
```

**Note :** If you are on windows os then add `gcc.exe` to the enviroment path variable before compiling the program
Binary file removed C/CAFETERIA_ORDER_PROGRAM/test
Binary file not shown.

0 comments on commit e61a43a

Please sign in to comment.