0% found this document useful (0 votes)
6 views14 pages

OOP Project

The document outlines a Supermarket Billing System designed to improve invoice calculations and customer service through an efficient user interface. It emphasizes the importance of billing software for maintaining accurate financial records and reducing human errors. Additionally, it includes a code implementation for functionalities like item addition, bill printing, and viewing bill history.

Uploaded by

stammer784
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views14 pages

OOP Project

The document outlines a Supermarket Billing System designed to improve invoice calculations and customer service through an efficient user interface. It emphasizes the importance of billing software for maintaining accurate financial records and reducing human errors. Additionally, it includes a code implementation for functionalities like item addition, bill printing, and viewing bill history.

Uploaded by

stammer784
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

Name: Hamza Latif & Muhammad Afzal

Rollno: 03-134221-013 & 03-134221-050

Market Billing System

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.

CODE:

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdlib>
#include <windows.h> // for Sleep function
using namespace std;

// Authentication class template


template <typename T>
class Authentication
{
private:
T username;
T password;

public:
Authentication(T uname, T pass) : username(uname), password(pass) {}

bool authenticate(T uname, T pass)


{
return (username == uname && password == pass);
}
};

template <typename T>


class Bill
{
private:
T Item;
int Rate, Quantity;

public:
Bill() : Item(""), Rate(0), Quantity(0) {}

// Overloaded setItem functions


void setItem(T item)
{
Item = item;
}

void setItem(T item, int rate)


{
Item = item;
Rate = rate;
}

// Overloaded setRate functions


void setRate(int rate)
{
Rate = rate;
}

void setRate(int rate, int quant)


{
Rate = rate;
Quantity = quant;
}

void setQuant(int quant)


{
Quantity = quant;
}
T getItem()
{
return Item;
}

int getRate()
{
return Rate;
}

int getQuant()
{
return Quantity;
}
};

template <typename T>


void addItem(Bill<T>& b)
{
bool close = false;
while (!close)
{
int choice;
cout << "\t1.Add." << endl;
cout << "\t2.close." << endl;
cout << "\tEnter Choice: ";
cin >> choice;

if (choice == 1)
{
system("cls");
T item;
int rate, quant;

cout << "\tEnter Item Name: ";


cin >> item;
cout << "\tEnter Rate Of Item: ";
cin >> rate;
cout << "\tEnter Quantity Of Item: ";
cin >> quant;

// Using the overloaded setItem function


b.setItem(item, rate);
b.setQuant(quant);

ofstream out("Bill.txt", ios::app);


ofstream history("BillHistory.txt", ios::app); // Append to
BillHistory.txt
if (!out || !history) {
cout << "\tError: File Can't Open!" << endl;
}
else
{
out << "\t" << b.getItem() << " : " << b.getRate() << " :
" << b.getQuant() << endl << endl;
history << "\t" << b.getItem() << " : " << b.getRate()
<< " : " << b.getQuant() << endl << endl; // Append to BillHistory.txt
}
out.close();
history.close();
cout << "\tItem Added Successfully" << endl;
Sleep(3000);
}
else if (choice == 2)
{
system("cls");
close = true;
cout << "\tBack To Main Menu!" << endl;
Sleep(3000);
}
}
}

void printBill()
{
system("cls");
int count = 0;
bool close = false;
while (!close)
{
system("cls");
int choice;
cout << "\t1.Add Bill." << endl;
cout << "\t2.Close Session." << endl;
cout << "\tEnter Choice: ";
cin >> choice;

if (choice == 1)
{
string item;
int quant;
cout << "\tEnter Item: ";
cin >> item;
cout << "\tEnter Quantity: ";
cin >> quant;

ifstream in("Bill.txt");
ofstream out("BillTemp.txt");

string line;
bool found = false;

while (getline(in, line))


{
stringstream ss;
ss << line;
string itemName;
int itemRate, itemQuant;
char delimiter;
ss >> itemName >> delimiter >> itemRate >> delimiter
>> itemQuant;

if (item == itemName)
{
found = true;
if (quant <= itemQuant)
{
int amount = itemRate * quant;
cout << "\t Item | Rate | Quantity | Amount"
<< endl;
cout << "\t" << itemName << "\t " <<
itemRate << "\t " << quant << "\t " << amount << endl;
int newQuant = itemQuant - quant;
itemQuant = newQuant;
count += amount;

out << "\t" << itemName << " : " <<


itemRate << " : " << itemQuant << endl;
}
else
{
cout << "\tSorry, " << item << " Ended!"
<< endl;
}
}
else
{
out << line << endl;
}
}
if (!found)
{
cout << "\tItem Not Available!" << endl;
}
out.close();
in.close();
remove("Bill.txt");
rename("BillTemp.txt", "Bill.txt");
}
else if (choice == 2)
{
close = true;
cout << "\tCounting Total Bill" << endl;
}
Sleep(3000);
}
system("cls");
cout << endl << endl;
cout << "\t Total Bill ----------------- : " << count << endl << endl;
cout << "\tThanks For Shopping!" << endl;
Sleep(5000);
}

void viewBillHistory() // Function to view bill history


{
system("cls");
ifstream history("BillHistory.txt");
if (!history) {
cout << "\tError: File Can't Open!" << endl;
return;
}
string line;
cout << "\tBill History:" << endl;
while (getline(history, line))
{
cout << "\t" << line << endl;
}
history.close();
cout << "\tEnd of Bill History." << endl;
system("pause");
}
int main()
{
Authentication<string> auth("admin", "password"); // Change the username
and password as needed

string username, password;


cout << "Enter Username: ";
cin >> username;
cout << "Enter Password: ";
cin >> password;

if (auth.authenticate(username, password))
{
Bill<string> b;

bool exit = false;


while (!exit)
{
system("cls");
int val;

cout << "\tWelcome To Super Market Billing System" << endl;


cout << "\t**" << endl;
cout << "\t\t1.Add Item." << endl;
cout << "\t\t2.Print Bill." << endl;
cout << "\t\t3.View Bill History." << endl; // Added option to
view bill history
cout << "\t\t4.Exit." << endl;
cout << "\t\tEnter Choice: ";
cin >> val;

if (val == 1)
{
system("cls");
addItem(b);
Sleep(3000);
}
else if (val == 2)
{
printBill();
}
else if (val == 3)
{
viewBillHistory(); // Call the function to view bill history
}
else if (val == 4)
{
system("cls");
exit = true;
cout << "\tGood Luck!" << endl;
Sleep(3000);
}
}
}
else
{
cout << "Authentication failed. Exiting program." << endl;
Sleep(3000);
}
system("pause");
return 0;
}

You might also like