Billing Management System In C++

Project for Billing a Supermarket in C++ with Source Code - This C++ grocery store billing system is a straightforward console program without any visuals. You will learn how to use the stream class and manage files in the C++ programming language with this project.

What is exactly a Supermarket Bill?

The supermarket billing system is intended to help supermarkets calculate and show invoices, as well as provides faster and more effective customer service. The user interface of this software solution is both efficient and user-friendly, helping staff members with customer service and bill calculation.

Why does Supermarket need a billing system?

They can keep their money in order since billing software is one of the greatest options for all kinds of grocery store enterprises. A good billing program can retain accurate financial records and eliminate human data entry mistakes.

What Functions Do Supermarket Billing Systems Serve?

By ensuring that the billing system is transparent and that the precise amount has been stated for the purchases, the supermarket billing system helps to preserve a good connection between the customer and the shop management. It enables and guarantees consumer payment.

Import the Necessary Libraries

Identifying the C++ libraries that our software will require as a first step. At the commencement of the presentation, these will be given. The header files are imported using #include from a library, iostream is the first library that our app needs. We'll use this library to manage our Supermarket Billing Project using C++ basic input and output.

Program Breakdown

Example

# include < iostream >
# include < process.h >
# include < fstream >
# include < stdlib.h >

We will import all the necessary libraries to avoid any kind of errors.

Example

class head
{
	char Iname [ 50 ] [ 50 ] ;
public :
	int totalitems ;
	float Qty [ 3 ] ;
	float price [ 3 ] ;
	int vatprice [ 3 ] ;
	int tprice [ 3 ] ;
	void input ( ) ;
	void output ( ) ;
} ;

In the above peace of code we have created a head class having the member function name, total items, quantity, price, input and output.

Example

class vat : public head
{
	float vats ;
public :
	void vatcal ( ) ;
	void outputs ( ) ;
	void sum ( ) ;
} ;

In the above peace of code we have derived a class vat which is inherited from the class head.

Example

void head : : input ( )
{
	system ( " CLS " ) ;
	cout << " \ nEnter number of items = " ;
	cin >> totalitems ;
	for ( int i = 0 ; i < totalitems ; i + + )
	{
		cout << " \ n Enter name of item " << i + 1 << " : " ;
		cin >> Iname [ i ] ;
		cout << " Enter quantity : " ;
		cin >> Qty [ i ] ;
		cout << " Enter price of item " << i + 1 << " : " ;
		cin >> price [ i ] ;
		tprice [ i ] = Qty [ i ] * price [ i ] ;
	}
}

In the above peace, it will responsible for the input like add the number of items, name of the items, enter the quantity of the item and enter the price for it.

Example

void head : : output ( )
{
	int a ;
	ifstream infile ( " COUNT . TXT " ) ;
	infile >> a ;
	ofstream outfile ( " COUNT . TXT " ) ;
	a + = 1 ;
	outfile << a ;
	outfile . close ( ) ;
	{ ofstream outfile ( " HIS . TXT " , ios : : app ) ;
	outfile << endl << " Bill No . : " << a << endl ;
	outfile << " ------------------------------------------------------------------------ " << endl ;
cout << " \ n " ;
	cout << " Name of Item \ t Quantity Price Total Price \ n " ;
	for ( int i = 0 ; i < totalitems ; i + + )
	{
		outfile << " Name : " << Iname [ i ] << " Qty : " << Qty [ i ] << " Price : " << tprice [ i ] << endl ;
		cout << Iname [ i ] << " \ t \ t " << Qty [ i ] << " \ t " << price [ i ] << " \ t " << tprice [ i ] << ' \ n ' ;
	}
	outfile << " ------------------------------------------------------------------------ " << endl ;
	outfile . close ( ) ;
	}
}

The above peace of code is responsible to display the the items entered by the user.

Example

void vat : : vatcal ( )
{
	input ( ) ;
	for ( int i = 0 ; i < totalitems ; i + + )
	{
		if ( price [ i ] < = 100.00 )
		{
			vatprice [ i ] = tprice [ i ] + ( 0.03 * tprice [ i ] ) ;
		}
		else
		{
			vatprice [ i ] = tprice [ i ] + ( 0.1 * tprice [ i ] ) ;
		}
	}
} void vat : : vatcal ( )
{
	input ( ) ;
	for ( int i = 0 ; i < totalitems ; i + + )
	{
		if ( price [ i ] < = 100.00 )
		{
			vatprice [ i ] = tprice [ i ] + ( 0.03 * tprice [ i ] ) ;
		}
		else
		{
			vatprice [ i ] = tprice [ i ] + ( 0.1 * tprice [ i ] ) ;
		}
	}
}

The above peace of code is use to calculate the amount of the items that the user has entered.

Example

void vat : : outputs ( )
{
	output ( ) ;

	float cash = 0 , sum = 0 , qty = 0 , sumt = 0 ;

	for ( int i = 0 ; i < totalitems ; i + + )
	{
	       sumt + = tprice [ i ] ;
		 sum + = vatprice [ i ] ;
		 qty + = Qty [ i ] ;
	}
	cout << " \ n Total : " ; 
	cout << " \ n ------------------------------------------------------------------------------ " ;
	cout << " \ n \ t Quantity = " << qty << " \ t \ t Sum = " << sumt << " \ tWith Vat : " << sum ;
	cout << " \ n------------------------------------------------------------------------------ " ;

pay :

	cout << " \ n \ n \ t \ t \ t **** PAYMENT SUMMARY **** \ n " ;
	cout << " \ n \ t \ t \ t Total cash given : " ;
	cin >> cash ;

	if ( cash > = sum )
		cout << " \ n \ t \ t \ t Total cash repaid : " << cash-sum << ' \ n ' ;
		
	else
	{	cout << " \ n \ t \ t \ t Cash given is less than total amount!!! " ;

	goto pay ;
	}
}

The above peace of code is used to show the calculated price of the items entered by the user.

Example

int passwords ( )
{

	char p1 , p2 , p3 ;

	cout << " \ n  \ n \ n \ n \ n \ n \ t \ t \ t ENTER THE PASSWORD : " ;

	cin >> p1 ;
	cout << " * " ;
	cin >> p2 ;
	cout << " * " ;
	cin >> p3 ;
	cout << " * " ;

	if ( ( p1 == ' s ' || p1 == ' S ' ) && ( p2 == ' i ' || p2 == ' I ' ) && ( p3 == ' d ' || p3 == ' D ' ) )

		return 1 ;

	else
		return 0 ;
}

The above peace of code will help the user to enter the password in the billing system. This will help the user to maintain the security of the supermarket billing system.

Example

int main ( )
{
	vat obj ;
	char opt , ch ;
	int a = 1 ;
	ifstream fin ;

	a==passwords ( ) ;
	if ( ! a )
	{
		for ( int i = 0 ; i < 2 ; i + + )
		{
			cout << " \ n Wrong password try once more \ n " ;
			if ( passwords ( ) ) 
			{
				goto last ;
			}
			else
			{
				cout << " \ n \ n \ t \ t \ t all attempts failed ..... " ;
				cout << " \ n \ n \ n \ t \ t \ t see you .................. " ;
				exit ( 0 ) ;
			}

		}
		cout << " \ t \ t \ t sorry all attempts failed ............. \ n \ t \ t \ t inactive " ;
			 }

The above code will be the driver code of our supermarket billing system. In which the user will be asked to enter the password. If the password entered by the user is wrong then it will say wrong password try again.

Example

else {
last : ;
	 do {
start :
	system ( " PAUSE " ) ;
	system ( " CLS " ) ;
	cout << " \ n \ n \ t \ t \ t ------------------------------ " ;
	cout << " \ n \ t \ t \ t Billing Management System " ;
	cout << " \ n \ t \ t \ t ------------------------------ " ;
	 cout <<"\n\n\t\t\tWhat you want to do?";
	 cout<<"\n\t\t\t1.\tTo enter new entry\n\t\t\t2.\tTo view previous entries\n\t\t\t3.\tExit\n";
	 cout<<"\n\nEnter your option: ";
	 cin>>opt;

If the user entered the correct password then the above loop while come in action.

Example

switch ( opt )
	 {
	 case ' 1 ' :
		 obj . vatcal ( ) ;

		 obj . outputs ( ) ;
		 goto start ;
	 case ' 2 ' :

		 fin . open ( " HIS . TXT " , ios : : in ) ;
		 while ( fin . get ( ch ) )
		 {
			 cout << ch ;
		 }
		 fin . close ( ) ;

		 goto start ;
	 case ' 3 ' : 
		 exit ( 0 ) ;
	 default :
		 cout << " \ a " ;
	 }

	 } while ( opt ! = 3 ) ;
	}
	return 0 ;
}

The above loop will run according the option selected by the user.

Program for Supermarket Billing System

Example

#include<iostream>
#include<process.h>
#include<fstream>
#include <stdlib.h>
using namespace std;
class head
{
	char Iname[50][50];

public:
	int totalitems;
	float Qty[3];
	float price[3];
	int vatprice[3];
	int tprice[3];
	void input();
	void output();
};
class vat:public head
{
	float vats;
public:
	void vatcal();
	void outputs();
	void sum();
};

//******************************************************************
//	    INPUT FUNCTION
//******************************************************************

void head::input()
{
	system("CLS");
	cout<<"\nEnter number of items= ";
	cin>>totalitems;

	for(int i=0; i<totalitems; i++)
	{
		cout<<"\nEnter name of item "<<i+1<<": ";
		cin>>Iname[i];
		cout<<"Enter quantity: ";
		cin>>Qty[i];
		cout<<"Enter price of item "<<i+1<<": ";
		cin>>price[i];
		tprice[i]=Qty[i]*price[i];
	}
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//	   OUTPUT FUNCTION
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
void head::output()
{
	int a;

	ifstream infile("COUNT.TXT");
	infile>>a;

	ofstream outfile("COUNT.TXT");
	a+=1;
	outfile<<a;
	outfile.close();

	{ofstream outfile("HIS.TXT", ios::app);
	outfile<<endl<<"Bill No.: "<<a<<endl;
	outfile<<"------------------------------------------------------------------------"<<endl;
cout<<"\n";
	cout<<"Name of Item\tQuantity   Price  Total Price\n";
	for(int i=0;i<totalitems;i++)
	{
		outfile<<"Name: "<<Iname[i]<<" Qty: "<<Qty[i]<<" Price: "<<tprice[i]<<endl;
		cout<<Iname[i]<<"\t\t"<<Qty[i]<<"\t   "<<price[i]<<"\t   "<<tprice[i]<<'\n';
	}

	outfile<<"------------------------------------------------------------------------"<<endl;
	outfile.close();
	}
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//	   VAT CALCULATION
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
void vat::vatcal()
{
	input();
	for(int i=0;i<totalitems;i++)
	{
		if(price[i]<=100.00)
		{
			vatprice[i]=tprice[i]+(0.03*tprice[i]);
		}
		else
		{
			vatprice[i]=tprice[i]+(0.1*tprice[i]);
		}
	}
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//	    VAT OUTPUTS
//*  * * * * * * * * * * * * * * * * * * * * ** * * * * * * * * * * * * * * * * * * * * * * * * *  
void vat::outputs()
{
	output();

	float cash=0,sum=0,qty=0,sumt=0;

	for(int i=0;i<totalitems;i++)
	{
	       sumt+=tprice[i];
		   sum+=vatprice[i];
		   qty+=Qty[i];
	}
	cout<<"\nTotal:";
	cout<<"\n------------------------------------------------------------------------------";
	cout<<"\n\tQuantity= "<<qty<<"\t\t Sum= "<<sumt<<"\tWith Vat:"<<sum;
	cout<<"\n------------------------------------------------------------------------------";

pay:

	cout<<"\n\n\t\t\t * * * * PAYMENT SUMMARY * * * * \n";
	cout<<"\n\t\t\tTotal cash given: ";
	cin>>cash;

	if(cash>=sum)
		cout<<"\n\t\t\tTotal cash repaid: "<<cash-sum<<'\n';
		
	else
	{	cout<<"\n\t\t\tCash given is less than total amount!!!";

	goto pay;
	}
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 
//	    PROTECTION PASSWORD
//* * * * * * * * * * * *  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * 

int passwords()
{

	char p1,p2,p3;

	cout<<"\n\n\n\n\n\n\t\t\tENTER THE PASSWORD: ";

	cin>>p1;
	cout<<"*";
	cin>>p2;
	cout<<"*";
	cin>>p3;
	cout<<"*";

	if ((p1=='s'||p1=='S')&&(p2=='i'||p2=='I')&&(p3=='d'||p3=='D'))

		return 1;

	else
		return 0;
}
// END of Password.

//****************************************************************
//    	THE MAIN FUNCTION OF PROGRAM
//****************************************************************

int main()
{
	vat obj;
	char opt, ch;
	int a=1;
	ifstream fin;

	a==passwords();
	if(!a)
	{
		for(int i=0;i<2;i++)
		{
			cout<<"\nWrong password try once more\n";
			if(passwords())
			{
				goto last;
			}
			else
			{
				cout<<"\n\n\t\t\t all attempts failed.....";
				cout<<"\n\n\n\t\t\t see you.................. ";
				exit(0);
			}

		}
		cout<<"\t\t\t sorry all attempts failed............. \n \t\t\tinactive";
			 }
	else{
last:; 
	 do{
start:
	system("PAUSE");
	system("CLS");
	cout<<"\n\n\t\t\t------------------------------";
	cout<<"\n\t\t\tBilling Management System";
	cout<<"\n\t\t\t------------------------------";
	 cout<<"\n\n\t\t\tWhat you want to do?";
	 cout<<"\n\t\t\t1.\tTo enter new entry\n\t\t\t2.\tTo view previous entries\n\t\t\t3.\tExit\n";
	 cout<<"\n\nEnter your option: ";
	 cin>>opt;
	 switch(opt)
	 {
	 case'1':
		 obj.vatcal();

		 obj.outputs();
		 goto start;
	 case'2':

		 fin.open("HIS.TXT", ios::in);
		 while(fin.get(ch))
		 {
			 cout<<ch;
		 }
		 fin.close();

		 goto start;
	 case'3':
		 exit(0);
	 default:
		 cout<<"\a";
	 }

	 }while(opt!=3);
	}
	return 0;
}

Output:

Output

ENTER THE PASSWORD: 123
***Press any key to continue . . .
                       ---------------------------------------
                        Billing Management System
                        ---------------------------------------
                        What you want to do?
                        1.      To enter new entry
                        2.      To view previous entries
                        3.      Exit
Enter your option: 1

Enter number of items= 3
Enter name of item 1: Vegetables
Enter quantity: 1kg
Enter price of item 1:
Enter name of item 2: Enter quantity: Enter price of item 2:
Enter name of item 3: Enter quantity: Enter price of item 3:
Name of Item    Quantity   Price  Total Price
Vegetables              1          0       0
                0          1.4013e-045     0
                1.13027e-038       0       0

Total:
------------------------------------------------------------------------------
        Quantity= 1              Sum= 0 With Vat:0
------------------------------------------------------------------------------

                        ****PAYMENT SUMMARY****

                        Total cash given:
                        Total cash repaid: 0
Press any key to continue . . .

Input Required

This code uses input(). Please provide values below: