oop cep (1)
oop cep (1)
OOP-CEP
GROUP MEMBERS :
Name : Abdul Haseeb Baig |EE-
1672 Name : Umer Ahmed |EE-
1630 Name : Abdullah Zia |EE-1681
Class : B1-F002
Semester : 3rd
Course : Object Oriented Programing
Lecturer : Sir Mubashir Tariq
1 | Page
Table of Contents
SUPER MARKET BILLING SYSTEM USING C++ :................................................................................................................ 3
Abstract...................................................................3
Introduction................................................................3
Objectives..................................................................3
Features...................................................................4
Libraries/Header files used:....................................................4
Iostream...................................................................................................................................................................................... 4
Fstream....................................................................................................................................................................................... 4
Iomanip....................................................................................................................................................................................... 4
Vector........................................................................................................................................................................................... 4
String............................................................................................................................................................................................ 4
products.h.................................................................................................................................................................................. 5
head1.h........................................................................................................................................................................................ 5
Principles of Object Oriented Programming used....................................5
Abstraction................................................................................................................................................................................ 5
Encapsulation...............................................................5
Inheritance.................................................................5
SOURCE CODE :.............................................................6
Header file # 01 : “products.h”.......................................................................................................................................... 6
Header file 2 : head1.h.......................................................................................................................................................... 7
Main source file: “main.cpp”............................................................................................................................................ 10
Console output:..................................................................................................................................................................... 11
Printed receipt :.................................................................................................................................................................... 12
CSV File Output :................................................................................................................................................................... 13
.........................................................................14
Excel Sheet Display :........................................................................................................................................................... 14
Conclusion :...............................................................14
2 | Page
SUPER MARKET BILLING SYSTEM USING C++ :
Abstract
Introduction
The supermarket billing system is designed to streamline the checkout
process by automating calculations and maintaining detailed transaction
records. The system allows staff to quickly generate invoices and store
transaction data in a structured format, like CSV files. By leveraging C++ for
its implementation, this project ensures high performance and ease of
maintenance.
Objectives
Develop a user-friendly billing system.
Automate the generation of invoices for customers.
Maintain a record of daily transactions in a CSV file.
Provide discounts for purchases exceeding a threshold amount.
3 | Page
Features
2. Fstream
Used for exporting daily transaction data to a CSV file via the ofstream
Class
3. Iomanip
Used in our project for aligning console output in tables (e.g., setw() for
setting column widths)
4. Vector
used to store products, prices, quantities, and customer transactions
dynamically.
5. String
used for handling textual data like product names, customer details, and email
4 | Page
addresses.
6. products.h
Custom header file containing the products class. It manages the product list
and prices, and displays available stock to the user.
7. head1.h
Custom header file containing the Head class. Manages customer details,
transaction processing, invoice generation, and exporting to a CSV file.
Encapsulation
By using private and public access specifiers in our classes, we have
encapsulated the data and ensured that only relevant parts of the data (e.g.,
product list, prices) are exposed via member functions. For example, the
vectors v and prices are private in the products class, and only accessible
through its methods or friend classes.
Inheritance
Though direct inheritance is not explicitly present, the use of a friend class
(Head) demonstrates a form of cooperation between classes. If we plan to
extend this project, we could use inheritance to create specialized classes,
such as Customer inheriting from a Person class.
5 | Page
SOURCE CODE :
#ifndef Products_H
#define Products_H
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace
std;
vector<int> prices = {
50, 120, 80, 900, 30, 750, 40, 60, 100, 70, 40,
90, 110, 200, 300, 220, 250, 450, 65, 25};
public:
Products()
{
cout << line << "\n\tWelcome to Falcon Super Mart!\n"
<< line << endl;
cout << line << "\nProducts available in stock : " << endl;
cout << left << setw(15) << "Serial No." << setw(22) << "Product"
<< "price :" << endl;
cout << line << endl;
for (int i = 0; i < productNames.size(); i++)
{
cout << left << setw(15) << i + 1 << setw(22) <<
productNames[i] << left << prices[i] << endl;
}
}
6 | Page
friend class Head; // Now Head can access the private
variables/vectors of this class through an object of this class
};
#endif
7 | Page
cout << "Enter buyer name: ";
getline(cin, name);
do
{
cout << "Enter serial number of item:
"; cin >> sn;
if (sn >= 1 && sn <= p.productNames.size())
{ // Use the instance of products to access v and prices
items.push_back(p.productNames[sn - 1]);
price.push_back(p.prices[sn - 1]);
cout << "Enter quantity per item:
"; int q;
cin >> q;
quantity.push_back(q);
total.push_back(q * (p.prices[sn - 1]));
cout << "Do you want to add more items (y/n):
"; cin >> choice;
}
else
{
cout << "Invalid serial number ! Please try again" << endl;
} // the user will be prompted this again and again until he/she
enters a valid sno.
} while (choice != 'n');
// Invoice Print
cout << "Here`s your receipt : \n";
cout << " " << endl;
cout << " Falco Super Mart" << endl;
cout << " n " << endl;
cout << "Invoice Number: " << inum <<
endl; cout << "Buyer Name: " << name <<
endl;
cout << "Buyer's Phone Number: " << pnum <<
endl; cout << "Buyer`s email : " << mail <<
endl;
cout << " " << endl;
cout << "Items:" << endl;
cout << " " << endl;
cout << left << setw(15) << "Name" << setw(13) << "Quantity" << setw(20)
8 | Page
<< "Price per item" << setw(20) << "Total" << endl;
9 | Page
cout << " " << endl;
for (int i = 0; i < items.size(); i++)
{ // displaying vectors: items,quantity,price,total and calculating
final bill.
cout << left << setw(15) << items[i] << setw(14) << quantity[i] <<
setw(20) << price[i] << setw(20) << total[i] << endl;
total_amount += total[i];
}
if (total_amount > 5000)
{
cout << line << "\nCongratulations! 10% discount applied
"; cout << "\nYour total amount after discount is Rs."
<<
int(discount(total_amount)) << endl
<< line;
}
else
{
cout << line << "\nYour total amount is Rs." << total_amount << endl
<< line;
}
cout << "\nJazakALLAH for shopping from \'The Falcon Super Mart\' \n"
<< line << endl;
}
void Head::display_csv() // function to record all the
transactions in a specified file
{
ofstream out;
out.open("Table.csv", ios::app); // updating the table
containing transactions
#include <iostream>
#include "head1.h"
using namespace
std; int main()
{
Products p;
Head h1;
h1.display(p)
;
h1.display_csv()
; return 0;
}
11 | P a g e
Console output:
12 | P a g e
Printed receipt :
13 | P a g e
CSV File Output :
14 | P a g e
Excel Sheet Display :
Conclusion :
This supermarket billing system successfully automates invoice generation and
transaction recording. This project demonstrates core C++ programming skills and
practical applications of file handling and class design.
15 | P a g e