0% found this document useful (0 votes)
10 views

Assignment Intro (Premium) (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)
10 views

Assignment Intro (Premium) (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/ 12

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
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.

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 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 :

Header file 1 : 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;
}
}
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>
#include <iomanip> // For setw()
#define discount(a) a - (a * 0.1) // macro to calculate discount
using namespace std;

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();
};

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.

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 << " 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";
}

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
<< price[i] << "," // Price per Item
<< total[i]; // Total for the 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;
}
Console output:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy