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

cs201 Assignment

Cs201 assignment 1
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)
2 views2 pages

cs201 Assignment

Cs201 assignment 1
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/ 2

#include <iostream>

#include <string>
#include <iomanip>

using namespace std;

int main() {
// Hard-coded name and VU ID
string name = "John Doe"; // Replace with your name
string vuID = "BS123456789"; // Replace with your VU ID

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


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

// Ask user for the numeric part of VU ID


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

// Extract 5 digits from the middle


if (numericPart.length() != 9) {
cout << "Invalid VU ID. Please enter a 9-digit numeric part." << endl;
return 1;
}

string extractedDigits = numericPart.substr(2, 5); // Extract 5 digits from the middle


cout << "Extracted Digits: " << extractedDigits << endl;

// Convert extracted digits to quantities


int quantityBurger = extractedDigits[0] - '0'; // Convert char to int
int quantityPizza = extractedDigits[1] - '0';
int quantityFries = extractedDigits[2] - '0';
int quantitySandwich = extractedDigits[3] - '0';
int quantityColdDrink = extractedDigits[4] - '0';

// Prices of menu items


const double priceBurger = 250.0;
const double pricePizza = 300.0;
const double priceFries = 150.0;
const double priceSandwich = 200.0;
const double priceColdDrink = 100.0;

// Calculate subtotal for each item


double subtotalBurger = quantityBurger * priceBurger;
double subtotalPizza = quantityPizza * pricePizza;
double subtotalFries = quantityFries * priceFries;
double subtotalSandwich = quantitySandwich * priceSandwich;
double subtotalColdDrink = quantityColdDrink * priceColdDrink;

// Calculate total bill


double totalBill = subtotalBurger + subtotalPizza + subtotalFries + subtotalSandwich +
subtotalColdDrink;

// Display billing details


cout << fixed << setprecision(2); // Set precision for currency display
cout << "\nBilling Details:\n";
cout << "Item\t\tQuantity\tUnit Price\tSubtotal\n";
cout << "Burger\t\t" << quantityBurger << "\t\t" << priceBurger << "\t\t" << subtotalBurger <<
endl;
cout << "Pizza\t\t" << quantityPizza << "\t\t" << pricePizza << "\t\t" << subtotalPizza << endl;
cout << "Fries\t\t" << quantityFries << "\t\t" << priceFries << "\t\t" << subtotalFries << endl;
cout << "Sandwich\t" << quantitySandwich << "\t\t" << priceSandwich << "\t\t" <<
subtotalSandwich << endl;
cout << "Cold Drink\t" << quantityColdDrink << "\t\t" << priceColdDrink << "\t\t" <<
subtotalColdDrink << endl;

// Calculate discount if applicable


double discountAmount = 0.0;
if (totalBill >= 5000) {
discountAmount = totalBill * 0.10; // 10% discount
}

// Calculate final payable amount


double finalAmount = totalBill - discountAmount;

// Display final amounts


cout << "\nTotal before discount: " << totalBill << endl;
cout << "Discount amount: " << discountAmount << endl;
cout << "Final payable amount: " << finalAmount << endl;

return 0;
}

You might also like