PCD Assignment 2 – Sales Receipt Program

The existing sales receipts program has been running of several months since the day it was used in the KL Fried Chicken Restaurant. The restaurant’s general manager has met up with you to discusson the enhancement to be developed to the program in order to cope with the changing environment and the arising requirements of the restaurant

Sample Video:

C++ Code:

/************************************************
	Program Name : SALES RECEIPT SYSTEM
	Written by   : Lim Teck Wei (DIT)
	Date         : 25-July-2011
************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#define GOVERNMENT_TAX		6
#define SERVICE_TAX		10

// Function Declaration
void f_menu(void);
void f_invalid(void);
void f_view(void);
void f_order(void);
void f_order_set(char);
char f_yesNo(void);
char * f_comboName(char);
float f_price(char);
void f_myorder(void);
void f_cancel(void);
void f_receipt(void);
void f_receipt_list(void);
void f_thankyou(void);

// Variable of Function (f_menu)
int selection;

// Variable of Order List

char set[6];
int setNum[6];

// Variable of Receipt N0
int receiptno = 0;

int main(void)
{
	printf("t=====================================================n"
		   "t SALES RECEIPT SYSTEM (KLFC Sdn. Bhd.)n"
		   "t=====================================================nn"
		   "t     KK  KK  LL      FFFFFF   CCCCC  n"
		   "t     KK KK   LL      FF      CC      n"
		   "t     KKK     LL      FF     CC       n"
		   "t     KKKK    LL      FFFF   CC       n"
		   "t     KK KK   LLLLLL  FF      CC      n"
		   "t     KK  KK  LLLLLL  FF       CCCCC  nn"
		   "t        Good Day and Welcome to KLFC Sdn. Bhd.");

	do{
		f_menu();
	}while(selection != 9);

	return 0;
}

void f_menu()
{
	printf("nt=====================================================nn"
		   "t(1) View Combo Listn");

	if(set[5])
	{
		printf("t(2) My Order Listn"
			   "t(3) Cancel My Ordern"
			   "t(4) Submit My Ordern");
	}
	else if(set[0])
	{
		printf("t(2) Order Combo Set (Continue Order)n"
			   "t(3) My Order Listn"
			   "t(4) Cancel My Ordern"
			   "t(5) Submit My Ordern");
	}
	else
	{
		printf("t(2) Order Combo Setn");
	}
		printf("t(9) Quit the Programn");

	printf("tPlease press a number to make your selection > ");
	fflush(stdin);
	scanf("%d", &selection);

	switch (selection)
	{
	case 1:
		f_view();
		break;
	case 2:
		if(set[5]) 
			f_myorder(); 
		else 
			f_order();
		break;
	case 3:
		if(set[5]) 
			f_cancel();
		else if(set[0]) 
			f_myorder();
		else
			f_invalid();	
		break;
	case 4:
		if(set[5]) 
			f_receipt();
		else if(set[0]) 
			f_cancel();
		else
			f_invalid();
		break;
	case 5:
		if(set[0]) 
			f_receipt();
		else{
			f_invalid();
		}
		break;
	case 9:
		f_thankyou();
		break;
	default:
		f_invalid();
	}
}

void f_invalid(void)
{
	printf("nt+= Sorry. Invalid entry =+n");
}

void f_view()
{
	int list;
	char comboset;
	printf("n"
		   "t=====================================================n"
		   "t  View Combo List n"
		   "t+-------+-------------------------------+-----------+n");

	comboset = 'A';
	for(list = 1; list <= 8; list++)
	{
		printf("t|   %c   | %-29s | RM %6.2f |n", comboset, f_comboName(comboset), f_price(comboset));
		comboset += 1;
	}
	printf("t+-------+-------------------------------+-----------+nnt");

	system("pause");
}

void f_order()
{
	int i;
	char yesNo = 'Y';

	printf("n"
		   "t=====================================================n"
		   "t  Order Formn"
		   "t-----------------------------------------------------n");

	i = 0;
	while(yesNo == 'Y')
	{
		if(!set[i])
		{
			f_order_set(i);
			yesNo = f_yesNo();
		}
		i++;
	}

	printf("nt");

	system("pause");
}

void f_order_set(char setor)
{
	float price;
	do
	{
		printf("ntEnter a series number of combo sets    > ");
		fflush(stdin);
		scanf("%c", &set[setor]);
		price = f_price(set[setor]);

		if(!price)
		{
			printf("t+= The combo set is not available! =+n");
			set[setor] = 0;
			setNum[setor] = 0;
		}
		else
		{
			printf("t+= Set %c = %s = RM %.2f =+n", set[setor], f_comboName(set[setor]), f_price(set[setor]));
			printf("tEnter number of combo sets             > ");
			fflush(stdin);
			scanf("%d", &setNum[setor]);

			while(!setNum[setor])
			{
				printf("t+= Error! This is not a number. =+ n"
					   "tReenter number of combo sets           > ");
				fflush(stdin);
				scanf("%d", &setNum[setor]);
			}
		}

	}while(!set[setor]);

}

char f_yesNo()
{
	char yesNo;
	printf("tDo you want to order another set (Y/N) ? ");
	fflush(stdin);
	scanf("%c", &yesNo);
	yesNo = toupper(yesNo);

	return yesNo;
}

// My Order List
void f_myorder(void)
{
	int i;
	printf("n"
		   "t=====================================================n"
		   "t  My Order List n"
		   "t+---+-----------------------------+-------------+n");

	i = 0;
	while(set[i])
	{
		printf("t| %d |   %-16s  * %3d   | RM%9.2f |n",i+1,f_comboName(set[i]), setNum[i], f_price(set[i])*setNum[i]);
		i++;
	}

	printf("t+---+-----------------------------+-------------+nnt");

	system("pause");
}

// Cancel My Order
void f_cancel(void)
{
	char yesNo;

	printf("n"
		   "t=====================================================n"
		   "t  Cancel My Order n"
		   "t-----------------------------------------------------n"
		   "tDo you want cancel your all order (Y/N) ?      ");
	fflush(stdin);
	scanf("%c", &yesNo);
	yesNo = toupper(yesNo);

	if(yesNo == 'Y')
	{
		int i;
		for(i=0; i<=5; i++)
		{
			set[i] = 0;
			setNum[i] = 0;
		}
		printf("nt+= Your order is cancel. =+n");
	}

	printf("nt");

	system("pause");
}

// Combo Set Name List
char * f_comboName(char comboSet)
{
	switch(comboSet)
	{
	case 'A':
		return "Colonel Burger";
		break;
	case 'B':
		return "Zinger Burger";
		break;
	case 'C':
		return "Snack Plate";
		break;
	case 'D':
		return "Dinner Plate";
		break;
	case 'E':
		return "Popcorn Chicken";
		break;
	case 'F':
		return "Toasted Twister";
		break;
	case 'G':
		return "Buddy Meal";
		break;
	case 'H':
		return "Barrel";
		break;
	default:
		return "";
	}

}

// Combo Set Price List
float f_price(char comboSet)
{
	switch(comboSet)
	{
	case 'A':
		return (float)5.50;
		break;
	case 'B':
		return (float)7.70;
		break;
	case 'C':
		return (float)8.30;
		break;
	case 'D':
		return (float)10.85;
		break;
	case 'E':
		return (float)6.55;
		break;
	case 'F':
		return (float)9.75;
		break;
	case 'G':
		return (float)16.00;
		break;
	case 'H':
		return (float)63.75;
		break;
	default:
		return 0;
	}
}

void f_receipt()
{
	int discount;
	float priceCombo=0, comboNum=0, govTax, serTax, subtotal, disVoucher = 0, disPrice, payable, cash, changeDue; 
	char yesNo;

	

	// Process
	int i=0;
	for(i=0; i<=5; i++)
	{
		  priceCombo += f_price(set[i])*setNum[i];
		  comboNum += setNum[i];
	}
	
	govTax = priceCombo * GOVERNMENT_TAX / 100;
	serTax = priceCombo * SERVICE_TAX / 100;
	subtotal = priceCombo + govTax + serTax;

	printf("n"
		   "t=====================================================n"
		   "t  Submit My Order n"
		   "t-----------------------------------------------------n"
		   "tSubtotal: RM %.2fn", subtotal);

	printf("tHave voucher or not (Y/N)   ? ");
	fflush(stdin);
	scanf("%c", &yesNo);
	yesNo = toupper(yesNo);

	if(yesNo == 'Y')
	{
		// Input Discount Voucher
		printf("tEnter your discount voucher > ");
		fflush(stdin);
		scanf("%f", &disVoucher);
	}
	if(disVoucher < 0 || !disVoucher){
		// Not Have Voucher can Enjoy a special discount
		if(subtotal >= 120)
			discount = 20;
		else if(subtotal >= 50)	
			discount = 5;
		else
			discount = 0;

		disPrice = subtotal * discount / 100;
		payable = subtotal - disPrice;
	
	}else{
		payable = subtotal - disVoucher;
		discount = 0;
		disPrice = 0;
	}

	printf("nnttttR E C E I P Tnn");

	// Display a4-digit Receipt Number
	receiptno++;
	printf("tReceipt No : %.4d", receiptno);

	printf("nn"
		   "t+--------------------------+---------+--------------+n"
	       "t|   Description            |  Rate   |  Amount (RM) |n"
		   "t+--------------------------+---------+--------------+n");

	f_receipt_list();

	printf("t|   Government Tax         |     %2d%% |  %9.2f   |n", GOVERNMENT_TAX, govTax);
	printf("t|   Service Tax            |     %2d%% |  %9.2f   |n", SERVICE_TAX, serTax);
	printf("t+--------------------------+---------+--------------+n"
		   "t|           S U B   T O T A L        |  %9.2f   |n"
		   "t+====================================+==============+n", subtotal);

	if(disVoucher)
		printf("t|   Discount Voucher  (RM)%9.2f                 |n", disVoucher);
	else if(subtotal >= 120)
		printf("t|   Get Free a member card                          |n");
	else if(subtotal >= 50)
		printf("t|   Get Free 1 combo set                            |n");
	else
		printf("t|   Get Free 1 drink                                |n");

	printf("t|   Discount     %2d%%  (RM)%9.2f                 |n"
		   "t|                         ----------                |n"
		   "t|   Amount Payable    (RM)%9.2f                 |n"
		   "t|                         ==========                |n", discount, disPrice, payable);
	
	// Process (Payable to the nearest 5 sen)
	payable = (float)floor(payable*20+0.5)/20;
	
	// Output
	printf("t|   Adjusted Amount Payable             %9.2f   |n"
		   "t+===================================================+n", payable);
	printf("t  Total combo set ordered : %4dn", comboNum);

	// Input & Process (Cash)
	do
	{
		printf("tttCASH               a");
		fflush(stdin);
		scanf("%f", &cash);
		if(cash < payable)
			printf("t+= Cash must be greater than Payable =+n");
	}
	while(cash < payable);

	changeDue = cash - payable;

	// Output
	printf("tttChange Due     %9.2fn", changeDue);
	f_thankyou();

	system("pause");

	// Clear Data
	for(i=0; i<=5; i++)
	{
		set[i] = 0;
		setNum[i] = 0;
		priceCombo = 0;
		comboNum = 0;
	}

}

void f_receipt_list()
{
	int i = 0;

	while(set[i])
	{
		printf("t|   %-16s * %3d | %6.2f  |  %9.2f   |n", f_comboName(set[i]),setNum[i], f_price(set[i]), f_price(set[i])*setNum[i]);
		i++;
	}
}

void f_thankyou()
{
	printf("t=====================================================n");
	printf("t            THANK YOU and HAVE A NICE DAYnnt");
}

Download: http://www.mediafire.com/?1ay0dce80x1na99