0% found this document useful (0 votes)
8 views2 pages

CS201 Assignment1 Solution Updated

The document is a C++ program that prompts the user for their VU ID and extracts a numeric part to determine quantities of food items ordered. It calculates subtotals based on predefined prices and applies a discount if the total bill exceeds 5000. Finally, it displays a detailed billing summary including quantities, prices, subtotals, total before discount, discount amount, and the final payable amount.

Uploaded by

zul676322
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

CS201 Assignment1 Solution Updated

The document is a C++ program that prompts the user for their VU ID and extracts a numeric part to determine quantities of food items ordered. It calculates subtotals based on predefined prices and applies a discount if the total bill exceeds 5000. Finally, it displays a detailed billing summary including quantities, prices, subtotals, total before discount, discount amount, and the final payable amount.

Uploaded by

zul676322
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <iostream>

#include <string>
using namespace std;

int main() {
// Hard-coded Name and VU ID
string name = "Muhammad Zulqarnain Haider";
string vuID = "BC240400720";

cout << "Name: " << name << endl;


cout << "VU ID: " << vuID << endl;

// Asking user to enter numeric part


string numericPart;
cout << "\nEnter the numeric part of your VU ID (9 digits): ";
cin >> numericPart;

if (numericPart.length() != 9) {
cout << "Invalid input! Please enter exactly 9 digits." << endl;
return 1;
}

// Extract 5 digits (remove 2 from left and right)


string extracted = numericPart.substr(2,5);

cout << "\nExtracted Digits: " << extracted << endl;

// Quantities
int quantityBurger = extracted[0] - '0';
int quantityPizza = extracted[1] - '0';
int quantityFries = extracted[2] - '0';
int quantitySandwich = extracted[3] - '0';
int quantityDrink = extracted[4] - '0';

// Prices
int priceBurger = 500;
int pricePizza = 1000;
int priceFries = 300;
int priceSandwich = 700;
int priceDrink = 100;

// Subtotals
int subtotalBurger = quantityBurger * priceBurger;
int subtotalPizza = quantityPizza * pricePizza;
int subtotalFries = quantityFries * priceFries;
int subtotalSandwich = quantitySandwich * priceSandwich;
int subtotalDrink = quantityDrink * priceDrink;

// Total Bill
int totalBill = subtotalBurger + subtotalPizza + subtotalFries + subtotalSandwich + subtota

// Discount
double discount = 0;
if (totalBill >= 5000) {
discount = totalBill * 0.10;
}

double finalAmount = totalBill - discount;

// Billing Details
cout << "\n--- Billing Details ---\n";
cout << "Item\t\tQuantity\tPrice\tSubtotal\n";
cout << "Burger\t\t" << quantityBurger << "\t\t" << priceBurger << "\t" << subtotalBurger <
cout << "Pizza\t\t" << quantityPizza << "\t\t" << pricePizza << "\t" << subtotalPizza << en
cout << "Fries\t\t" << quantityFries << "\t\t" << priceFries << "\t" << subtotalFries << en
cout << "Sandwich\t" << quantitySandwich << "\t\t" << priceSandwich << "\t" << subtotalSand
cout << "Cold Drink\t" << quantityDrink << "\t\t" << priceDrink << "\t" << subtotalDrink <<

cout << "\nTotal before discount: Rs. " << totalBill << endl;
cout << "Discount: Rs. " << discount << endl;
cout << "Final Payable Amount: Rs. " << finalAmount << endl;

return 0;
}

You might also like