Assignment Intro (Premium) (1)
Assignment Intro (Premium) (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
SUPER MARKET BILLING SYSTEM USING C++:
Abstract
Introduction
Objectives
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 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
1. 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.
2.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.
3. 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.
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;
}
}
friend class Head; // Now Head can access the private
variables/vectors of this class through an object of this class
};
#endif
class Head
{
private:
vector<string> items; // vector containing purchased
items
vector<int> price, quantity, total; // storing price of every
purchased item// quantity vector = quantity per item of a product
int inum, sn, total_amount = 0; // inum = invoice no. and sn =
serial no. of item
string name, iname, mail, pnum; // name = buyer name, iname =
item name, mail = gmail, pnum = phone number
char choice; // 'choice' that whether the
buyer want to add more items on the list or not
public:
void display(Products &p);
void display_csv();
};
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 << " Falcon Super Mart" << endl;
cout << "-----------------------------------------------------" <<
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) << "Price per item" << setw(20) << "Total" << endl;
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";
}