In this project, we will see how to build the billing system of supermarkets project using C++ programming language.
Introduction:
This billing system in supermarkets is a straightforward console programme written in C++ with no visuals. This project will teach you how to utilise the stream class and how to handle files in the C++ programming language.
This project has two classes, class amount and class item, with class amount inheriting from class item.
About Project:
There are only a few features, the project is quite straightforward to comprehend. To understanding the source code will provide you an idea of how to operate with files, for example add , remove, update, and search data or information inside and outside of them.
The following are the project's main features:
Details of the object to be displayed: While adding an item, this feature allows users to see the products and the data associated with them.
Tools Used using project:
I used Dev C++ IDE or you can use any IDE which is suitable to you.
Implementation of Billing System of Supermarket:
Step 1. Create a new Project in Dev C++.
File > New > Source File or Ctrl + N |
Step 2. First of all we will include all Header file which will use in project.
#include<iostream> #include<windows.h> #include<conio.h> #include<fstream> #include<cstring> #include<cstdio> #include<cstdlib> #include<iomanip> |
Step 3. Add the following line below header file:
using namespace std; |
The using namespace statement simply implies that in the scope in which it is present, all items in the std namespace are available without needing to prefix them with std::
Step 4. Initialize the global variables:
int k=7,r=0,flag=0; |
Step 5. Next, we will make the coord globally accessible and a gotoxy() function with two integer parameters x and y.
These are definitions of global variables, together with initialisation from some literal values for the first two.
COORD coord = {0, 0}; void gotoxy(int x, int y) { COORD coord; coord.X = x; coord.Y = y; SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); } |
Step 6. Now, create a structure for date with following date pattern
struct date { int mm,dd,yy; }; |
Step 7. Now create the I/o Stream and Associate with actual files
It used to read any input or write any output, open the file streams and associate them with the actual files:
ofstream fout; |
Step 8. Now we will create a class (Product) and add the following functions:
Functions is for add() , show(), report(), retno().
|
Step 9: Now we will create a new class (Amount) which inherit the product class and return the net amount and add the code be like:
class amount: public Product { float price,qty,tax,gross,dis,netamt; public: void add(); void show(); void report(); void calculate(); void pay(); float retnetamt() { return(netamt); } } amt; |
Step 10. In next step, we use :: (Scope Resolution operator).
It is to access the data memeber add() of the class Amount(). when used without any specifier, it access the global variable.
void amount::add() { Product::add(); cout<<"\n\n\tPrice: "; cin>>price; cout<<"\n\n\tQuantity: "; cin>>qty; cout<<"\n\n\tTax percent: "; cin>>tax; cout<<"\n\n\tDiscount percent: "; cin>>dis; calculate(); fout.write((char *)&amt,sizeof(amt)); fout.close(); } |
void amount::calculate() { gross=price+(price*(tax/100)); netamt=qty*(gross-(gross*(dis/100))); } |
Code for amount()::show()
void amount::show() { fin.open("Productstore.dat",ios::binary); fin.read((char*)&amt,sizeof(amt)); Product::show(); cout<<"\n\n\tNet amount: "; cout< fin.close(); } |
void amount::report() { Product::report(); gotoxy(23,k); cout< gotoxy(33,k); cout< gotoxy(44,k); cout< gotoxy(52,k); cout< gotoxy(64,k); cout< k=k+1; if(k==50) { gotoxy(25,50); cout<<"PRESS ANY KEY TO CONTINUE..."; getch(); k=7; system("cls"); gotoxy(30,3); cout<<" Product DETAILS "; gotoxy(3,5); cout<<"NUMBER"; gotoxy(13,5); cout<<"NAME"; gotoxy(23,5); cout<<"PRICE"; gotoxy(33,5); cout<<"QUANTITY"; gotoxy(44,5); cout<<"TAX"; gotoxy(52,5); cout<<"DEDUCTION"; gotoxy(64,5); cout<<"NET AMOUNT"; } } |
void amount::pay() { show(); cout<<"\n\n\n\t\t*********************************************"; cout<<"\n\t\t PRODUCT DETAILS "; cout<<"\n\t\t*********************************************"; cout<<"\n\n\t\tPRICE :"< cout<<"\n\n\t\tQUANTITY :"< cout<<"\n\t\tTAX PERCENTAGE :"< cout<<"\n\t\tDISCOUNT PERCENTAGE :"< cout<<"\n\n\n\t\tNET AMOUNT :Rs."< cout<<"\n\t\t*********************************************"; } |
Step 11. Finally we will add main method for run the project
A special function is the primary function. A function called main is required in every C++ application. It acts as the program's starting point. The computer will begin running the code from the main function's beginning.
int main() { cout.setf(ios::fixed); cout.setf(ios::showpoint); cout< fstream tmp("temp.dat",ios::binary|ios::out); menu: system("cls"); gotoxy(25,2); cout<<"BILLING SYSTEM IN SUPER MARKETS "; gotoxy(25,3); cout<<"*******************************\n\n"; cout<<"\n\t\t1.Bill Report\n\n"; cout<<"\t\t2.Add/Remove/Edit Item\n\n"; cout<<"\t\t3.Show Product Details\n\n"; cout<<"\t\t4.Exit\n\n"; cout<<"\t\tPlease Enter Required Option: "; int ch,ff; float gtotal; cin>>ch; switch(ch) { case 1: ss: system("cls"); gotoxy(25,2); cout<<"Bill Details"; gotoxy(25,3); cout<<"================\n\n"; cout<<"\n\t\t1.All Products\n\n"; cout<<"\t\t2.Back to Main menu\n\n"; cout<<"\t\tPlease Enter Required Option: "; int cho; cin>>cho; if(cho==1) { system("cls"); gotoxy(30,3); cout<<" BILL DETAILS "; gotoxy(3,5); cout<<"Product NO"; gotoxy(13,5); cout<<"NAME"; gotoxy(23,5); cout<<"PRICE"; gotoxy(33,5); cout<<"QUANTITY"; gotoxy(44,5); cout<<"TAX %"; gotoxy(52,5); cout<<"DISCOUNT %"; gotoxy(64,5); cout<<"NET AMOUNT"; fin.open("Productstore.dat",ios::binary); if(!fin) { cout<<"\n\nFile Not Found..."; goto menu; } fin.seekg(0); gtotal=0; while(!fin.eof()) { fin.read((char*)&amt,sizeof(amt)); if(!fin.eof()) { amt.report(); gtotal+=amt.retnetamt(); ff=0; } if(ff!=0) gtotal=0; } gotoxy(17,k); cout<<"\n\n\n\t\t\tGrand Total="< getch(); fin.close(); } if(cho==2) { goto menu; } goto ss; case 2: db: system("cls"); gotoxy(25,2); cout<<"Bill Editor"; gotoxy(25,3); cout<<"=================\n\n"; cout<<"\n\t\t1.Add Product Details\n\n"; cout<<"\t\t2.Edit Product Details\n\n"; cout<<"\t\t3.Delete Product Details\n\n"; cout<<"\t\t4.Back to Main Menu "; int apc; cin>>apc; switch(apc) { case 1: fout.open("Productstore.dat",ios::binary|ios::app); amt.add(); cout<<"\n\t\tProduct Added Successfully!"; getch(); goto db;
case 2: int ino; flag=0; cout<<"\n\n\tEnter Product Number to be Edited :"; cin>>ino; fin.open("Productstore.dat",ios::binary); fout.open("Producttore.dat",ios::binary|ios::app); if(!fin) { cout<<"\n\nFile Not Found..."; goto menu; } fin.seekg(0); r=0; while(!fin.eof()) { fin.read((char*)&amt,sizeof(amt)); if(!fin.eof()) { int x=amt.Product::retno(); if(x==ino) { flag=1; fout.seekp(r*sizeof(amt)); system("cls"); cout<<"\n\t\tCurrent Details are\n"; amt.show(); cout<<"\n\n\t\tEnter New Details\n"; amt.add(); cout<<"\n\t\tItem Details editted"; } } r++; } if(flag==0) { cout<<"\n\t\tProduct No does not exist...Please Retry!"; getch(); goto db; } fin.close(); getch(); goto db;
case 3: flag=0; cout<<"\n\n\tEnter Product Number to be deleted :"; cin>>ino; fin.open("Productstore.dat",ios::binary); if(!fin) { cout<<"\n\nFile Not Found..."; goto menu; } //fstream tmp("temp.dat",ios::binary|ios::out); fin.seekg(0); while(fin.read((char*)&amt, sizeof(amt))) { int x=amt.Product::retno(); if(x!=ino) tmp.write((char*)&amt,sizeof(amt)); else { flag=1; } } fin.close(); tmp.close(); fout.open("Productstore.dat",ios::trunc|ios::binary); fout.seekp(0); tmp.open("temp.dat",ios::binary|ios::in); if(!tmp) { cout<<"Error in File"; goto db; } while(tmp.read((char*)&amt,sizeof(amt))) fout.write((char*)&amt,sizeof(amt)); tmp.close(); fout.close(); if(flag==1) cout<<"\n\t\tProduct Succesfully Deleted"; else if (flag==0) cout<<"\n\t\tProduct does not Exist! Please Retry"; getch(); goto db; case 4: goto menu; default: cout<<"\n\n\t\tWrong Choice!!! Retry"; getch(); goto db; } case 3: system("cls"); flag=0; int ino; cout<<"\n\n\t\tEnter Product Number :"; cin>>ino; fin.open("Productstore.dat",ios::binary); if(!fin) { cout<<"\n\nFile Not Found...\nProgram Terminated!"; goto menu; } fin.seekg(0); while(fin.read((char*)&amt,sizeof(amt))) { int x=amt.Product::retno(); if(x==ino) { amt.pay(); flag=1; break; } } if(flag==0) cout<<"\n\t\tProduct does not exist....Please Recheck the Product details..!"; getch(); fin.close(); goto menu; case 4: system("cls"); gotoxy(20,20); cout<<"ARE YOU SURE, YOU WANT TO EXIT (Y/N)?"; char yn; cin>>yn; if((yn=='Y')||(yn=='y')) { gotoxy(12,20); system("cls"); cout<<"###################HAVE A NICE DAY###################"; getch(); exit(0); } else if((yn=='N')||(yn=='n')) goto menu; else { goto menu; } default: cout<<"\n\n\t\tWrong Choice....Please Retry!"; getch(); goto menu; } return 0; } |
Run your project and you will get following output:
Conclusion: In this project we have covered how to build Billing System in Supermarkets using C++ programming language.
Article Contributed By :
|
|
|
|
5196 Views |