NUST – PNEC
Assignment 01
Name : Abdul Haseeb Baig |EE-1672
Abdullah Zia |EE-1681
Umer Ahmed |EE-1630
Class : B1-F102
Semester : 2nd
Course : Fundamentals of Programming
Lecturer : Sir Mubashir Tariq
Super Market
Billing System
Using C++
Algorithm
Step 1: Start
Step 2: Declare a structure Item with members name (string),
quantity (int), and price (double)
Step 3: Declare a function calculate TotalPrice that takes a
vector of Item objects as input and returns a double
Step 4: Inside calculate TotalPrice function, initialize total as
0.0
Step 5:Iterate over each item in the items vector
Step 6: Inside the loop, calculate the total price as quantity*
price and add it to total
Step 7: Return the total
Step & Declare a function displayInvoice that takes
invoiceNumber (int), buyerName (string),
buyerAddress (string), and items (vector of Item) as input
and returns void
Step 9: Inside displayInvoice function, output invoice details
and items in a formatted invoice format
Step 10: Inside the main function, declare variables
invoiceNumber, buyerName, buyerAddress, and
items (vector of Item)
Step 11: Prompt the user to input invoiceNumber,
buyerName, and buyerAddress
Step 12: Declare a variable addMoreltems (char)
Step 13: Start a do-while loop to input items until the user
does not want to add more items
Step 14: Inside the loop, prompt the user to in tem details
and add the item to the items vector
Step 15: Prompt the user to ask if he/she wants to add more
items
Step 16: If yes, repeat the steps 12 to 15 until the user
doesn`t want to add more items and presses “n”.
Step 17: Call displayInvoice function with provided inputs
Step 18: Output invoice details and items in a formatted
invoice format
Step 19: Stop
FlowCHART
Code
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Item {
string name;
int quantity;
double price;
};
double calculateTotalPrice(const vector<Item>& items) {
double total = 0.0;
for (const Item& item : items) {
total += item.quantity * item.price;
return total;
void displayInvoice(int invoiceNumber, const string& buyerName, const string& buyerAddress, const
vector<Item>& items) {
cout << "--------------------------------------------" << endl;
cout << " Falcon Super Mart" << endl;
cout << "--------------------------------------------" << endl;
cout << "Invoice Number: " << invoiceNumber << endl;
cout << "Buyer Name: " << buyerName << endl;
cout << "Buyer Address: " << buyerAddress << endl;
cout << "--------------------------------------------" << endl;
cout << "Items:" << endl;
cout << "--------------------------------------------" << endl;
cout << "Name\t\tQuantity\tPrice\tTotal" << endl;
cout << "--------------------------------------------" << endl;
for (const Item& item : items) {
cout << item.name << " \t\t " << item.quantity << " \t\t\t " << item.price << " \t\t " << item.quantity
* item.price << endl;
cout << "--------------------------------------------" << endl;
cout << "Total Price: " << calculateTotalPrice(items) << endl;
cout << "--------------------------------------------" << endl;
int main() {
int invoiceNumber;
string buyerName, buyerAddress;
vector<Item> items;
cout << " Welcome to Falcon Super Mart "<<endl;
cout <<"\n";
cout << "Enter Invoice Number: ";
cin >> invoiceNumber;
cin.ignore();
cout << "Enter Buyer Name: ";
getline(cin, buyerName);
cout << "Enter Buyer Address: ";
getline(cin, buyerAddress);
char addMoreItems;
do {
Item newItem;
cout << "Enter Name of Item: ";
getline(cin, newItem.name);
cout << "Enter Quantity: ";
cin >> newItem.quantity;
cout << "Enter Price per Item: ";
cin >> newItem.price;
items.push_back(newItem);
cout << "Do you want to add more items? (y/n): ";
cin >> addMoreItems;
cin.ignore();
} while (addMoreItems == 'y' || addMoreItems == 'Y');
displayInvoice(invoiceNumber, buyerName, buyerAddress, items);
return 0;