0% found this document useful (0 votes)
19 views15 pages

oop cep (1)

Uploaded by

usmanahmedboy890
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)
19 views15 pages

oop cep (1)

Uploaded by

usmanahmedboy890
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/ 15

NUST –PNEC

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

This document presents a supermarket billing system implemented in C++.


The system aims to automate the billing process in a supermarket, reducing
human errors and enhancing efficiency. Customers can select products,
specify quantities, and receive detailed invoices. Additionally, the program
exports daily transactions to a CSV file, ensuring comprehensive record-
keeping. The project demonstrates fundamental programming concepts,
including file handling, class design, and vector operations in C++.

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

 Displays an interactive product list with prices.


 Captures customer details, including name, phone number, and email.
 Allows item selection with specified quantities.
 Automatically calculates the total amount with discounts for eligible
purchases.
 Exports daily transaction details to a CSV file

Libraries/Header files used:


1. Iostream
Used for console-based I/O operations such as cin for input and cout
for displaying messages and data.

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.

Principles of Object Oriented Programming used


Abstraction
In our code, the product details and billing processes are encapsulated in
classes like products and Head. The internal implementation of how products
and prices are stored or how the bill is calculated is hidden from the user,
providing a simplified interface for interaction.

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 :

Header file # 01 : “products.h”

#ifndef Products_H
#define Products_H

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
using namespace
std;

string line = " ";


class Products
{
private:
vector<string> productNames = {
"Juice", "Milk", "Bread", "Fish", "Chips", "Cooking Oil",
"Chocolate", "Soft Drink", "Baking Soda", "Butter",
"Yogurt", "Pasta", "Donut", "Coffee", "Flour", "Sugar",
"Burger", "Pizza", "Biscuit", "Eggs"};

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

Header file 2 : head1.h


#include
"products.h"
#include <iostream>
#include <fstream>
#include <vector>
#include <string> // For
#include <iomanip> a - (a * 0.1)
#define discount(a) setw()
// macro to calculate
discount
using namespace std;
class Head
{
private:
vector<string> // vector containing purchased
items; items
vector<int> price, quantity, total; // storing price of every
purchased
item//
int quantity
inum, sn,vector = quantity
total_amount = per//item
inumof= ainvoice
productno. and sn = serial
0; no.
of item // name = buyer name, iname = item
string name, iname, mail, name,
pnum; mail = gmail, pnum = phone
number // 'choice' that whether the buyer
char choice;
public:
void display(Products &p);
void display_csv();
};

void Head::display(Products &p) // passing the reference of the object


of the class Products
{

cout << "Enter invoice number:


"; cin >> inum;
cin.ignore(); // since we are going to input a string. It will
ignore the
already existing null(\n) character in cin.

7 | Page
cout << "Enter buyer name: ";
getline(cin, name);

cout << "Enter buyer's phone number:


"; cin >> pnum;

cout << "Enter buyer's email:


"; cin >> mail;

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

// Check if the file is empty and write the header only


once if (out.tellp() == -1)
{
out << "Invoice Number,Buyer Name,Phone
Number,Email,Item,Quantity,Price per Item,Total,Total Amount\n";
}

for (int i = 0; i < items.size(); i++)


{
out << inum << "," // Invoice Number
<< name << "," // Buyer Name
<< pnum << "," // Phone Number
<< mail << "," // Email
<< items[i] << "," // Item
<< quantity[i] << "," // Quantity
10 | P a g e
<< price[i] << // Price per Item
"," // Total for the
<< total[i]; item
// Add the Total Amount only for the last
item
if (i == items.size() - 1)
{
out << "," << total_amount;
}

out << "\n";


}
} out.close(); // Explicitly closing the file

Main source file: “main.cpp”

#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

You might also like